Search in sources :

Example 6 with ReadOnlyModel

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

the class FocusProjectionsPanel method initLayout.

protected void initLayout() {
    IModel<Integer> deadShadows = new ReadOnlyModel<>(this::countDeadShadows);
    Label label = new Label(ID_DEAD_SHADOWS, deadShadows);
    label.add(new VisibleBehaviour(() -> deadShadows.getObject() > 0));
    add(label);
    MultivalueContainerListPanelWithDetailsPanel<ShadowType> multivalueContainerListPanel = new MultivalueContainerListPanelWithDetailsPanel<ShadowType>(ID_SHADOW_TABLE, ShadowType.class, getPanelConfiguration()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected ISelectableDataProvider<ShadowType, PrismContainerValueWrapper<ShadowType>> createProvider() {
            return new ProjectionsListProvider(FocusProjectionsPanel.this, getSearchModel(), loadShadowModel()) {

                @Override
                protected PageStorage getPageStorage() {
                    PageStorage storage = getSession().getSessionStorage().getPageStorageMap().get(SessionStorage.KEY_FOCUS_PROJECTION_TABLE);
                    if (storage == null) {
                        storage = getSession().getSessionStorage().initPageStorage(SessionStorage.KEY_FOCUS_PROJECTION_TABLE);
                    }
                    return storage;
                }
            };
        }

        @Override
        protected void newItemPerformed(AjaxRequestTarget target, AssignmentObjectRelation relation) {
            List<QName> supportedTypes = Arrays.asList(ResourceType.COMPLEX_TYPE);
            PageBase pageBase = FocusProjectionsPanel.this.getPageBase();
            ObjectBrowserPanel<ResourceType> resourceSelectionPanel = new ObjectBrowserPanel<>(pageBase.getMainPopupBodyId(), ResourceType.class, supportedTypes, true, pageBase) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void addPerformed(AjaxRequestTarget target, QName type, List<ResourceType> selected) {
                    FocusProjectionsPanel.this.addSelectedAccountPerformed(target, selected);
                    target.add(getPageBase().getFeedbackPanel());
                }
            };
            resourceSelectionPanel.setOutputMarkupId(true);
            pageBase.showMainPopup(resourceSelectionPanel, target);
        }

        @Override
        protected boolean isCreateNewObjectVisible() {
            PrismObjectDefinition<F> def = FocusProjectionsPanel.this.getObjectWrapperModel().getObject().getObject().getDefinition();
            PrismReferenceDefinition ref = def.findReferenceDefinition(UserType.F_LINK_REF);
            return (ref.canRead() && ref.canAdd());
        }

        @Override
        protected IModel<PrismContainerWrapper<ShadowType>> getContainerModel() {
            return null;
        }

        @Override
        protected TableId getTableId() {
            return TableId.FOCUS_PROJECTION_TABLE;
        }

        @Override
        protected List<IColumn<PrismContainerValueWrapper<ShadowType>, String>> createDefaultColumns() {
            return initBasicColumns();
        }

        @Override
        protected List<InlineMenuItem> createInlineMenu() {
            return createShadowMenu();
        }

        @Override
        public void editItemPerformed(AjaxRequestTarget target, IModel<PrismContainerValueWrapper<ShadowType>> rowModel, List<PrismContainerValueWrapper<ShadowType>> listItems) {
            loadShadowIfNeeded(rowModel, target);
            if (listItems != null) {
                listItems.forEach(value -> {
                    if (((ShadowWrapper) value.getParent()).isLoadWithNoFetch()) {
                        loadFullShadow((PrismObjectValueWrapper) value, target);
                    }
                });
            }
            super.editItemPerformed(target, rowModel, listItems);
        }

        @Override
        protected Search createSearch(Class<ShadowType> type) {
            Search search = super.createSearch(type);
            PropertySearchItem<Boolean> defaultDeadItem = search.findPropertySearchItem(ShadowType.F_DEAD);
            if (defaultDeadItem != null) {
                defaultDeadItem.setVisible(false);
            }
            addDeadSearchItem(search);
            return search;
        }

        @Override
        protected List<SearchItemDefinition> initSearchableItems(PrismContainerDefinition<ShadowType> containerDef) {
            List<SearchItemDefinition> defs = new ArrayList<>();
            SearchFactory.addSearchRefDef(containerDef, ShadowType.F_RESOURCE_REF, defs, AreaCategoryType.ADMINISTRATION, getPageBase());
            SearchFactory.addSearchPropertyDef(containerDef, ShadowType.F_NAME, defs);
            SearchFactory.addSearchPropertyDef(containerDef, ShadowType.F_INTENT, defs);
            SearchFactory.addSearchPropertyDef(containerDef, ShadowType.F_KIND, defs);
            return defs;
        }

        @Override
        protected MultivalueContainerDetailsPanel<ShadowType> getMultivalueContainerDetailsPanel(ListItem<PrismContainerValueWrapper<ShadowType>> item) {
            return FocusProjectionsPanel.this.getMultivalueContainerDetailsPanel(item);
        }
    };
    add(multivalueContainerListPanel);
    setOutputMarkupId(true);
}
Also used : VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) Label(org.apache.wicket.markup.html.basic.Label) ArrayList(java.util.ArrayList) AssignmentObjectRelation(com.evolveum.midpoint.model.api.AssignmentObjectRelation) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) ProjectionsListProvider(com.evolveum.midpoint.web.component.util.ProjectionsListProvider) List(java.util.List) ArrayList(java.util.ArrayList) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) PageStorage(com.evolveum.midpoint.web.session.PageStorage) IModel(org.apache.wicket.model.IModel) QName(javax.xml.namespace.QName) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) ObjectBrowserPanel(com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel) MultivalueContainerListPanelWithDetailsPanel(com.evolveum.midpoint.gui.impl.component.MultivalueContainerListPanelWithDetailsPanel) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 7 with ReadOnlyModel

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

the class MainMenuPanel method initLayout.

private void initLayout() {
    WebMarkupContainer item = new WebMarkupContainer(ID_ITEM);
    item.setOutputMarkupId(true);
    item.add(AttributeModifier.append("class", new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            MainMenuItem mainMenuItem = getModelObject();
            if (mainMenuItem.isMenuActive(getPageBase())) {
                return "active";
            }
            if (mainMenuItem.hasActiveSubmenu(getPageBase())) {
                return "active menu-open";
            }
            return null;
        }
    }));
    add(item);
    item.add(AttributeModifier.append("style", new ReadOnlyModel<>(() -> isMenuExpanded() ? "" : "display: none;")));
    WebMarkupContainer link = new AjaxLink<Void>(ID_LINK) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            mainMenuPerformed();
        }
    };
    item.add(link);
    WebMarkupContainer icon = new WebMarkupContainer(ID_ICON);
    icon.add(AttributeModifier.replace("class", new PropertyModel<>(getModel(), MainMenuItem.F_ICON_CLASS)));
    link.add(icon);
    Label label = new Label(ID_LABEL, new StringResourceModel("${nameModel}", getModel()).setDefaultValue(new PropertyModel<>(getModel(), "nameModel")));
    link.add(label);
    final PropertyModel<String> bubbleModel = new PropertyModel<>(getModel(), MainMenuItem.F_BUBBLE_LABEL);
    Label bubble = new Label(ID_BUBBLE, bubbleModel);
    bubble.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return bubbleModel.getObject() != null;
        }
    });
    link.add(bubble);
    WebMarkupContainer arrow = new WebMarkupContainer(ID_ARROW);
    arrow.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return getModelObject().containsSubMenu() && bubbleModel.getObject() == null;
        }
    });
    link.add(arrow);
    WebMarkupContainer submenu = new WebMarkupContainer(ID_SUBMENU);
    item.add(submenu);
    ListView<MenuItem> subItem = new ListView<MenuItem>(ID_SUB_ITEM, new PropertyModel<>(getModel(), MainMenuItem.F_ITEMS)) {

        @Override
        protected void populateItem(ListItem<MenuItem> listItem) {
            createSubmenu(listItem);
        }
    };
    submenu.add(subItem);
}
Also used : IModel(org.apache.wicket.model.IModel) PropertyModel(org.apache.wicket.model.PropertyModel) Label(org.apache.wicket.markup.html.basic.Label) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListView(org.apache.wicket.markup.html.list.ListView) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ListItem(org.apache.wicket.markup.html.list.ListItem) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 8 with ReadOnlyModel

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

the class UserMenuPanel method loadJpegPhotoModel.

private IModel<AbstractResource> loadJpegPhotoModel() {
    return new ReadOnlyModel<>(() -> {
        GuiProfiledPrincipal principal = AuthUtil.getPrincipalUser();
        if (principal == null) {
            return null;
        }
        CompiledGuiProfile profile = principal.getCompiledGuiProfile();
        byte[] jpegPhoto = profile.getJpegPhoto();
        if (jpegPhoto == null) {
            URL placeholder = UserMenuPanel.class.getClassLoader().getResource("static/img/placeholder.png");
            if (placeholder == null) {
                return null;
            }
            try {
                jpegPhoto = IOUtils.toByteArray(placeholder);
            } catch (IOException e) {
                LOGGER.error("Cannot load placeholder for photo.");
                return null;
            }
        }
        return new ByteArrayResource("image/jpeg", jpegPhoto);
    });
}
Also used : ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal) IOException(java.io.IOException) ByteArrayResource(org.apache.wicket.request.resource.ByteArrayResource) CompiledGuiProfile(com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile) URL(java.net.URL)

Example 9 with ReadOnlyModel

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

the class CaseWorkItemSummaryPanel method getDisplayNameModel.

@Override
protected IModel<String> getDisplayNameModel() {
    return new ReadOnlyModel<>(() -> {
        CaseWorkItemType caseWorkItemType = CaseWorkItemSummaryPanel.this.getModelObject();
        CaseType caseType = CaseTypeUtil.getCase(caseWorkItemType);
        return defaultIfNull(WfGuiUtil.getLocalizedProcessName(caseType != null ? caseType.getApprovalContext() : null, CaseWorkItemSummaryPanel.this), caseWorkItemType != null ? WebComponentUtil.getTranslatedPolyString(caseWorkItemType.getName()) : null);
    });
}
Also used : ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) CaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType) CaseWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType)

Example 10 with ReadOnlyModel

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

the class CorrelationContextPanel method createCorrelationContextModel.

private IModel<CorrelationContextDto> createCorrelationContextModel() {
    return new ReadOnlyModel<>(() -> {
        CaseType aCase = getObjectDetailsModels().getObjectType();
        CaseCorrelationContextType correlationContext = aCase.getCorrelationContext();
        if (correlationContext == null || CorrelationCaseUtil.getOwnerOptions(aCase) == null) {
            return null;
        }
        Task task = getPageBase().createSimpleTask(OP_LOAD);
        OperationResult result = task.getResult();
        try {
            return new CorrelationContextDto(aCase, getPageBase(), task, result);
        } catch (Throwable t) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load correlation context for {}", t, aCase);
            return null;
        } finally {
            result.computeStatusIfUnknown();
            getPageBase().showResult(result, false);
        }
    });
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

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