use of org.apache.wicket.model.util.ListModel in project midpoint by Evolveum.
the class TypedAssignablePanel method initLayout.
private void initLayout(Class<T> type, final boolean multiselect) {
DropDownChoice<QName> typeSelect = new DropDownChoice(ID_TYPE, typeModel, new ListModel(WebComponentUtil.createAssignableTypesList()), new QNameChoiceRenderer());
typeSelect.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(get(ID_TABLES_CONTAINER));
target.add(addOrReplace(createCountContainer()));
}
});
typeSelect.setOutputMarkupId(true);
add(typeSelect);
WebMarkupContainer tablesContainer = new WebMarkupContainer(ID_TABLES_CONTAINER);
tablesContainer.setOutputMarkupId(true);
add(tablesContainer);
PopupObjectListPanel<T> listRolePanel = createObjectListPanel(ID_ROLE_TABLE, ID_SELECTED_ROLES, RoleType.COMPLEX_TYPE);
tablesContainer.add(listRolePanel);
PopupObjectListPanel<T> listResourcePanel = createObjectListPanel(ID_RESOURCE_TABLE, ID_SELECTED_RESOURCES, ResourceType.COMPLEX_TYPE);
tablesContainer.add(listResourcePanel);
PopupObjectListPanel<T> listOrgPanel = createObjectListPanel(ID_ORG_TABLE, ID_SELECTED_ORGS, OrgType.COMPLEX_TYPE);
tablesContainer.add(listOrgPanel);
PopupObjectListPanel<T> listServicePanel = createObjectListPanel(ID_SERVICE_TABLE, ID_SELECTED_SERVICES, ServiceType.COMPLEX_TYPE);
tablesContainer.add(listServicePanel);
WebMarkupContainer countContainer = createCountContainer();
add(countContainer);
AjaxButton addButton = new AjaxButton(ID_BUTTON_ASSIGN, createStringResource("userBrowserDialog.button.addButton")) {
@Override
public void onClick(AjaxRequestTarget target) {
List<T> selected = getSelectedData(ID_ROLE_TABLE);
selected.addAll(getSelectedData(ID_RESOURCE_TABLE));
selected.addAll(getSelectedData(ID_ORG_TABLE));
selected.addAll(getSelectedData(ID_SERVICE_TABLE));
TypedAssignablePanel.this.addPerformed(target, selected);
}
};
addButton.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return multiselect;
}
});
add(addButton);
}
use of org.apache.wicket.model.util.ListModel in project wicket by apache.
the class ListViewTest method generics.
/**
*/
@Test
public void generics() {
// a listView for numbers
class NumberListView<N extends Number> extends ListView<N> {
private static final long serialVersionUID = 1L;
// accept lists accepting subtypes of numbers only
public NumberListView(String id, IModel<? extends List<N>> model) {
super(id, model);
}
@Override
protected void populateItem(ListItem<N> item) {
// non-fancy display of the number
add(new Label("label", item.getModel()));
}
}
;
IModel<List<Integer>> integers = new ListModel<>(new ArrayList<Integer>());
// pass list of integers to the number listView
new NumberListView<>("integers", integers);
}
use of org.apache.wicket.model.util.ListModel in project wicket by apache.
the class PaletteTest method choicesModelMissingSelected.
/**
* WICKET-4231 palette with choicesModel missing currently selected
*/
@Test
public void choicesModelMissingSelected() {
IModel<List<String>> selected = new ListModel<>(new ArrayList<>(Arrays.asList("D")));
IModel<List<String>> all = new ListModel<>(new ArrayList<>(Arrays.asList("A", "B", "C")));
PaletteTestPage testPage = new PaletteTestPage(selected, all);
tester.startPage(testPage);
FormTester formTester = tester.newFormTester(testPage.form.getId());
formTester.submit();
Collection<String> collection = testPage.palette.getModelCollection();
assertEquals(0, collection.size());
}
use of org.apache.wicket.model.util.ListModel in project wicket by apache.
the class PaletteTest method choicesModelAccountingForSelected.
/**
* WICKET-4231 palette with choicesModel accounting for currently selected
*/
@Test
public void choicesModelAccountingForSelected() {
final List<String> list = new ArrayList<>(Arrays.asList("D"));
IModel<List<String>> selected = new ListModel<>(list);
IModel<List<String>> all = new LoadableDetachableModel<List<String>>() {
@Override
protected List<String> load() {
// normally coming from DB
List<String> fromDB = Arrays.asList("A", "B", "C");
List<String> result = new ArrayList<>();
result.addAll(fromDB);
// include already selected
result.addAll(list);
return result;
}
};
PaletteTestPage testPage = new PaletteTestPage(selected, all);
tester.startPage(testPage);
FormTester formTester = tester.newFormTester(testPage.form.getId());
formTester.submit();
Collection<String> collection = testPage.palette.getModelCollection();
assertEquals(1, collection.size());
assertEquals("D", collection.iterator().next());
}
use of org.apache.wicket.model.util.ListModel in project wicket by apache.
the class PaletteTest method unselectedChoices.
/**
* WICKET-6244
*/
@Test
public void unselectedChoices() {
IModel<List<String>> selected = new ListModel<>(new ArrayList<String>());
IModel<List<String>> all = new ListModel<>(new ArrayList<>(Arrays.asList("A", "AA", "AAA")));
PaletteTestPage testPage = new PaletteTestPage(selected, all);
tester.startPage(testPage);
FormTester formTester = tester.newFormTester(testPage.form.getId());
formTester.setValue("palette:recorder", "AAA");
formTester.submit();
Iterator<String> iterator = testPage.palette.getUnselectedChoices();
assertEquals(true, iterator.hasNext());
assertEquals("A", iterator.next());
assertEquals(true, iterator.hasNext());
assertEquals("AA", iterator.next());
assertEquals(false, iterator.hasNext());
}
Aggregations