Search in sources :

Example 61 with AbstractReadOnlyModel

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

the class MultiValueTextPanel method initLayout.

private void initLayout(final NonEmptyModel<Boolean> readOnlyModel, final boolean emptyStringToNull) {
    WebMarkupContainer placeholderContainer = new WebMarkupContainer(ID_PLACEHOLDER_CONTAINER);
    placeholderContainer.setOutputMarkupPlaceholderTag(true);
    placeholderContainer.setOutputMarkupPlaceholderTag(true);
    placeholderContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getModel().getObject().isEmpty();
        }
    });
    add(placeholderContainer);
    AjaxLink placeholderAdd = new AjaxLink(ID_PLACEHOLDER_ADD) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addValuePerformed(target);
        }
    };
    placeholderAdd.add(WebComponentUtil.visibleIfFalse(readOnlyModel));
    placeholderAdd.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            if (buttonsDisabled()) {
                return " " + CSS_DISABLED;
            }
            return "";
        }
    }));
    placeholderAdd.setOutputMarkupId(true);
    placeholderAdd.setOutputMarkupPlaceholderTag(true);
    placeholderContainer.add(placeholderAdd);
    ListView repeater = new ListView<T>(ID_REPEATER, getModel()) {

        @Override
        protected void populateItem(final ListItem<T> item) {
            TextField text = new TextField<>(ID_TEXT, createTextModel(item.getModel()));
            text.add(new AjaxFormComponentUpdatingBehavior("blur") {

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            });
            text.add(AttributeAppender.replace("placeholder", createEmptyItemPlaceholder()));
            text.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
            text.setConvertEmptyInputStringToNull(emptyStringToNull);
            item.add(text);
            WebMarkupContainer buttonGroup = new WebMarkupContainer(ID_BUTTON_GROUP);
            item.add(buttonGroup);
            initButtons(buttonGroup, item, readOnlyModel);
        }
    };
    repeater.setOutputMarkupId(true);
    repeater.setOutputMarkupPlaceholderTag(true);
    repeater.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !getModel().getObject().isEmpty();
        }
    });
    add(repeater);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) ListView(org.apache.wicket.markup.html.list.ListView) TextField(org.apache.wicket.markup.html.form.TextField) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ListItem(org.apache.wicket.markup.html.list.ListItem) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 62 with AbstractReadOnlyModel

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

the class GenericMultiValueLabelEditPanel method initLayout.

private void initLayout(final IModel<String> label, final String labelSize, final String textSize) {
    Label l = new Label(ID_LABEL, label);
    l.setVisible(getLabelVisibility());
    if (StringUtils.isNotEmpty(labelSize)) {
        l.add(AttributeAppender.prepend("class", labelSize));
    }
    add(l);
    WebMarkupContainer addFirstContainer = new WebMarkupContainer(ID_ADD_FIRST_CONTAINER);
    addFirstContainer.setOutputMarkupId(true);
    addFirstContainer.setOutputMarkupPlaceholderTag(true);
    addFirstContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getModelObject().isEmpty();
        }
    });
    add(addFirstContainer);
    AjaxLink addFirst = new AjaxLink(ID_ADD_FIRST) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addFirstPerformed(target);
        }
    };
    addFirstContainer.add(addFirst);
    ListView repeater = new ListView<T>(ID_REPEATER, getModel()) {

        @Override
        protected void populateItem(final ListItem<T> listItem) {
            WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
            textWrapper.add(AttributeAppender.prepend("class", new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    StringBuilder sb = new StringBuilder();
                    if (StringUtils.isNotEmpty(textSize)) {
                        sb.append(textSize).append(' ');
                    }
                    if (listItem.getIndex() > 0 && StringUtils.isNotEmpty(getOffsetClass())) {
                        sb.append(getOffsetClass()).append(' ');
                        sb.append(CLASS_MULTI_VALUE);
                    }
                    return sb.toString();
                }
            }));
            listItem.add(textWrapper);
            TextField text = new TextField<>(ID_TEXT, createTextModel(listItem.getModel()));
            text.add(new AjaxFormComponentUpdatingBehavior("blur") {

                @Override
                protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
                }
            });
            text.setEnabled(false);
            text.add(AttributeAppender.replace("placeholder", label));
            text.setLabel(label);
            textWrapper.add(text);
            FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ComponentFeedbackMessageFilter(text));
            textWrapper.add(feedback);
            WebMarkupContainer buttonGroup = new WebMarkupContainer(ID_BUTTON_GROUP);
            buttonGroup.add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    if (listItem.getIndex() > 0 && StringUtils.isNotEmpty(labelSize)) {
                        return CLASS_MULTI_VALUE;
                    }
                    return null;
                }
            }));
            AjaxLink edit = new AjaxLink(ID_EDIT) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    editValuePerformed(target, listItem.getModel());
                }
            };
            textWrapper.add(edit);
            listItem.add(buttonGroup);
            initButtons(buttonGroup, listItem);
        }
    };
    add(repeater);
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ComponentFeedbackMessageFilter(org.apache.wicket.feedback.ComponentFeedbackMessageFilter) FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) ListView(org.apache.wicket.markup.html.list.ListView) TextField(org.apache.wicket.markup.html.form.TextField) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ListItem(org.apache.wicket.markup.html.list.ListItem) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Example 63 with AbstractReadOnlyModel

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

the class MultiValueAutoCompleteTextPanel method initLayout.

private void initLayout(final boolean inputEnabled, final NonEmptyModel<Boolean> readOnlyModel) {
    WebMarkupContainer placeholderContainer = new WebMarkupContainer(ID_PLACEHOLDER_CONTAINER);
    placeholderContainer.setOutputMarkupPlaceholderTag(true);
    placeholderContainer.setOutputMarkupPlaceholderTag(true);
    placeholderContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getModel().getObject().isEmpty();
        }
    });
    add(placeholderContainer);
    AjaxLink placeholderAdd = new AjaxLink(ID_PLACEHOLDER_ADD) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addValuePerformed(target);
        }
    };
    placeholderAdd.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            if (buttonsDisabled()) {
                return " " + CSS_DISABLED;
            }
            return "";
        }
    }));
    placeholderAdd.setOutputMarkupId(true);
    placeholderAdd.setOutputMarkupPlaceholderTag(true);
    placeholderAdd.add(WebComponentUtil.visibleIfFalse(readOnlyModel));
    placeholderContainer.add(placeholderAdd);
    ListView repeater = new ListView<T>(ID_REPEATER, getModel()) {

        @Override
        protected void populateItem(final ListItem<T> item) {
            AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
            autoCompleteSettings.setShowListOnEmptyInput(true);
            autoCompleteSettings.setMaxHeightInPx(200);
            AutoCompleteTextField<String> autoCompleteEditor = new AutoCompleteTextField<String>(ID_TEXT, createTextModel(item.getModel()), autoCompleteSettings) {

                @Override
                protected Iterator<String> getChoices(String input) {
                    return createAutoCompleteObjectList(input);
                }
            };
            autoCompleteEditor.add(createAutoCompleteValidator());
            autoCompleteEditor.add(new AjaxFormComponentUpdatingBehavior("change") {

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            });
            item.add(autoCompleteEditor);
            autoCompleteEditor.add(AttributeAppender.replace("placeholder", createEmptyItemPlaceholder()));
            if (!inputEnabled) {
                autoCompleteEditor.add(new AttributeModifier("disabled", "disabled"));
            }
            item.add(autoCompleteEditor);
            WebMarkupContainer buttonGroup = new WebMarkupContainer(ID_BUTTON_GROUP);
            item.add(buttonGroup);
            initButtons(buttonGroup, item, readOnlyModel);
        }
    };
    repeater.setOutputMarkupId(true);
    repeater.setOutputMarkupPlaceholderTag(true);
    repeater.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !getModel().getObject().isEmpty();
        }
    });
    add(repeater);
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) AttributeModifier(org.apache.wicket.AttributeModifier) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AutoCompleteSettings(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) ListView(org.apache.wicket.markup.html.list.ListView) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ListItem(org.apache.wicket.markup.html.list.ListItem) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 64 with AbstractReadOnlyModel

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

the class MultiValueDropDownPanel method initLayout.

private void initLayout(final boolean nullValid, final NonEmptyModel<Boolean> readOnlyModel) {
    WebMarkupContainer placeholderContainer = new WebMarkupContainer(ID_PLACEHOLDER_CONTAINER);
    placeholderContainer.setOutputMarkupPlaceholderTag(true);
    placeholderContainer.setOutputMarkupPlaceholderTag(true);
    placeholderContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getModel().getObject().isEmpty();
        }
    });
    add(placeholderContainer);
    AjaxLink placeholderAdd = new AjaxLink(ID_PLACEHOLDER_ADD) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addValuePerformed(target);
        }
    };
    placeholderAdd.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            if (buttonsDisabled()) {
                return " " + CSS_DISABLED;
            }
            return "";
        }
    }));
    placeholderAdd.setOutputMarkupId(true);
    placeholderAdd.setOutputMarkupPlaceholderTag(true);
    placeholderAdd.add(WebComponentUtil.visibleIfFalse(readOnlyModel));
    placeholderContainer.add(placeholderAdd);
    ListView repeater = new ListView<T>(ID_REPEATER, getModel()) {

        @Override
        protected void populateItem(final ListItem<T> item) {
            DropDownChoice choice = new DropDownChoice<>(ID_INPUT, createDropDownItemModel(item.getModel()), createChoiceList(), createRenderer());
            choice.setNullValid(nullValid);
            choice.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
            item.add(choice);
            WebMarkupContainer buttonGroup = new WebMarkupContainer(ID_BUTTON_GROUP);
            item.add(buttonGroup);
            initButtons(buttonGroup, item, readOnlyModel);
        }
    };
    repeater.setOutputMarkupId(true);
    repeater.setOutputMarkupPlaceholderTag(true);
    repeater.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !getModel().getObject().isEmpty();
        }
    });
    add(repeater);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) ListView(org.apache.wicket.markup.html.list.ListView) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ListItem(org.apache.wicket.markup.html.list.ListItem) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 65 with AbstractReadOnlyModel

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

the class NavigatorPanel method initLast.

private void initLast() {
    WebMarkupContainer last = new WebMarkupContainer(ID_LAST);
    last.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            return isLastEnabled() ? "" : "disabled";
        }
    }));
    add(last);
    AjaxLink lastLink = new AjaxLink(ID_LAST_LINK) {

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            attributes.setChannel(new AjaxChannel("blocking", AjaxChannel.Type.ACTIVE));
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            lastPerformed(target);
        }
    };
    lastLink.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isEnabled() {
            return BooleanUtils.isTrue(showPageListingModel.getObject()) && isLastEnabled();
        }
    });
    last.add(lastLink);
}
Also used : AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) AjaxChannel(org.apache.wicket.ajax.AjaxChannel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AttributeModifier(org.apache.wicket.AttributeModifier) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Aggregations

AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)105 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)60 Label (org.apache.wicket.markup.html.basic.Label)59 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)54 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)41 ArrayList (java.util.ArrayList)34 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)29 ListItem (org.apache.wicket.markup.html.list.ListItem)29 IModel (org.apache.wicket.model.IModel)26 ListView (org.apache.wicket.markup.html.list.ListView)25 List (java.util.List)23 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)23 AttributeModifier (org.apache.wicket.AttributeModifier)21 PropertyModel (org.apache.wicket.model.PropertyModel)20 Model (org.apache.wicket.model.Model)16 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)13 TextField (org.apache.wicket.markup.html.form.TextField)11 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)10 Form (org.apache.wicket.markup.html.form.Form)9 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)8