Search in sources :

Example 16 with ListModel

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);
}
Also used : QNameChoiceRenderer(com.evolveum.midpoint.web.component.input.QNameChoiceRenderer) QName(javax.xml.namespace.QName) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) ListModel(org.apache.wicket.model.util.ListModel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Example 17 with ListModel

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);
}
Also used : IModel(org.apache.wicket.model.IModel) ListModel(org.apache.wicket.model.util.ListModel) Label(org.apache.wicket.markup.html.basic.Label) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 18 with ListModel

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());
}
Also used : ListModel(org.apache.wicket.model.util.ListModel) FormTester(org.apache.wicket.util.tester.FormTester) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 19 with ListModel

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());
}
Also used : ListModel(org.apache.wicket.model.util.ListModel) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) ArrayList(java.util.ArrayList) FormTester(org.apache.wicket.util.tester.FormTester) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 20 with ListModel

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());
}
Also used : ListModel(org.apache.wicket.model.util.ListModel) FormTester(org.apache.wicket.util.tester.FormTester) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

ListModel (org.apache.wicket.model.util.ListModel)28 ArrayList (java.util.ArrayList)14 List (java.util.List)13 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)12 IModel (org.apache.wicket.model.IModel)9 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)8 Test (org.junit.Test)8 FormTester (org.apache.wicket.util.tester.FormTester)7 Model (org.apache.wicket.model.Model)5 QName (javax.xml.namespace.QName)4 EmptyOnChangeAjaxFormUpdatingBehavior (com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior)3 IOException (java.io.IOException)3 FilterCriteriaManager (ru.ydn.wicket.wicketorientdb.utils.query.filter.FilterCriteriaManager)3 IFilterCriteriaManager (ru.ydn.wicket.wicketorientdb.utils.query.filter.IFilterCriteriaManager)3 AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)2 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)2 BoxedTablePanel (com.evolveum.midpoint.web.component.data.BoxedTablePanel)2 ColumnTypeDto (com.evolveum.midpoint.web.component.data.column.ColumnTypeDto)2