Search in sources :

Example 1 with ListModel

use of org.apache.wicket.model.util.ListModel in project midpoint by Evolveum.

the class ResourceDetailsTabPanel method initLayout.

protected void initLayout(IModel model, PageBase parentPage) {
    PrismObject<ResourceType> resourceObject = (PrismObject<ResourceType>) model.getObject();
    ResourceType resource = resourceObject.asObjectable();
    add(createLastAvailabilityStatusInfo(resource));
    add(createSourceTargetInfo(resource));
    add(createSchemaStatusInfo(resource));
    CapabilitiesPanel capabilities = new CapabilitiesPanel(PANEL_CAPABILITIES, capabilitiesModel);
    add(capabilities);
    List<ResourceConfigurationDto> resourceConfigList = createResourceConfigList(resource);
    ListDataProvider<ResourceConfigurationDto> resourceConfigProvider = new ListDataProvider<ResourceConfigurationDto>(ResourceDetailsTabPanel.this, new ListModel<ResourceConfigurationDto>(resourceConfigList));
    List<ColumnTypeDto<String>> columns = Arrays.asList(new ColumnTypeDto<String>("ShadowType.kind", "objectTypeDefinition.kind", ShadowType.F_KIND.getLocalPart()), new ColumnTypeDto<String>("ShadowType.objectClass", "objectTypeDefinition.objectClass.localPart", ShadowType.F_OBJECT_CLASS.getLocalPart()), new ColumnTypeDto<String>("ShadowType.intent", "objectTypeDefinition.intent", ShadowType.F_INTENT.getLocalPart()), new ColumnTypeDto<String>("ResourceType.isSync", "sync", null));
    List<IColumn<SelectableBean<ResourceType>, String>> tableColumns = ColumnUtils.createColumns(columns);
    PropertyColumn tasksColumn = new PropertyColumn(PageBase.createStringResourceStatic(this, "ResourceType.tasks"), "definedTasks") {

        @Override
        public void populateItem(Item item, String componentId, final IModel rowModel) {
            ResourceConfigurationDto conf = (ResourceConfigurationDto) rowModel.getObject();
            RepeatingView repeater = new RepeatingView(componentId);
            for (final TaskType task : conf.getDefinedTasks()) {
                repeater.add(new LinkPanel(repeater.newChildId(), new Model<String>(task.getName().getOrig())) {

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        ResourceDetailsTabPanel.this.taskDetailsPerformed(target, task.getOid());
                    }
                });
            }
            item.add(repeater);
        }
    };
    tableColumns.add(tasksColumn);
    BoxedTablePanel<ResourceConfigurationDto> resourceConfig = new BoxedTablePanel("resourceConfig", resourceConfigProvider, tableColumns);
    resourceConfig.setAdditionalBoxCssClasses("box-success");
    add(resourceConfig);
}
Also used : ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) PropertyColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn) RepeatingView(org.apache.wicket.markup.repeater.RepeatingView) ResourceConfigurationDto(com.evolveum.midpoint.web.page.admin.resources.dto.ResourceConfigurationDto) ColumnTypeDto(com.evolveum.midpoint.web.component.data.column.ColumnTypeDto) LinkPanel(com.evolveum.midpoint.web.component.data.column.LinkPanel) PrismObject(com.evolveum.midpoint.prism.PrismObject) Item(org.apache.wicket.markup.repeater.Item) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) BoxedTablePanel(com.evolveum.midpoint.web.component.data.BoxedTablePanel) IModel(org.apache.wicket.model.IModel) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) IModel(org.apache.wicket.model.IModel) ListModel(org.apache.wicket.model.util.ListModel) Model(org.apache.wicket.model.Model) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel)

Example 2 with ListModel

use of org.apache.wicket.model.util.ListModel in project wicket by apache.

the class MultiFileUploadFieldTest method submitMultiFileUploadFields.

/**
 * FormTester supports MultiFileUploadField
 *
 * https://issues.apache.org/jira/browse/WICKET-5346
 */
@Test
public void submitMultiFileUploadFields() {
    final AtomicBoolean submitted = new AtomicBoolean(false);
    final ListModel<FileUpload> filesModel = new ListModel<>(new ArrayList<FileUpload>());
    TestPage page = new TestPage(filesModel) {

        @Override
        protected void onSubmit() {
            super.onSubmit();
            List<FileUpload> uploads = filesModel.getObject();
            assertEquals(2, uploads.size());
            for (int i = 0; i < 2; i++) {
                FileUpload fileUpload = uploads.get(i);
                String clientFileName = fileUpload.getClientFileName();
                String id = clientFileName.replaceAll(MultiFileUploadFieldTest.class.getSimpleName() + "(\\d).txt", "$1");
                try {
                    assertEquals("Test" + id, IOUtils.toString(fileUpload.getInputStream()));
                } catch (IOException e) {
                    fail("Reading file upload '" + id + "' failed: " + e.getMessage());
                }
            }
            submitted.set(true);
        }
    };
    tester.startPage(page);
    tester.assertContainsNot("disabled=\"disabled\"");
    FormTester ft = tester.newFormTester("f");
    ft.setFile("muf", new File("target/test-classes/org/apache/wicket/markup/html/form/upload/MultiFileUploadFieldTest0.txt"), "plain/text");
    ft.setFile("muf", new File("target/test-classes/org/apache/wicket/markup/html/form/upload/MultiFileUploadFieldTest1.txt"), "plain/text");
    ft.submit();
    assertEquals("The form is not submitted", true, submitted.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ListModel(org.apache.wicket.model.util.ListModel) FormTester(org.apache.wicket.util.tester.FormTester) IOException(java.io.IOException) File(org.apache.wicket.util.file.File) Test(org.junit.Test)

Example 3 with ListModel

use of org.apache.wicket.model.util.ListModel in project wicket by apache.

the class PaletteTest method required.

/**
 * WICKET-5352
 */
@Test
public void required() {
    IModel<List<String>> selected = new ListModel<>(new ArrayList<String>());
    IModel<List<String>> all = new ListModel<>(new ArrayList<>(Arrays.asList("A")));
    PaletteTestPage testPage = new PaletteTestPage(selected, all);
    testPage.palette.setRequired(true);
    tester.startPage(testPage);
    FormTester formTester = tester.newFormTester(testPage.form.getId());
    formTester.submit();
    assertTrue(testPage.form.hasError());
}
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 4 with ListModel

use of org.apache.wicket.model.util.ListModel in project wicket by apache.

the class PaletteTest method validationErrorRawInput.

/**
 * WICKET-5352
 */
@Test
public void validationErrorRawInput() {
    IModel<List<String>> selected = new ListModel<>(new ArrayList<String>());
    IModel<List<String>> all = new ListModel<>(new ArrayList<>(Arrays.asList("A", "B")));
    PaletteTestPage testPage = new PaletteTestPage(selected, all);
    testPage.palette.add(new IValidator<Collection<String>>() {

        @Override
        public void validate(IValidatable<Collection<String>> validatable) {
            if (validatable.getValue().contains("A")) {
                validatable.error(new ValidationError("A not allowed"));
            }
        }
    });
    tester.startPage(testPage);
    FormTester formTester = tester.newFormTester(testPage.form.getId());
    formTester.setValue("palette:recorder", "A");
    formTester.submit();
    assertTrue(testPage.form.hasError());
    // with RAW_INPUT
    tester.assertContains("<option value=\"B\">B</option>\\s*</select>");
    tester.assertContains("<option value=\"A\">A</option>\\s*</select>");
    testPage.form.clearInput();
    tester.startPage(testPage);
    // without RAW_INPUT
    tester.assertContains("<option value=\"A\">A</option>\\s*<option value=\"B\">B</option>\\s*</select>");
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) ListModel(org.apache.wicket.model.util.ListModel) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ValidationError(org.apache.wicket.validation.ValidationError) Test(org.junit.Test)

Example 5 with ListModel

use of org.apache.wicket.model.util.ListModel in project wicket by apache.

the class PaletteTest method standard.

/**
 */
@Test
public void standard() {
    IModel<List<String>> selected = new ListModel<>(new ArrayList<>(Arrays.asList("A", "D")));
    IModel<List<String>> all = new ListModel<>(new ArrayList<>(Arrays.asList("A", "B", "C", "D")));
    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(2, collection.size());
    Iterator<String> iterator = collection.iterator();
    assertEquals("A", iterator.next());
    assertEquals("D", iterator.next());
}
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)26 ArrayList (java.util.ArrayList)13 List (java.util.List)12 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)11 Test (org.junit.Test)11 IModel (org.apache.wicket.model.IModel)8 FormTester (org.apache.wicket.util.tester.FormTester)7 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)6 Model (org.apache.wicket.model.Model)5 StringResourceModel (org.apache.wicket.model.StringResourceModel)5 QName (javax.xml.namespace.QName)4 Form (org.apache.wicket.markup.html.form.Form)4 EmptyOnChangeAjaxFormUpdatingBehavior (com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior)3 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)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