Search in sources :

Example 1 with VisibleEnableBehaviour

use of com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour in project midpoint by Evolveum.

the class PasswordPanel method initLayout.

private void initLayout(final IModel<ProtectedStringType> model, final boolean isReadOnly) {
    setOutputMarkupId(true);
    final WebMarkupContainer inputContainer = new WebMarkupContainer(ID_INPUT_CONTAINER) {

        @Override
        public boolean isVisible() {
            return passwordInputVisble;
        }
    };
    inputContainer.setOutputMarkupId(true);
    add(inputContainer);
    final PasswordTextField password1 = new PasswordTextField(ID_PASSWORD_ONE, new PasswordModel(model));
    password1.setRequired(false);
    password1.setResetPassword(false);
    password1.setOutputMarkupId(true);
    password1.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    inputContainer.add(password1);
    final PasswordTextField password2 = new PasswordTextField(ID_PASSWORD_TWO, new Model<String>());
    password2.setRequired(false);
    password2.setResetPassword(false);
    password2.setOutputMarkupId(true);
    password2.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    inputContainer.add(password2);
    password1.add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            boolean required = !StringUtils.isEmpty(password1.getModel().getObject());
            password2.setRequired(required);
        //fix of MID-2463
        //				target.add(password2);
        //				target.appendJavaScript("$(\"#"+ password2.getMarkupId() +"\").focus()");
        }
    });
    password2.add(new PasswordValidator(password1, password2));
    final WebMarkupContainer linkContainer = new WebMarkupContainer(ID_LINK_CONTAINER) {

        @Override
        public boolean isVisible() {
            return !passwordInputVisble;
        }
    };
    inputContainer.setOutputMarkupId(true);
    linkContainer.setOutputMarkupId(true);
    add(linkContainer);
    final Label passwordSetLabel = new Label(ID_PASSWORD_SET, new ResourceModel("passwordPanel.passwordSet"));
    linkContainer.add(passwordSetLabel);
    final Label passwordRemoveLabel = new Label(ID_PASSWORD_REMOVE, new ResourceModel("passwordPanel.passwordRemoveLabel"));
    passwordRemoveLabel.setVisible(false);
    linkContainer.add(passwordRemoveLabel);
    AjaxLink link = new AjaxLink(ID_CHANGE_PASSWORD_LINK) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            onLinkClick(target);
        }

        @Override
        public boolean isVisible() {
            return !passwordInputVisble;
        }
    };
    link.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !isReadOnly;
        }
    });
    link.setBody(new ResourceModel("passwordPanel.passwordChange"));
    link.setOutputMarkupId(true);
    linkContainer.add(link);
    final WebMarkupContainer removeButtonContainer = new WebMarkupContainer(ID_REMOVE_BUTTON_CONTAINER);
    AjaxLink removePassword = new AjaxLink(ID_REMOVE_PASSWORD_LINK) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            onRemovePassword(model, target);
        }
    };
    removePassword.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            PageBase pageBase = (PageBase) getPage();
            if (pageBase == null) {
                return false;
            }
            if (pageBase instanceof PageSelfProfile) {
                return false;
            }
            if (pageBase instanceof PageUser && model.getObject() != null && !model.getObject().isEmpty()) {
                return true;
            }
            return false;
        }
    });
    removePassword.setBody(new ResourceModel("passwordPanel.passwordRemove"));
    removePassword.setOutputMarkupId(true);
    removeButtonContainer.add(removePassword);
    add(removeButtonContainer);
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) Label(org.apache.wicket.markup.html.basic.Label) PasswordTextField(org.apache.wicket.markup.html.form.PasswordTextField) PageSelfProfile(com.evolveum.midpoint.web.page.self.PageSelfProfile) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PageUser(com.evolveum.midpoint.web.page.admin.users.PageUser) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ResourceModel(org.apache.wicket.model.ResourceModel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Example 2 with VisibleEnableBehaviour

use of com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour in project midpoint by Evolveum.

the class PageBase method createFocusPageNewEditMenu.

private void createFocusPageNewEditMenu(List<MenuItem> submenu, String newKey, String editKey, final Class<? extends PageAdmin> newPageClass, boolean checkAuthorization) {
    MenuItem edit = new MenuItem(createStringResource(editKey), newPageClass, null, new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return false;
        }

        @Override
        public boolean isVisible() {
            if (!getPage().getClass().equals(newPageClass)) {
                return false;
            }
            if (getPage() instanceof PageAdminFocus) {
                PageAdminFocus page = (PageAdminFocus) getPage();
                return page.isEditingFocus();
            } else if (getPage() instanceof PageResourceWizard) {
                PageResourceWizard page = (PageResourceWizard) getPage();
                return !page.isNewResource();
            } else {
                return false;
            }
        }
    });
    submenu.add(edit);
    MenuItem newMenu = new MenuItem(createStringResource(newKey), newPageClass, null, new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !checkAuthorization || isMenuItemAuthorized(newPageClass);
        }
    }) {

        private static final long serialVersionUID = 1L;

        @Override
        protected boolean isMenuActive() {
            if (!PageBase.this.getPage().getClass().equals(newPageClass)) {
                return false;
            }
            if (PageBase.this.getPage() instanceof PageAdminFocus) {
                PageAdminFocus page = (PageAdminFocus) PageBase.this.getPage();
                return !page.isEditingFocus();
            } else if (PageBase.this.getPage() instanceof PageResourceWizard) {
                PageResourceWizard page = (PageResourceWizard) PageBase.this.getPage();
                return page.isNewResource();
            } else {
                return false;
            }
        }
    };
    submenu.add(newMenu);
}
Also used : PageAdminFocus(com.evolveum.midpoint.web.page.admin.PageAdminFocus) PageResourceWizard(com.evolveum.midpoint.web.page.admin.resources.PageResourceWizard) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Example 3 with VisibleEnableBehaviour

use of com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour 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 VisibleEnableBehaviour

use of com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour in project midpoint by Evolveum.

the class TypedAssignablePanel method createObjectListPanel.

private PopupObjectListPanel<T> createObjectListPanel(String id, final String countId, final QName type) {
    PopupObjectListPanel<T> listPanel = new PopupObjectListPanel<T>(id, qnameToCompileTimeClass(type), true, getPageBase()) {

        @Override
        protected void onUpdateCheckbox(AjaxRequestTarget target) {
            refreshCounts(target);
        }

        @Override
        protected ObjectQuery addFilterToContentQuery(ObjectQuery query) {
            if (type.equals(RoleType.COMPLEX_TYPE)) {
                LOGGER.debug("Loading roles which the current user has right to assign");
                OperationResult result = new OperationResult(OPERATION_LOAD_ASSIGNABLE_ROLES);
                ObjectFilter filter = null;
                try {
                    ModelInteractionService mis = parentPage.getModelInteractionService();
                    RoleSelectionSpecification roleSpec = mis.getAssignableRoleSpecification(SecurityUtils.getPrincipalUser().getUser().asPrismObject(), result);
                    filter = roleSpec.getFilter();
                } catch (Exception ex) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load available roles", ex);
                    result.recordFatalError("Couldn't load available roles", ex);
                } finally {
                    result.recomputeStatus();
                }
                if (!result.isSuccess() && !result.isHandledError()) {
                    parentPage.showResult(result);
                }
                if (query == null) {
                    query = new ObjectQuery();
                }
                query.addFilter(filter);
            }
            return query;
        }
    };
    listPanel.setOutputMarkupId(true);
    listPanel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return type.equals(typeModel.getObject());
        }
    });
    return listPanel;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ModelInteractionService(com.evolveum.midpoint.model.api.ModelInteractionService) RoleSelectionSpecification(com.evolveum.midpoint.model.api.RoleSelectionSpecification) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 5 with VisibleEnableBehaviour

use of com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour in project midpoint by Evolveum.

the class OperationResultPanel method initParams.

private void initParams(WebMarkupContainer operationContent, final IModel<OpResult> model, Page parentPage) {
    Label paramsLabel = new Label("paramsLabel", parentPage.getString("FeedbackAlertMessageDetails.params"));
    paramsLabel.setOutputMarkupId(true);
    paramsLabel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return CollectionUtils.isNotEmpty(model.getObject().getParams());
        }
    });
    operationContent.add(paramsLabel);
    ListView<Param> params = new ListView<Param>(ID_PARAMS, createParamsModel(model)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<Param> item) {
            item.add(new Label("paramName", new PropertyModel<Object>(item.getModel(), "name")));
            item.add(new Label("paramValue", new PropertyModel<Object>(item.getModel(), "value")));
        }
    };
    params.setOutputMarkupId(true);
    params.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return CollectionUtils.isNotEmpty(model.getObject().getParams());
        }
    });
    operationContent.add(params);
    ListView<OpResult> subresults = new ListView<OpResult>("subresults", createSubresultsModel(model)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<OpResult> item) {
            Panel subresult = new OperationResultPanel("subresult", item.getModel(), getPage());
            subresult.setOutputMarkupId(true);
            item.add(subresult);
        }
    };
    subresults.setOutputMarkupId(true);
    subresults.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return CollectionUtils.isNotEmpty(model.getObject().getSubresults());
        }
    });
    operationContent.add(subresults);
}
Also used : Label(org.apache.wicket.markup.html.basic.Label) PropertyModel(org.apache.wicket.model.PropertyModel) Panel(org.apache.wicket.markup.html.panel.Panel) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) ListView(org.apache.wicket.markup.html.list.ListView) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ListItem(org.apache.wicket.markup.html.list.ListItem)

Aggregations

VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)272 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)184 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)146 Label (org.apache.wicket.markup.html.basic.Label)119 IModel (org.apache.wicket.model.IModel)69 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)62 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)48 ListItem (org.apache.wicket.markup.html.list.ListItem)42 PropertyModel (org.apache.wicket.model.PropertyModel)40 ListView (org.apache.wicket.markup.html.list.ListView)36 List (java.util.List)35 ArrayList (java.util.ArrayList)30 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)30 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)25 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)24 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)23 QName (javax.xml.namespace.QName)23 AttributeModifier (org.apache.wicket.AttributeModifier)23 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)21