Search in sources :

Example 46 with AjaxFormComponentUpdatingBehavior

use of org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior in project midpoint by Evolveum.

the class DirectlyEditablePropertyColumn method createInputPanel.

protected InputPanel createInputPanel(String componentId, final IModel<T> model) {
    TextPanel<?> textPanel = new TextPanel<String>(componentId, new PropertyModel<>(model, getPropertyExpression()));
    // UGLY HACK
    TextField<?> textField = (TextField<?>) textPanel.getBaseFormComponent();
    textField.add(new AjaxFormComponentUpdatingBehavior("blur") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            onBlur(target, model);
        }
    });
    return textPanel;
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel) TextField(org.apache.wicket.markup.html.form.TextField)

Example 47 with AjaxFormComponentUpdatingBehavior

use of org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior in project midpoint by Evolveum.

the class SearchPanel method initPopover.

private void initPopover() {
    WebMarkupContainer popover = new WebMarkupContainer(ID_POPOVER);
    popover.setOutputMarkupId(true);
    add(popover);
    final WebMarkupContainer propList = new WebMarkupContainer(ID_PROP_LIST);
    propList.setOutputMarkupId(true);
    popover.add(propList);
    ListView properties = new ListView<SearchItemDefinition>(ID_PROPERTIES, new PropertyModel<>(moreDialogModel, MoreDialogDto.F_PROPERTIES)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<SearchItemDefinition> item) {
            CheckBox check = new CheckBox(ID_CHECK, new PropertyModel<>(item.getModel(), SearchItemDefinition.F_SELECTED));
            check.add(new AjaxFormComponentUpdatingBehavior("change") {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                // nothing, just update model.
                }
            });
            item.add(check);
            AjaxLink<Void> propLink = new AjaxLink<Void>(ID_PROP_LINK) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    addOneItemPerformed(item.getModelObject(), target);
                }
            };
            item.add(propLink);
            Label name = new Label(ID_PROP_NAME, new PropertyModel<>(item.getModel(), SearchItemDefinition.F_NAME));
            name.setRenderBodyOnly(true);
            propLink.add(name);
            Label help = new Label(ID_HELP);
            IModel<String> helpModel = new PropertyModel<>(item.getModel(), SearchItemDefinition.F_HELP);
            help.add(AttributeModifier.replace("title", createStringResource(helpModel.getObject() != null ? helpModel.getObject() : "")));
            help.add(new InfoTooltipBehavior() {

                @Override
                public String getDataPlacement() {
                    return "left";
                }
            });
            help.add(new VisibleBehaviour(() -> StringUtils.isNotEmpty(helpModel.getObject())));
            item.add(help);
            item.add(new VisibleEnableBehaviour() {

                private static final long serialVersionUID = 1L;

                @Override
                public boolean isVisible() {
                    SearchItemDefinition property = item.getModelObject();
                    Search<C> search = SearchPanel.this.getModelObject();
                    if (!search.getAvailableDefinitions().contains(property)) {
                        return false;
                    }
                    for (SearchItem searchItem : search.getItems()) {
                        if (searchItem.getDefinition().equals(property)) {
                            return false;
                        }
                        if (searchItem instanceof PropertySearchItem) {
                            ItemPath propertyPath = property.getPath();
                            if (propertyPath != null && QNameUtil.match(propertyPath.lastName(), ((PropertySearchItem) searchItem).getPath().lastName())) {
                                return false;
                            }
                        }
                    }
                    MoreDialogDto dto = moreDialogModel.getObject();
                    String nameFilter = dto.getNameFilter();
                    String propertyName = property.getName().toLowerCase();
                    if (StringUtils.isNotEmpty(nameFilter) && !propertyName.contains(nameFilter.toLowerCase())) {
                        return false;
                    }
                    return true;
                }
            });
        }
    };
    propList.add(properties);
    TextField<?> addText = new TextField<>(ID_ADD_TEXT, new PropertyModel<>(moreDialogModel, MoreDialogDto.F_NAME_FILTER));
    addText.add(WebComponentUtil.preventSubmitOnEnterKeyDownBehavior());
    popover.add(addText);
    addText.add(new AjaxFormComponentUpdatingBehavior("keyup") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(propList);
        }
    });
    popover.add(addText);
    AjaxButton add = new AjaxButton(ID_ADD, createStringResource("SearchPanel.add")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            addItemPerformed(target);
        }
    };
    popover.add(add);
    AjaxButton close = new AjaxButton(ID_CLOSE, createStringResource("SearchPanel.close")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            closeMorePopoverPerformed(target);
        }
    };
    popover.add(close);
}
Also used : VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) Label(org.apache.wicket.markup.html.basic.Label) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AbstractRoleCompositedSearchItem(com.evolveum.midpoint.web.page.admin.roles.AbstractRoleCompositedSearchItem) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) ListView(org.apache.wicket.markup.html.list.ListView) TextField(org.apache.wicket.markup.html.form.TextField) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) PropertyModel(org.apache.wicket.model.PropertyModel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) CheckBox(org.apache.wicket.markup.html.form.CheckBox) ListItem(org.apache.wicket.markup.html.list.ListItem) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 48 with AjaxFormComponentUpdatingBehavior

use of org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior in project midpoint by Evolveum.

the class MidPointApplication method isPostMethodTypeBehavior.

private boolean isPostMethodTypeBehavior(AbstractDefaultAjaxBehavior behavior, AjaxRequestAttributes attributes) {
    if (behavior instanceof AjaxFormComponentUpdatingBehavior) {
        // these also uses POST, but they set it after this method is called
        return true;
    }
    if (behavior instanceof AjaxFormSubmitBehavior) {
        AjaxFormSubmitBehavior fb = (AjaxFormSubmitBehavior) behavior;
        Form form = fb.getForm();
        String formMethod = form.getMarkupAttributes().getString("method");
        if (formMethod == null || "POST".equalsIgnoreCase(formMethod) || form.getRootForm().isMultiPart()) {
            // this will also use POST
            return true;
        }
    }
    return AjaxRequestAttributes.Method.POST.equals(attributes.getMethod());
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) Form(org.apache.wicket.markup.html.form.Form) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 49 with AjaxFormComponentUpdatingBehavior

use of org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior in project midpoint by Evolveum.

the class NameStep method createConnectorDropDown.

private DropDownFormGroup<PrismObject<ConnectorType>> createConnectorDropDown() {
    return new DropDownFormGroup<PrismObject<ConnectorType>>(ID_CONNECTOR, selectedConnectorModel, relevantConnectorsModel, new IChoiceRenderer<PrismObject<ConnectorType>>() {

        @Override
        public PrismObject<ConnectorType> getObject(String id, IModel<? extends List<? extends PrismObject<ConnectorType>>> choices) {
            return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
        }

        @Override
        public Object getDisplayValue(PrismObject<ConnectorType> object) {
            return WebComponentUtil.getName(object);
        }

        @Override
        public String getIdValue(PrismObject<ConnectorType> object, int index) {
            if (index < 0) {
                // noinspection unchecked
                List<PrismObject<ConnectorType>> connectors = (List<PrismObject<ConnectorType>>) getConnectorDropDown().getInput().getChoices();
                for (PrismObject<ConnectorType> connector : connectors) {
                    if (connector.getOid().equals(selectedConnectorModel.getObject().getOid())) {
                        return Integer.toString(connectors.indexOf(connector));
                    }
                }
            }
            return Integer.toString(index);
        }
    }, createStringResource("NameStep.connectorType"), "col-md-3", "col-md-6", true) {

        @Override
        protected DropDownChoice<PrismObject<ConnectorType>> createDropDown(String id, IModel<List<PrismObject<ConnectorType>>> choices, IChoiceRenderer<PrismObject<ConnectorType>> renderer, boolean required) {
            DropDownChoice<PrismObject<ConnectorType>> choice = super.createDropDown(id, choices, renderer, required);
            choice.add(new AjaxFormComponentUpdatingBehavior("change") {

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    target.add(getConnectorDropDown().getAdditionalInfoComponent());
                }
            });
            choice.setOutputMarkupId(true);
            return choice;
        }

        @Override
        protected Component createAdditionalInfoComponent(String id) {
            Label l = new Label(id, schemaChangeWarningModel);
            l.add(new AttributeAppender("class", "text-danger"));
            l.setOutputMarkupId(true);
            return l;
        }
    };
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) IModel(org.apache.wicket.model.IModel) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) DropDownFormGroup(com.evolveum.midpoint.web.component.form.DropDownFormGroup) Label(org.apache.wicket.markup.html.basic.Label) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) List(java.util.List) ArrayList(java.util.ArrayList) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 50 with AjaxFormComponentUpdatingBehavior

use of org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior in project midpoint by Evolveum.

the class NameStep method createHostDropDown.

@NotNull
private DropDownFormGroup<PrismObject<ConnectorHostType>> createHostDropDown() {
    return new DropDownFormGroup<PrismObject<ConnectorHostType>>(ID_CONNECTOR_HOST, selectedHostModel, allHostsModel, new IChoiceRenderer<PrismObject<ConnectorHostType>>() {

        @Override
        public PrismObject<ConnectorHostType> getObject(String id, IModel<? extends List<? extends PrismObject<ConnectorHostType>>> choices) {
            if (StringUtils.isBlank(id)) {
                return null;
            }
            return choices.getObject().get(Integer.parseInt(id));
        }

        @Override
        public Object getDisplayValue(PrismObject<ConnectorHostType> object) {
            if (object == null) {
                return NameStep.this.getString("NameStep.hostNotUsed");
            }
            return ConnectorHostTypeComparator.getUserFriendlyName(object);
        }

        @Override
        public String getIdValue(PrismObject<ConnectorHostType> object, int index) {
            return Integer.toString(index);
        }
    }, createStringResource("NameStep.connectorHost"), "col-md-3", "col-md-6", false) {

        @Override
        protected DropDownChoice<PrismObject<ConnectorHostType>> createDropDown(String id, IModel<List<PrismObject<ConnectorHostType>>> choices, IChoiceRenderer<PrismObject<ConnectorHostType>> renderer, boolean required) {
            DropDownChoice<PrismObject<ConnectorHostType>> choice = super.createDropDown(id, choices, renderer, required);
            choice.add(new AjaxFormComponentUpdatingBehavior("change") {

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    discoverConnectorsPerformed(target);
                }
            });
            return choice;
        }
    };
}
Also used : ConnectorHostType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType) IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) IModel(org.apache.wicket.model.IModel) DropDownFormGroup(com.evolveum.midpoint.web.component.form.DropDownFormGroup) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)52 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)51 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)26 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)25 TextField (org.apache.wicket.markup.html.form.TextField)20 Label (org.apache.wicket.markup.html.basic.Label)18 List (java.util.List)16 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)16 IModel (org.apache.wicket.model.IModel)16 ArrayList (java.util.ArrayList)15 ListItem (org.apache.wicket.markup.html.list.ListItem)13 ListView (org.apache.wicket.markup.html.list.ListView)13 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)10 ComponentFeedbackMessageFilter (org.apache.wicket.feedback.ComponentFeedbackMessageFilter)9 CheckBox (org.apache.wicket.markup.html.form.CheckBox)8 FeedbackPanel (org.apache.wicket.markup.html.panel.FeedbackPanel)8 DropDownChoice (org.apache.wicket.markup.html.form.DropDownChoice)7 Form (org.apache.wicket.markup.html.form.Form)7 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)5 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)5