Search in sources :

Example 21 with ReadOnlyModel

use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.

the class OrgTreePanel method initLayout.

private void initLayout(ModelServiceLocator serviceLocator) {
    WebMarkupContainer treeHeader = new WebMarkupContainer(ID_TREE_HEADER);
    treeHeader.setOutputMarkupId(true);
    add(treeHeader);
    String title = StringUtils.isEmpty(treeTitleKey) ? "TreeTablePanel.hierarchy" : treeTitleKey;
    Label treeTitle = new Label(ID_TREE_TITLE, createStringResource(title));
    treeHeader.add(treeTitle);
    List<InlineMenuItem> actions = createTreeMenu();
    DropdownButtonDto model = new DropdownButtonDto(null, "fa fa-cog", null, actions);
    DropdownButtonPanel treeMenu = new DropdownButtonPanel(ID_TREE_MENU, model) {

        private static final long serialVersionUID = 1L;

        @Override
        protected String getSpecialButtonClass() {
            return "btn-default";
        }

        @Override
        protected boolean visibleCaret() {
            return false;
        }
    };
    treeMenu.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !actions.isEmpty();
        }
    });
    treeMenu.setOutputMarkupId(true);
    treeMenu.setOutputMarkupPlaceholderTag(true);
    treeHeader.add(treeMenu);
    ISortableTreeProvider provider = new OrgTreeProvider(this, getModel(), preselecteOrgsList) {

        @Override
        protected ObjectFilter getCustomFilter() {
            return OrgTreePanel.this.getCustomFilter();
        }
    };
    WebMarkupContainer treeContainer = new WebMarkupContainer(ID_TREE_CONTAINER) {

        private static final long serialVersionUID = 1L;

        @Override
        public void renderHead(IHeaderResponse response) {
            super.renderHead(response);
            // method computes height based on document.innerHeight() -
            // screen height;
            Component form = OrgTreePanel.this.getParent().get("memberPanel");
            if (form != null) {
            // TODO fix
            // response.render(OnDomReadyHeaderItem.forScript(
            // "updateHeight('" + getMarkupId() + "', ['#" + form.getMarkupId() + "'], ['#"
            // + OrgTreePanel.this.get(ID_TREE_HEADER).getMarkupId() + "'])"));
            }
        }
    };
    add(treeContainer);
    TreeStateModel treeStateMode = new TreeStateModel(this, provider, getOrgTreeStateStorage()) {

        private static final long serialVersionUID = 1L;

        @Override
        public Set<TreeSelectableBean<OrgType>> getExpandedItems() {
            return OrgTreePanel.this.getExpandedItems(getOrgTreeStateStorage());
        }

        @Override
        public Set<TreeSelectableBean<OrgType>> getCollapsedItems() {
            return OrgTreePanel.this.getCollapsedItems(getOrgTreeStateStorage());
        }

        @Override
        public void setCollapsedItems(TreeStateSet items) {
            OrgTreePanel.this.setCollapsedItems(null, getOrgTreeStateStorage());
        }
    };
    contentPannels = new ArrayList<OrgTreeFolderContent>();
    MidpointNestedTree tree = new MidpointNestedTree(ID_TREE, provider, treeStateMode) {

        @Override
        protected Component newContentComponent(String id, IModel<TreeSelectableBean<OrgType>> model) {
            OrgTreeFolderContent contentPannel = new OrgTreeFolderContent(id, model, selectable, selected, this, getOrgTreeStateStorage()) {

                @Override
                protected void selectTreeItemPerformed(TreeSelectableBean<OrgType> selected, AjaxRequestTarget target) {
                    OrgTreePanel.this.selectTreeItemPerformed(selected, target);
                }

                @Override
                protected IModel<Boolean> getCheckboxModel(IModel<TreeSelectableBean<OrgType>> org) {
                    return OrgTreePanel.this.getCheckBoxValueModel(org);
                }

                @Override
                protected void onUpdateCheckbox(AjaxRequestTarget target) {
                    selected = getModel();
                    onOrgTreeCheckBoxSelectionPerformed(target, selected);
                }

                @Override
                protected IModel<List<InlineMenuItem>> createInlineMenuItemsModel() {
                    return new ReadOnlyModel<>(() -> createTreeChildrenMenuInternal(model.getObject(), serviceLocator.getCompiledGuiProfile()));
                }
            };
            contentPannels.add(contentPannel);
            return contentPannel;
        }

        @Override
        public void collapse(TreeSelectableBean<OrgType> collapsedItem) {
            super.collapse(collapsedItem);
            Set<TreeSelectableBean<OrgType>> items = OrgTreePanel.this.getExpandedItems(getOrgTreeStateStorage());
            if (items != null && items.contains(collapsedItem)) {
                items.remove(collapsedItem);
            }
            OrgTreePanel.this.setExpandedItems((TreeStateSet) items, getOrgTreeStateStorage());
            OrgTreePanel.this.addCollapsedItem(collapsedItem, getOrgTreeStateStorage());
        }

        @Override
        public void expand(TreeSelectableBean<OrgType> expandedItem) {
            super.expand(expandedItem);
            Set<TreeSelectableBean<OrgType>> items = OrgTreePanel.this.getCollapsedItems(getOrgTreeStateStorage());
            if (items != null && items.contains(expandedItem)) {
                items.remove(expandedItem);
            }
            OrgTreePanel.this.setCollapsedItems((TreeStateSet) items, getOrgTreeStateStorage());
            OrgTreePanel.this.addExpandedItem(expandedItem, getOrgTreeStateStorage());
        }
    };
    tree.setItemReuseStrategy(new ReuseIfModelsEqualStrategy());
    tree.setOutputMarkupId(true);
    tree.add(new WindowsTheme());
    treeContainer.add(tree);
}
Also used : Label(org.apache.wicket.markup.html.basic.Label) WindowsTheme(org.apache.wicket.extensions.markup.html.repeater.tree.theme.WindowsTheme) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ReuseIfModelsEqualStrategy(org.apache.wicket.markup.repeater.ReuseIfModelsEqualStrategy) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) OrgTreeProvider(com.evolveum.midpoint.web.page.admin.users.component.OrgTreeProvider) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) Component(org.apache.wicket.Component) IModel(org.apache.wicket.model.IModel) DropdownButtonDto(com.evolveum.midpoint.gui.api.component.button.DropdownButtonDto) TreeStateSet(com.evolveum.midpoint.web.page.admin.users.dto.TreeStateSet) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ISortableTreeProvider(org.apache.wicket.extensions.markup.html.repeater.tree.ISortableTreeProvider) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) TreeSelectableBean(com.evolveum.midpoint.web.component.util.TreeSelectableBean) DropdownButtonPanel(com.evolveum.midpoint.gui.api.component.button.DropdownButtonPanel)

Example 22 with ReadOnlyModel

use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.

the class MainMenuPanel method createSubmenu.

private void createSubmenu(final ListItem<MenuItem> listItem) {
    IModel<MenuItem> menuItem = listItem.getModel();
    listItem.add(AttributeModifier.replace("class", new ReadOnlyModel<>(() -> {
        if (menuItem.getObject().isMenuActive(getPageBase())) {
            return "active";
        }
        return null;
    })));
    Link<String> subLink = new Link<String>(ID_SUB_LINK) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            menuItemPerformed(menuItem.getObject());
        }
    };
    listItem.add(subLink);
    WebMarkupContainer subLinkIcon = new WebMarkupContainer(ID_SUB_LINK_ICON);
    subLinkIcon.add(AttributeAppender.append("class", new PropertyModel<>(menuItem, MainMenuItem.F_ICON_CLASS)));
    subLink.add(subLinkIcon);
    Label subLabel = new Label(ID_SUB_LABEL, new StringResourceModel("${nameModel}", menuItem).setDefaultValue(new PropertyModel<>(menuItem, "nameModel")));
    subLink.add(subLabel);
}
Also used : ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) PropertyModel(org.apache.wicket.model.PropertyModel) Label(org.apache.wicket.markup.html.basic.Label) StringResourceModel(org.apache.wicket.model.StringResourceModel) Link(org.apache.wicket.markup.html.link.Link) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 23 with ReadOnlyModel

use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.

the class CorrelationContextPanel method initLayout.

@Override
protected void initLayout() {
    IModel<CorrelationContextDto> correlationCtxModel = createCorrelationContextModel();
    ListView<String> headers = new ListView<>(ID_HEADERS, new PropertyModel<>(correlationCtxModel, F_OPTION_HEADERS)) {

        @Override
        protected void populateItem(ListItem<String> item) {
            item.add(new Label(ID_HEADER, item.getModel()));
        }
    };
    add(headers);
    ListView<CorrelationOptionDto> actions = new ListView<>(ID_ACTIONS, new PropertyModel<>(correlationCtxModel, CorrelationContextDto.F_CORRELATION_OPTIONS)) {

        @Override
        protected void populateItem(ListItem<CorrelationOptionDto> item) {
            AjaxButton actionButton = new AjaxButton(ID_ACTION) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    CaseType correlationCase = getObjectDetailsModels().getObjectType();
                    WorkItemId workItemId = WorkItemId.of(correlationCase.getWorkItem().get(0));
                    AbstractWorkItemOutputType output = new AbstractWorkItemOutputType().outcome(item.getModelObject().getIdentifier());
                    Task task = getPageBase().createSimpleTask("DecideCorrelation");
                    OperationResult result = task.getResult();
                    try {
                        getPageBase().getCaseService().completeWorkItem(workItemId, output, task, result);
                        result.computeStatusIfUnknown();
                    } catch (Throwable e) {
                        result.recordFatalError("Cannot finish correlation process, " + e.getMessage(), e);
                    }
                    getPageBase().showResult(result);
                    target.add(getPageBase().getFeedbackPanel());
                }
            };
            actionButton.add(new Label(ID_ACTION_LABEL, item.getModelObject().isNewOwner() ? TEXT_CREATE_NEW : TEXT_CORRELATE));
            item.add(actionButton);
        }
    };
    add(actions);
    ListView<CorrelationOptionDto> referenceIds = new ListView<>(ID_NAMES, new PropertyModel<>(correlationCtxModel, CorrelationContextDto.F_CORRELATION_OPTIONS)) {

        @Override
        protected void populateItem(ListItem<CorrelationOptionDto> item) {
            // A full-object reference to the candidate owner
            ReadOnlyModel<ObjectReferenceType> referenceModel = new ReadOnlyModel<>(() -> {
                CorrelationOptionDto optionDto = item.getModelObject();
                if (!optionDto.isNewOwner()) {
                    return ObjectTypeUtil.createObjectRefWithFullObject(optionDto.getObject());
                } else {
                    // GUI cannot currently open object that does not exist in the repository.
                    return null;
                }
            });
            item.add(new LinkedReferencePanel<>(ID_NAME, referenceModel));
        }
    };
    add(referenceIds);
    ListView<CorrelationPropertyDefinition> rows = new ListView<>(ID_ROWS, new PropertyModel<>(correlationCtxModel, CorrelationContextDto.F_CORRELATION_PROPERTIES)) {

        @Override
        protected void populateItem(ListItem<CorrelationPropertyDefinition> item) {
            // First column contains the property name
            item.add(new Label(ID_ATTR_NAME, new PropertyModel<>(item.getModel(), CorrelationPropertyDefinition.F_DISPLAY_NAME)));
            // Here are columns for values for individual options
            item.add(createColumnsForPropertyRow(correlationCtxModel, item));
        }
    };
    add(rows);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Label(org.apache.wicket.markup.html.basic.Label) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) ListView(org.apache.wicket.markup.html.list.ListView) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) WorkItemId(com.evolveum.midpoint.schema.util.WorkItemId) PropertyModel(org.apache.wicket.model.PropertyModel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 24 with ReadOnlyModel

use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.

the class DisplayNamePanel method createHeaderModel.

protected IModel<String> createHeaderModel() {
    // TODO: align with DisplayNameModel
    return new ReadOnlyModel<>(() -> {
        if (getModelObject() == null) {
            return "";
        }
        if (ObjectType.class.isAssignableFrom(getModelObject().getClass())) {
            return WebComponentUtil.getEffectiveName((ObjectType) getModelObject(), AbstractRoleType.F_DISPLAY_NAME);
        }
        if (isObjectPolicyConfigurationType()) {
            QName typeValue = WebComponentUtil.getValue(getModel().getObject().asPrismContainerValue(), ObjectPolicyConfigurationType.F_TYPE, QName.class);
            ObjectReferenceType objectTemplate = ((ObjectPolicyConfigurationType) getModel().getObject()).getObjectTemplateRef();
            if (objectTemplate == null || objectTemplate.getTargetName() == null) {
                return "";
            }
            String objectTemplateNameValue = objectTemplate.getTargetName().toString();
            StringBuilder sb = new StringBuilder();
            if (typeValue != null) {
                sb.append(typeValue.getLocalPart()).append(" - ");
            }
            sb.append(objectTemplateNameValue);
            return sb.toString();
        }
        PrismProperty<?> name = getModelObject().asPrismContainerValue().findProperty(ObjectType.F_NAME);
        if (name == null || name.isEmpty()) {
            return "";
        }
        if (QNameUtil.match(DOMUtil.XSD_STRING, name.getDefinition().getTypeName())) {
            return (String) name.getRealValue();
        } else if (QNameUtil.match(PolyStringType.COMPLEX_TYPE, name.getDefinition().getTypeName())) {
            return WebComponentUtil.getTranslatedPolyString((PolyString) name.getRealValue());
        }
        return name.getRealValue().toString();
    });
}
Also used : ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) QName(javax.xml.namespace.QName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 25 with ReadOnlyModel

use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.

the class ImagePanel method initLayout.

private void initLayout() {
    Label image = new Label(ID_IMAGE);
    image.add(AttributeModifier.replace("class", new PropertyModel<>(getModel(), "icon.cssClass")));
    image.add(AttributeModifier.replace("title", new PropertyModel<>(getModel(), "tooltip.orig")));
    image.add(AttributeAppender.append("style", new ReadOnlyModel<>(() -> StringUtils.isNotBlank(getColor()) ? "color: " + getColor() + ";" : "")));
    image.setOutputMarkupId(true);
    image.add(new VisibleBehaviour(() -> getModelObject() != null && getModelObject().getIcon() != null && StringUtils.isNotEmpty(getModelObject().getIcon().getCssClass())));
    add(image);
    ExternalImage customLogoImgSrc = new ExternalImage(ID_IMAGE_SRC, WebComponentUtil.getIconUrlModel(getModelObject() != null ? getModelObject().getIcon() : null));
    customLogoImgSrc.setOutputMarkupId(true);
    customLogoImgSrc.add(new VisibleBehaviour(() -> getModelObject() != null && getModelObject().getIcon() != null && StringUtils.isNotEmpty(getModelObject().getIcon().getImageUrl())));
    add(customLogoImgSrc);
}
Also used : ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) Label(org.apache.wicket.markup.html.basic.Label) PropertyModel(org.apache.wicket.model.PropertyModel) ExternalImage(org.apache.wicket.markup.html.image.ExternalImage)

Aggregations

ReadOnlyModel (com.evolveum.midpoint.gui.api.model.ReadOnlyModel)35 Label (org.apache.wicket.markup.html.basic.Label)14 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)13 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)10 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)9 IModel (org.apache.wicket.model.IModel)9 ListItem (org.apache.wicket.markup.html.list.ListItem)8 PropertyModel (org.apache.wicket.model.PropertyModel)8 ListView (org.apache.wicket.markup.html.list.ListView)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 ArrayList (java.util.ArrayList)5 QName (javax.xml.namespace.QName)5 List (java.util.List)4 StringResourceModel (org.apache.wicket.model.StringResourceModel)4 ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)3 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)3 DisplayType (com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType)3 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)3