Search in sources :

Example 1 with OnChangeAjaxBehavior

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

the class AutoCompleteItemDefinitionPanel method initLayout.

private void initLayout(final IModel<ItemDefinition<?>> model) {
    final Model<String> itemDefinitionAsStringModel = new Model<String>(null);
    AutoCompleteTextField<String> input = new AutoCompleteTextField<String>(ID_INPUT, itemDefinitionAsStringModel, String.class, createAutoCompleteSettings()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<String> getChoices(String input) {
            List<String> defsAsString = new ArrayList<>();
            for (ItemDefinition<?> def : listChoices(input).values()) {
                defsAsString.add(def.getName().getLocalPart());
            }
            return defsAsString.iterator();
        }

        @Override
        protected void onConfigure() {
            itemDefinitionAsStringModel.setObject(null);
        }
    };
    input.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String newValue = itemDefinitionAsStringModel.getObject();
            if (StringUtils.isNotBlank(newValue)) {
                ItemDefinition<?> def = listChoices("").get(newValue);
                if (def != null) {
                    model.setObject(def);
                }
            }
        }
    });
    add(input);
}
Also used : ArrayList(java.util.ArrayList) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) Model(org.apache.wicket.model.Model) IModel(org.apache.wicket.model.IModel)

Example 2 with OnChangeAjaxBehavior

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

the class AutoCompleteQNamePanel method initLayout.

private void initLayout(final IModel<QName> model) {
    setOutputMarkupId(true);
    AutoCompleteSettings autoCompleteSettings = createAutoCompleteSettings();
    final IModel<String> stringModel = new Model<String>() {

        @Override
        public void setObject(String object) {
            super.setObject(object);
            model.setObject(convertToQname(object));
        }
    };
    // The inner autocomplete field is always String. Non-string auto-complete fields are problematic
    final AutoCompleteTextField<String> input = new AutoCompleteTextField<String>(ID_INPUT, stringModel, String.class, autoCompleteSettings) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<String> getChoices(String input) {
            return getIterator(input);
        }
    };
    input.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String inputString = stringModel.getObject();
            if (StringUtils.isBlank(inputString)) {
                QName modelObject = model.getObject();
                if (modelObject != null) {
                    model.setObject(null);
                    AutoCompleteQNamePanel.this.onChange(target);
                }
            } else {
                QName inputQName = convertToQname(stringModel.getObject());
                if (inputQName == null) {
                // We have some input, but it does not match any QName. Just do nothing.
                } else {
                    QName modelObject = model.getObject();
                    if (inputQName.equals(modelObject)) {
                        model.setObject(inputQName);
                        AutoCompleteQNamePanel.this.onChange(target);
                    }
                }
            }
        }
    });
    add(input);
}
Also used : 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) QName(javax.xml.namespace.QName) Model(org.apache.wicket.model.Model) IModel(org.apache.wicket.model.IModel) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior)

Example 3 with OnChangeAjaxBehavior

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

the class ObjectBrowserPanel method initLayout.

private void initLayout(Class<? extends O> type, final List<QName> supportedTypes, final boolean multiselect) {
    WebMarkupContainer typePanel = new WebMarkupContainer(ID_TYPE_PANEL);
    typePanel.setOutputMarkupId(true);
    typePanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return supportedTypes.size() != 1;
        }
    });
    add(typePanel);
    DropDownChoice<QName> typeSelect = new DropDownChoice<QName>(ID_TYPE, typeModel, new ListModel<QName>(supportedTypes), new QNameChoiceRenderer());
    typeSelect.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            ObjectListPanel<O> listPanel = (ObjectListPanel<O>) get(ID_TABLE);
            listPanel = createObjectListPanel(qnameToCompileTimeClass(typeModel.getObject()), multiselect);
            addOrReplace(listPanel);
            target.add(listPanel);
        }
    });
    typePanel.add(typeSelect);
    ObjectListPanel<O> listPanel = createObjectListPanel(type, multiselect);
    add(listPanel);
    AjaxButton addButton = new AjaxButton(ID_BUTTON_ADD, createStringResource("userBrowserDialog.button.addButton")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            List<O> selected = ((PopupObjectListPanel) getParent().get(ID_TABLE)).getSelectedObjects();
            QName type = ObjectBrowserPanel.this.typeModel.getObject();
            ObjectBrowserPanel.this.addPerformed(target, type, selected);
        }
    };
    addButton.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return multiselect;
        }
    });
    add(addButton);
}
Also used : QNameChoiceRenderer(com.evolveum.midpoint.web.component.input.QNameChoiceRenderer) QName(javax.xml.namespace.QName) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Example 4 with OnChangeAjaxBehavior

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

the class OrgMemberPanel method initSearch.

@Override
protected void initSearch(Form form) {
    /// TODO: move to utils class??
    List<ObjectTypes> objectTypes = Arrays.asList(ObjectTypes.values());
    Collections.sort(objectTypes, new Comparator<ObjectTypes>() {

        @Override
        public int compare(ObjectTypes o1, ObjectTypes o2) {
            Validate.notNull(o1);
            Validate.notNull(o2);
            String type1 = o1.getValue();
            String type2 = o2.getValue();
            return String.CASE_INSENSITIVE_ORDER.compare(type1, type2);
        }
    });
    DropDownChoice<ObjectTypes> objectType = new DropDownChoice<ObjectTypes>(ID_SEARCH_BY_TYPE, Model.of(OBJECT_TYPES_DEFAULT), objectTypes, new EnumChoiceRenderer<ObjectTypes>());
    objectType.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            refreshTable(target);
        }
    });
    objectType.setOutputMarkupId(true);
    form.add(objectType);
    DropDownChoice<String> seachScrope = new DropDownChoice<String>(ID_SEARCH_SCOPE, Model.of(SEARCH_SCOPE_SUBTREE), SEARCH_SCOPE_VALUES, new StringResourceChoiceRenderer("TreeTablePanel.search.scope"));
    seachScrope.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            refreshTable(target);
        }
    });
    seachScrope.setOutputMarkupId(true);
    form.add(seachScrope);
}
Also used : StringResourceChoiceRenderer(com.evolveum.midpoint.web.util.StringResourceChoiceRenderer) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice)

Example 5 with OnChangeAjaxBehavior

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

the class ResourceContentTabPanel method initLayout.

private void initLayout(final IModel<PrismObject<ResourceType>> model, final PageBase parentPage) {
    setOutputMarkupId(true);
    final Form mainForm = new Form(ID_MAIN_FORM);
    mainForm.setOutputMarkupId(true);
    mainForm.addOrReplace(initTable(model));
    add(mainForm);
    AutoCompleteTextPanel<String> intent = new AutoCompleteTextPanel<String>(ID_INTENT, new PropertyModel<String>(resourceContentSearch, "intent"), String.class) {

        private static final long serialVersionUID = 1L;

        @Override
        public Iterator<String> getIterator(String input) {
            RefinedResourceSchema refinedSchema = null;
            try {
                refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(model.getObject(), parentPage.getPrismContext());
            } catch (SchemaException e) {
                return new ArrayList<String>().iterator();
            }
            return RefinedResourceSchemaImpl.getIntentsForKind(refinedSchema, getKind()).iterator();
        }
    };
    intent.getBaseFormComponent().add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(get(ID_REAL_OBJECT_CLASS));
            updateResourceContentSearch();
            mainForm.addOrReplace(initTable(model));
            target.add(mainForm);
        }
    });
    intent.setOutputMarkupId(true);
    intent.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !isUseObjectClass();
        }
    });
    add(intent);
    Label realObjectClassLabel = new Label(ID_REAL_OBJECT_CLASS, new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            RefinedObjectClassDefinition ocDef;
            try {
                RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(model.getObject(), parentPage.getPrismContext());
                if (refinedSchema == null) {
                    return "NO SCHEMA DEFINED";
                }
                ocDef = refinedSchema.getRefinedDefinition(getKind(), getIntent());
                if (ocDef != null) {
                    return ocDef.getObjectClassDefinition().getTypeName().getLocalPart();
                }
            } catch (SchemaException e) {
            }
            return "NOT FOUND";
        }
    });
    realObjectClassLabel.setOutputMarkupId(true);
    add(realObjectClassLabel);
    AutoCompleteQNamePanel objectClassPanel = new AutoCompleteQNamePanel(ID_OBJECT_CLASS, new PropertyModel<QName>(resourceContentSearch, "objectClass")) {

        private static final long serialVersionUID = 1L;

        @Override
        public Collection<QName> loadChoices() {
            return createObjectClassChoices(model);
        }

        @Override
        protected void onChange(AjaxRequestTarget target) {
            LOGGER.trace("Object class panel update: {}", isUseObjectClass());
            updateResourceContentSearch();
            mainForm.addOrReplace(initTable(model));
            target.add(mainForm);
        }
    };
    objectClassPanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return isUseObjectClass();
        }
    });
    add(objectClassPanel);
    AjaxLink<Boolean> repoSearch = new AjaxLink<Boolean>(ID_REPO_SEARCH, new PropertyModel<Boolean>(resourceContentSearch, "resourceSearch")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            isRepoSearch = true;
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT).setResourceSearch(Boolean.FALSE);
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT).setResourceSearch(Boolean.FALSE);
            resourceContentSearch.getObject().setResourceSearch(Boolean.FALSE);
            updateResourceContentSearch();
            mainForm.addOrReplace(initRepoContent(model));
            target.add(getParent().addOrReplace(mainForm));
            target.add(this);
            target.add(getParent().get(ID_RESOURCE_SEARCH).add(AttributeModifier.replace("class", "btn btn-sm btn-default")));
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            if (!getModelObject().booleanValue())
                add(AttributeModifier.replace("class", "btn btn-sm btn-default active"));
        }
    };
    add(repoSearch);
    AjaxLink<Boolean> resourceSearch = new AjaxLink<Boolean>(ID_RESOURCE_SEARCH, new PropertyModel<Boolean>(resourceContentSearch, "resourceSearch")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            isRepoSearch = false;
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT).setResourceSearch(Boolean.TRUE);
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT).setResourceSearch(Boolean.TRUE);
            updateResourceContentSearch();
            resourceContentSearch.getObject().setResourceSearch(Boolean.TRUE);
            mainForm.addOrReplace(initResourceContent(model));
            target.add(getParent().addOrReplace(mainForm));
            target.add(this.add(AttributeModifier.append("class", " active")));
            target.add(getParent().get(ID_REPO_SEARCH).add(AttributeModifier.replace("class", "btn btn-sm btn-default")));
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            getModelObject().booleanValue();
            if (getModelObject().booleanValue())
                add(AttributeModifier.replace("class", "btn btn-sm btn-default active"));
        }
    };
    add(resourceSearch);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Form(org.apache.wicket.markup.html.form.Form) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) AutoCompleteQNamePanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Aggregations

AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)16 OnChangeAjaxBehavior (org.apache.wicket.ajax.form.OnChangeAjaxBehavior)16 DropDownChoice (org.apache.wicket.markup.html.form.DropDownChoice)10 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)6 QName (javax.xml.namespace.QName)6 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)6 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)4 ArrayList (java.util.ArrayList)4 Label (org.apache.wicket.markup.html.basic.Label)4 Form (org.apache.wicket.markup.html.form.Form)4 QNameChoiceRenderer (com.evolveum.midpoint.web.component.input.QNameChoiceRenderer)3 StringResourceChoiceRenderer (com.evolveum.midpoint.web.util.StringResourceChoiceRenderer)3 List (java.util.List)3 AutoCompleteTextField (org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField)3 AceEditor (com.evolveum.midpoint.web.component.AceEditor)2 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)2 DropDownFormGroup (com.evolveum.midpoint.web.component.form.DropDownFormGroup)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 CheckBox (org.apache.wicket.markup.html.form.CheckBox)2