Search in sources :

Example 41 with ListItem

use of org.apache.wicket.markup.html.list.ListItem in project midpoint by Evolveum.

the class ScenePanel method initLayout.

private void initLayout() {
    final IModel<SceneDto> model = getModel();
    WebMarkupContainer box = new WebMarkupContainer(ID_BOX);
    box.add(AttributeModifier.append("class", new IModel<String>() {

        @Override
        public String getObject() {
            SceneDto dto = model.getObject();
            if (dto.getBoxClassOverride() != null) {
                return dto.getBoxClassOverride();
            }
            if (dto.getChangeType() == null) {
                return null;
            }
            switch(dto.getChangeType()) {
                case ADD:
                    return "box-success";
                case DELETE:
                    return "box-danger";
                case MODIFY:
                    return "box-info";
                default:
                    return null;
            }
        }
    }));
    add(box);
    WebMarkupContainer headerPanel = new WebMarkupContainer(ID_HEADER_PANEL);
    box.add(headerPanel);
    headerPanel.add(new SceneButtonPanel(ID_OPTION_BUTTONS, model) {

        @Override
        public void minimizeOnClick(AjaxRequestTarget target) {
            headerOnClickPerformed(target, model);
        }
    });
    Label headerChangeType = new Label(ID_HEADER_CHANGE_TYPE, new ChangeTypeModel());
    // headerChangeType.setRenderBodyOnly(true);
    Label headerObjectType = new Label(ID_HEADER_OBJECT_TYPE, new ObjectTypeModel());
    // headerObjectType.setRenderBodyOnly(true);
    IModel<String> nameModel = new IModel<String>() {

        @Override
        public String getObject() {
            return model.getObject().getName(ScenePanel.this);
        }
    };
    Label headerNameLabel = new Label(ID_HEADER_NAME_LABEL, nameModel);
    AjaxLinkPanel headerNameLink = new AjaxLinkPanel(ID_HEADER_NAME_LINK, nameModel) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            PrismContainerValue<?> value = getModelObject().getScene().getSourceValue();
            if (value != null && value.getParent() instanceof PrismObject) {
                PrismObject<? extends ObjectType> object = (PrismObject<? extends ObjectType>) value.getParent();
                WebComponentUtil.dispatchToObjectDetailsPage(ObjectTypeUtil.createObjectRef(object, getPageBase().getPrismContext()), getPageBase(), false);
            }
        }
    };
    Label headerDescription = new Label(ID_HEADER_DESCRIPTION, new IModel<String>() {

        @Override
        public String getObject() {
            return model.getObject().getDescription(ScenePanel.this);
        }
    });
    Label headerWrapperDisplayName = new Label(ID_HEADER_WRAPPER_DISPLAY_NAME, new IModel<String>() {

        @Override
        public String getObject() {
            String key = ((WrapperScene) getModelObject().getScene()).getDisplayNameKey();
            Object[] parameters = ((WrapperScene) getModelObject().getScene()).getDisplayNameParameters();
            return new StringResourceModel(key, this).setModel(null).setDefaultValue(key).setParameters(parameters).getObject();
        }
    });
    headerPanel.add(headerChangeType);
    headerPanel.add(headerObjectType);
    headerPanel.add(headerNameLabel);
    headerPanel.add(headerNameLink);
    headerPanel.add(headerDescription);
    headerPanel.add(headerWrapperDisplayName);
    headerChangeType.add(createHeaderOnClickBehaviour(model));
    headerObjectType.add(createHeaderOnClickBehaviour(model));
    headerNameLabel.add(createHeaderOnClickBehaviour(model));
    headerDescription.add(createHeaderOnClickBehaviour(model));
    headerWrapperDisplayName.add(createHeaderOnClickBehaviour(model));
    VisibleEnableBehaviour visibleIfNotWrapper = new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !getModelObject().isWrapper();
        }
    };
    VisibleEnableBehaviour visibleIfWrapper = new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getModelObject().isWrapper();
        }
    };
    VisibleEnableBehaviour visibleIfExistingObjectAndAuthorized = new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            if (getModelObject().isWrapper()) {
                return false;
            }
            return isExistingViewableObject() && isAutorized();
        }
    };
    VisibleEnableBehaviour visibleIfNotWrapperAndNotExistingObjectAndNotAuthorized = new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            if (getModelObject().isWrapper()) {
                return false;
            }
            return !isExistingViewableObject() || !isAutorized();
        }
    };
    headerChangeType.add(visibleIfNotWrapper);
    headerObjectType.add(visibleIfNotWrapper);
    headerNameLabel.add(visibleIfNotWrapperAndNotExistingObjectAndNotAuthorized);
    headerNameLink.add(visibleIfExistingObjectAndAuthorized);
    headerDescription.add(visibleIfNotWrapper);
    headerWrapperDisplayName.add(visibleIfWrapper);
    WebMarkupContainer body = new WebMarkupContainer(ID_BODY);
    body.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            SceneDto wrapper = model.getObject();
            return !wrapper.isMinimized();
        }
    });
    box.add(body);
    WebMarkupContainer itemsTable = new WebMarkupContainer(ID_ITEMS_TABLE);
    itemsTable.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !model.getObject().getItems().isEmpty();
        }
    });
    itemsTable.setOutputMarkupId(true);
    ToggleIconButton<String> sortPropertiesButton = new ToggleIconButton<String>(ID_SORT_PROPERTIES, GuiStyleConstants.CLASS_ICON_SORT_ALPHA_ASC, GuiStyleConstants.CLASS_ICON_SORT_AMOUNT_ASC) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            onSortClicked(model, target);
        }

        @Override
        public boolean isOn() {
            return model.getObject().isSorted();
        }
    };
    sortPropertiesButton.setOutputMarkupId(true);
    sortPropertiesButton.setOutputMarkupPlaceholderTag(true);
    itemsTable.add(sortPropertiesButton);
    WebMarkupContainer oldValueLabel = new WebMarkupContainer(ID_OLD_VALUE_LABEL);
    oldValueLabel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return model.getObject().containsDeltaItems();
        }
    });
    itemsTable.add(oldValueLabel);
    WebMarkupContainer newValueLabel = new WebMarkupContainer(ID_NEW_VALUE_LABEL);
    newValueLabel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return model.getObject().containsDeltaItems();
        }
    });
    itemsTable.add(newValueLabel);
    WebMarkupContainer valueLabel = new WebMarkupContainer(ID_VALUE_LABEL);
    valueLabel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !model.getObject().containsDeltaItems();
        }
    });
    itemsTable.add(valueLabel);
    ListView<SceneItemDto> items = new ListView<SceneItemDto>(ID_ITEMS, new PropertyModel<>(model, SceneDto.F_ITEMS)) {

        @Override
        protected void populateItem(ListItem<SceneItemDto> item) {
            SceneItemPanel panel = new SceneItemPanel(ID_ITEM, item.getModel());
            panel.add(new VisibleBehaviour(() -> !isOperationalItem(item.getModel()) || isOperationalItemsVisible()));
            panel.setRenderBodyOnly(true);
            item.add(panel);
        }
    };
    items.setReuseItems(true);
    itemsTable.add(items);
    body.add(itemsTable);
    ListView<SceneDto> partialScenes = new ListView<SceneDto>(ID_PARTIAL_SCENES, new PropertyModel<>(model, SceneDto.F_PARTIAL_SCENES)) {

        @Override
        protected void populateItem(ListItem<SceneDto> item) {
            ScenePanel panel = new ScenePanel(ID_PARTIAL_SCENE, item.getModel()) {

                private static final long serialVersionUID = 1L;

                @Override
                protected boolean isOperationalItemsVisible() {
                    ScenePanel parentScenePanel = findParent(ScenePanel.class);
                    if (parentScenePanel != null) {
                        return parentScenePanel.isOperationalItemsVisible();
                    } else {
                        return ScenePanel.this.operationalItemsVisible;
                    }
                }
            };
            panel.add(new VisibleBehaviour(() -> !isOperationalPartialScene(item.getModel()) || operationalItemsVisible));
            panel.setOutputMarkupPlaceholderTag(true);
            item.add(panel);
        }
    };
    partialScenes.setReuseItems(true);
    body.add(partialScenes);
    AjaxButton showOperationalItemsLink = new AjaxButton(ID_SHOW_OPERATIONAL_ITEMS_LINK) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            setOperationalItemsVisible(!operationalItemsVisible);
            target.add(ScenePanel.this);
        }

        @Override
        public IModel<?> getBody() {
            return getShowOperationalItemsLinkLabel();
        }
    };
    showOperationalItemsLink.setOutputMarkupId(true);
    showOperationalItemsLink.add(AttributeAppender.append("style", "cursor: pointer;"));
    showOperationalItemsLink.add(new VisibleBehaviour(() -> showOperationalItems));
    body.add(showOperationalItemsLink);
}
Also used : ToggleIconButton(com.evolveum.midpoint.gui.api.component.togglebutton.ToggleIconButton) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) Label(org.apache.wicket.markup.html.basic.Label) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) ListView(org.apache.wicket.markup.html.list.ListView) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLinkPanel(com.evolveum.midpoint.web.component.data.column.AjaxLinkPanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 42 with ListItem

use of org.apache.wicket.markup.html.list.ListItem in project midpoint by Evolveum.

the class ProgressPanel method initLayout.

private void initLayout() {
    MidpointForm progressForm = new MidpointForm<>(ID_PROGRESS_FORM, true);
    add(progressForm);
    contentsPanel = new WebMarkupContainer(ID_CONTENTS_PANEL);
    contentsPanel.setOutputMarkupId(true);
    progressForm.add(contentsPanel);
    ListView statusItemsListView = new ListView<ProgressReportActivityDto>(ID_ACTIVITIES, new IModel<List<ProgressReportActivityDto>>() {

        @Override
        public List<ProgressReportActivityDto> getObject() {
            ProgressReporter reporter = reporterModel.getProcessData();
            ProgressDto progressDto = reporter.getProgress();
            return progressDto.getProgressReportActivities();
        }
    }) {

        @Override
        protected void populateItem(ListItem<ProgressReportActivityDto> item) {
            populateStatusItem(item);
        }
    };
    contentsPanel.add(statusItemsListView);
    statisticsPanel = new StatisticsPanel(ID_STATISTICS, new StatisticsDtoModel());
    contentsPanel.add(statisticsPanel);
    ListView logItemsListView = new ListView(ID_LOG_ITEMS, new IModel<List>() {

        @Override
        public List getObject() {
            ProgressReporter reporter = reporterModel.getProcessData();
            ProgressDto progressDto = reporter.getProgress();
            return progressDto.getLogItems();
        }
    }) {

        @Override
        protected void populateItem(ListItem item) {
            item.add(new Label(ID_LOG_ITEM, item.getModel()));
        }
    };
    contentsPanel.add(logItemsListView);
    Label executionTime = new Label(ID_EXECUTION_TIME, new IModel<String>() {

        @Override
        public String getObject() {
            ProgressReporter reporter = reporterModel.getProcessData();
            if (reporter.getOperationDurationTime() > 0) {
                return getString("ProgressPanel.ExecutionTimeWhenFinished", reporter.getOperationDurationTime());
            } else if (reporter.getOperationStartTime() > 0) {
                return getString("ProgressPanel.ExecutionTimeWhenRunning", (System.currentTimeMillis() - reporter.getOperationStartTime()) / 1000);
            } else {
                return null;
            }
        }
    });
    contentsPanel.add(executionTime);
    initButtons(progressForm);
}
Also used : Label(org.apache.wicket.markup.html.basic.Label) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ListView(org.apache.wicket.markup.html.list.ListView) List(java.util.List) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 43 with ListItem

use of org.apache.wicket.markup.html.list.ListItem in project midpoint by Evolveum.

the class ResourceSchemaHandlingTabPanel method initLayout.

private void initLayout() {
    MidpointForm<?> form = new MidpointForm<>(ID_FORM);
    add(form);
    MultivalueContainerListPanelWithDetailsPanel<ResourceObjectTypeDefinitionType> objectTypesPanel = new MultivalueContainerListPanelWithDetailsPanel<>(ID_TABLE, ResourceObjectTypeDefinitionType.class) {

        @Override
        protected MultivalueContainerDetailsPanel<ResourceObjectTypeDefinitionType> getMultivalueContainerDetailsPanel(ListItem<PrismContainerValueWrapper<ResourceObjectTypeDefinitionType>> item) {
            return createMultivalueContainerDetailsPanel(ID_ITEM_DETAILS, item.getModel());
        }

        @Override
        protected boolean isCreateNewObjectVisible() {
            return false;
        }

        @Override
        protected IModel<PrismContainerWrapper<ResourceObjectTypeDefinitionType>> getContainerModel() {
            return PrismContainerWrapperModel.fromContainerWrapper(ResourceSchemaHandlingTabPanel.this.getModel(), SchemaHandlingType.F_OBJECT_TYPE);
        }

        @Override
        protected UserProfileStorage.TableId getTableId() {
            return null;
        }

        @Override
        protected List<IColumn<PrismContainerValueWrapper<ResourceObjectTypeDefinitionType>, String>> createDefaultColumns() {
            List<IColumn<PrismContainerValueWrapper<ResourceObjectTypeDefinitionType>, String>> columns = new ArrayList<>();
            columns.add(new PrismPropertyWrapperColumn<>(getContainerModel(), ResourceObjectTypeDefinitionType.F_DISPLAY_NAME, AbstractItemWrapperColumn.ColumnType.STRING, getPageBase()));
            columns.add(new PrismPropertyWrapperColumn<>(getContainerModel(), ResourceObjectTypeDefinitionType.F_KIND, AbstractItemWrapperColumn.ColumnType.STRING, getPageBase()));
            columns.add(new PrismPropertyWrapperColumn<>(getContainerModel(), ResourceObjectTypeDefinitionType.F_INTENT, AbstractItemWrapperColumn.ColumnType.STRING, getPageBase()));
            columns.add(new PrismPropertyWrapperColumn<>(getContainerModel(), ResourceObjectTypeDefinitionType.F_DEFAULT, AbstractItemWrapperColumn.ColumnType.STRING, getPageBase()));
            columns.add(new PrismPropertyWrapperColumn<>(getContainerModel(), ResourceObjectTypeDefinitionType.F_DESCRIPTION, AbstractItemWrapperColumn.ColumnType.STRING, getPageBase()));
            List<InlineMenuItem> menuActionsList = getMultivalueContainerListPanel().getDefaultMenuActions();
            columns.add(new InlineMenuButtonColumn(menuActionsList, getPageBase()) {

                private static final long serialVersionUID = 1L;

                @Override
                public String getCssClass() {
                    return " col-md-1 ";
                }
            });
            return columns;
        }
    };
    form.add(objectTypesPanel);
}
Also used : InlineMenuButtonColumn(com.evolveum.midpoint.web.component.data.column.InlineMenuButtonColumn) PrismContainerWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper) ArrayList(java.util.ArrayList) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) UserProfileStorage(com.evolveum.midpoint.web.session.UserProfileStorage) ResourceObjectTypeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) MultivalueContainerListPanelWithDetailsPanel(com.evolveum.midpoint.gui.impl.component.MultivalueContainerListPanelWithDetailsPanel) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 44 with ListItem

use of org.apache.wicket.markup.html.list.ListItem in project midpoint by Evolveum.

the class ActivitiesItemProcessingPanel method initLayoutNew.

private void initLayoutNew() {
    ListView<ActivityItemProcessingDto> activitiesView = new ListView<>(ID_ACTIVITIES, new PropertyModel<>(getModel(), ActivitiesItemProcessingDto.F_ACTIVITIES)) {

        @Override
        protected void populateItem(ListItem<ActivityItemProcessingDto> listItem) {
            IModel<ActivityItemProcessingDto> itemProcessingModel = listItem.getModel();
            Label summary = new Label(ID_SUMMARY, PropertyModel.of(itemProcessingModel, ActivityItemProcessingDto.F_TITLE));
            summary.setOutputMarkupId(true);
            listItem.add(summary);
            Label wallClockThroughput = new Label(ID_WALL_CLOCK_THROUGHPUT, PropertyModel.of(itemProcessingModel, ActivityItemProcessingDto.F_WALL_CLOCK_THROUGHPUT));
            summary.setOutputMarkupId(true);
            listItem.add(wallClockThroughput);
            ChartJsPanel<PieChartConfiguration> chartPanel = new ChartJsPanel<>(ID_CHART, PropertyModel.of(itemProcessingModel, ActivityItemProcessingDto.F_CHART));
            listItem.add(chartPanel);
            chartPanel.add(new VisibleBehaviour(() -> itemProcessingModel.getObject().getTotalCount() > 0));
            PropertyModel<List<ProcessedItemDto>> currentItemsModel = PropertyModel.of(itemProcessingModel, ActivityItemProcessingDto.F_CURRENT_ITEMS);
            BoxedTablePanel<ProcessedItemDto> currentItems = new BoxedTablePanel<>(ID_CURRENT_ITEMS, new ListDataProvider<>(ActivitiesItemProcessingPanel.this, currentItemsModel), createCurrentItemsColumns()) {

                @Override
                protected boolean hideFooterIfSinglePage() {
                    return true;
                }

                @Override
                public String getAdditionalBoxCssClasses() {
                    return " box-info ";
                }
            };
            currentItems.setOutputMarkupId(true);
            currentItems.add(new VisibleBehaviour(() -> CollectionUtils.isNotEmpty(currentItemsModel.getObject())));
            listItem.add(currentItems);
            listItem.add(createInfoBoxPanel(PropertyModel.of(itemProcessingModel, ActivityItemProcessingDto.F_SUCCESS_BOX), ID_SUCCESS_ITEM));
            listItem.add(createInfoBoxPanel(PropertyModel.of(itemProcessingModel, ActivityItemProcessingDto.F_FAILED_BOX), ID_FAILED_ITEM));
            listItem.add(createInfoBoxPanel(PropertyModel.of(itemProcessingModel, ActivityItemProcessingDto.F_SKIP_BOX), ID_SKIPPED_ITEM));
        }
    };
    activitiesView.setOutputMarkupId(true);
    add(activitiesView);
}
Also used : ChartJsPanel(com.evolveum.wicket.chartjs.ChartJsPanel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) PieChartConfiguration(com.evolveum.wicket.chartjs.PieChartConfiguration) Label(org.apache.wicket.markup.html.basic.Label) ListView(org.apache.wicket.markup.html.list.ListView) ArrayList(java.util.ArrayList) List(java.util.List) ListItem(org.apache.wicket.markup.html.list.ListItem) BoxedTablePanel(com.evolveum.midpoint.web.component.data.BoxedTablePanel)

Example 45 with ListItem

use of org.apache.wicket.markup.html.list.ListItem in project midpoint by Evolveum.

the class PolyStringEditorPanel method initLayout.

private void initLayout() {
    setOutputMarkupId(true);
    String localizedValue = getLocalizedPolyStringValue();
    WebMarkupContainer localizedValueContainer = new WebMarkupContainer(ID_LOCALIZED_VALUE_CONTAINER);
    localizedValueContainer.setOutputMarkupId(true);
    localizedValueContainer.add(getInputFieldClassAppenderForContainer());
    localizedValueContainer.add(new VisibleBehaviour(() -> showFullData || StringUtils.isNotEmpty(localizedValue)));
    add(localizedValueContainer);
    Label localizedValueLabel = new Label(ID_LOCALIZED_VALUE_LABEL, ((PageBase) getPage()).createStringResource("PolyStringEditorPanel.localizedValue"));
    localizedValueLabel.setOutputMarkupId(true);
    localizedValueLabel.add(new VisibleBehaviour(() -> showFullData));
    localizedValueContainer.add(localizedValueLabel);
    WebMarkupContainer localizedValueWithButton = new WebMarkupContainer(ID_LOCALIZED_VALUE_WITH_BUTTON);
    localizedValueWithButton.setOutputMarkupId(true);
    localizedValueWithButton.add(getInputFieldClassAppender());
    localizedValueContainer.add(localizedValueWithButton);
    TextPanel<String> localizedValuePanel = new TextPanel<>(ID_LOCALIZED_VALUE_PANEL, Model.of(localizedValue));
    localizedValuePanel.setOutputMarkupId(true);
    localizedValuePanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    localizedValuePanel.add(new EnableBehaviour(() -> false));
    localizedValueWithButton.add(localizedValuePanel);
    AjaxButton showHideLanguagesLocalizedButton = new AjaxButton(ID_SHOW_HIDE_LANGUAGES_LOCALIZED) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            showHideLanguagesPerformed(target);
        }
    };
    showHideLanguagesLocalizedButton.setOutputMarkupId(true);
    // showHideLanguagesLocalizedButton.add(AttributeAppender.append("style", "cursor: pointer;"));
    localizedValueWithButton.add(showHideLanguagesLocalizedButton);
    WebMarkupContainer originValueContainer = new WebMarkupContainer(ID_ORIGIN_VALUE_CONTAINER);
    originValueContainer.setOutputMarkupId(true);
    originValueContainer.add(getInputFieldClassAppenderForContainer());
    originValueContainer.add(new VisibleBehaviour(() -> showFullData || StringUtils.isEmpty(localizedValue)));
    add(originValueContainer);
    Label origValueLabel = new Label(ID_ORIG_VALUE_LABEL, ((PageBase) getPage()).createStringResource("PolyStringEditorPanel.origValue"));
    origValueLabel.setOutputMarkupId(true);
    origValueLabel.add(new VisibleBehaviour(() -> showFullData));
    originValueContainer.add(origValueLabel);
    WebMarkupContainer origValueWithButton = new WebMarkupContainer(ID_ORIG_VALUE_WITH_BUTTON);
    origValueWithButton.add(getInputFieldClassAppender());
    origValueWithButton.setOutputMarkupId(true);
    originValueContainer.add(origValueWithButton);
    InputPanel origValuePanel;
    IModel<String> origValueModel = new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getModelObject() != null ? getModelObject().getOrig() : null;
        }

        @Override
        public void setObject(String object) {
            PolyString oldModelObject = getModelObject();
            if (oldModelObject != null && (oldModelObject.getTranslation() != null || MapUtils.isNotEmpty(oldModelObject.getLang()))) {
                getModel().setObject(new PolyString(object, oldModelObject.getNorm(), oldModelObject.getTranslation(), oldModelObject.getLang()));
            } else if (StringUtils.isNotBlank(object)) {
                getModel().setObject(new PolyString(object));
            } else {
                getModel().setObject(null);
            }
        }

        @Override
        public void detach() {
        }
    };
    if (predefinedValuesLookupTable == null) {
        origValuePanel = new TextPanel<>(ID_ORIG_VALUE, origValueModel, String.class, false);
    } else {
        origValuePanel = new AutoCompleteTextPanel<String>(ID_ORIG_VALUE, origValueModel, String.class, hasValueEnumerationRef, predefinedValuesLookupTable) {

            private static final long serialVersionUID = 1L;

            @Override
            public Iterator<String> getIterator(String input) {
                return getPredefinedValuesIterator(input).iterator();
            }
        };
    }
    origValuePanel.setOutputMarkupId(true);
    origValuePanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    origValueWithButton.add(origValuePanel);
    WebMarkupContainer fullDataContainer = new WebMarkupContainer(ID_FULL_DATA_CONTAINER);
    fullDataContainer.setOutputMarkupId(true);
    fullDataContainer.add(new VisibleBehaviour(() -> showFullData));
    add(fullDataContainer);
    TextPanel<String> keyValue = new TextPanel<>(ID_KEY_VALUE, new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getModelObject() != null && getModelObject().getTranslation() != null ? getModelObject().getTranslation().getKey() : null;
        }

        @Override
        public void setObject(String object) {
            if (getModelObject() == null) {
                getModel().setObject(new PolyString(""));
            }
            if (getModelObject().getTranslation() == null) {
                getModelObject().setTranslation(new PolyStringTranslationType());
            }
            getModelObject().getTranslation().setKey(object);
        }

        @Override
        public void detach() {
        }
    });
    keyValue.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    keyValue.setOutputMarkupId(true);
    fullDataContainer.add(keyValue);
    IModel<String> langChoiceModel = Model.of();
    WebMarkupContainer languageEditorContainer = new WebMarkupContainer(ID_LANGUAGE_EDITOR);
    languageEditorContainer.setOutputMarkupId(true);
    languageEditorContainer.add(new VisibleBehaviour(() -> CollectionUtils.isNotEmpty(getLanguageChoicesModel().getObject())));
    fullDataContainer.add(languageEditorContainer);
    final DropDownChoicePanel<String> languageChoicePanel = new DropDownChoicePanel<>(ID_LANGUAGES_LIST, langChoiceModel, getLanguageChoicesModel(), true);
    languageChoicePanel.setOutputMarkupId(true);
    languageChoicePanel.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    languageChoicePanel.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
            removeLanguageValue(currentlySelectedLang.toString());
            clearSelectedLanguageValue();
            currentlySelectedLang.append(getLanguagesChoicePanel().getBaseFormComponent().getModelObject());
        }
    });
    languageEditorContainer.add(languageChoicePanel);
    final TextPanel<String> newLanguageValue = new TextPanel<>(ID_VALUE_TO_ADD, Model.of());
    newLanguageValue.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateLanguageValue(languageChoicePanel.getBaseFormComponent().getModelObject(), newLanguageValue.getBaseFormComponent().getValue());
        }
    });
    languageChoicePanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateLanguageValue(languageChoicePanel.getBaseFormComponent().getModelObject(), newLanguageValue.getBaseFormComponent().getValue());
        }
    });
    newLanguageValue.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
            updateLanguageValue(languageChoicePanel.getBaseFormComponent().getModelObject(), newLanguageValue.getBaseFormComponent().getValue());
        }
    });
    newLanguageValue.setOutputMarkupId(true);
    languageEditorContainer.add(newLanguageValue);
    AjaxLink<Void> addLanguageButton = new AjaxLink<Void>(ID_ADD_LANGUAGE_VALUE_BUTTON) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            updateLanguageValue(languageChoicePanel.getModel().getObject(), newLanguageValue.getBaseFormComponent().getModelObject());
            languageChoicePanel.getModel().setObject(null);
            newLanguageValue.getBaseFormComponent().getModel().setObject(null);
            clearSelectedLanguageValue();
            target.add(PolyStringEditorPanel.this);
        }
    };
    addLanguageButton.add(AttributeAppender.append("style", "cursor: pointer;"));
    addLanguageButton.setOutputMarkupId(true);
    languageEditorContainer.add(addLanguageButton);
    ListView<String> languagesContainer = new ListView<String>(ID_LANGUAGES_REPEATER, getLanguagesListModel()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<String> listItem) {
            TextPanel<String> languageName = new TextPanel<>(ID_LANGUAGE_NAME, listItem.getModel());
            languageName.add(new EnableBehaviour(() -> false));
            languageName.setOutputMarkupId(true);
            listItem.add(languageName);
            TextPanel<String> translation = new TextPanel<>(ID_TRANSLATION, Model.of(getLanguageValueByKey(listItem.getModelObject())));
            translation.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour() {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    updateLanguageValue(languageName.getBaseFormComponent().getValue(), translation.getBaseFormComponent().getValue());
                }
            });
            translation.setOutputMarkupId(true);
            translation.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior() {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
                    updateLanguageValue(languageName.getBaseFormComponent().getValue(), translation.getBaseFormComponent().getValue());
                }
            });
            listItem.add(translation);
            AjaxLink<Void> removeButton = new AjaxLink<Void>(ID_REMOVE_LANGUAGE_BUTTON) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    removeLanguageValue(listItem.getModelObject());
                    target.add(PolyStringEditorPanel.this);
                }
            };
            removeButton.setOutputMarkupId(true);
            listItem.add(removeButton);
        }
    };
    languagesContainer.setOutputMarkupId(true);
    fullDataContainer.add(languagesContainer);
    AjaxButton showHideLanguagesButton = new AjaxButton(ID_SHOW_HIDE_LANGUAGES_ORIG) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            showHideLanguagesPerformed(target);
        }
    };
    showHideLanguagesButton.setOutputMarkupId(true);
    // showHideLanguagesButton.add(AttributeAppender.append("style", "cursor: pointer;"));
    origValueWithButton.add(showHideLanguagesButton);
}
Also used : DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) Label(org.apache.wicket.markup.html.basic.Label) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) EmptyOnChangeAjaxFormUpdatingBehavior(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) ListView(org.apache.wicket.markup.html.list.ListView) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour) IModel(org.apache.wicket.model.IModel) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ListItem(org.apache.wicket.markup.html.list.ListItem)

Aggregations

ListItem (org.apache.wicket.markup.html.list.ListItem)127 ListView (org.apache.wicket.markup.html.list.ListView)103 Label (org.apache.wicket.markup.html.basic.Label)79 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)70 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)69 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)40 IModel (org.apache.wicket.model.IModel)40 List (java.util.List)38 ArrayList (java.util.ArrayList)37 PropertyModel (org.apache.wicket.model.PropertyModel)28 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)23 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)23 TextField (org.apache.wicket.markup.html.form.TextField)15 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)14 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)14 QName (javax.xml.namespace.QName)13 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)13 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)11 AttributeModifier (org.apache.wicket.AttributeModifier)11 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)10