Search in sources :

Example 11 with ReadOnlyModel

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

the class SchrodingerComponentInitListener method handleLocalization.

private void handleLocalization(Component component) {
    if (component instanceof PrismPropertyPanel || component instanceof PrismReferencePanel) {
        ItemPanel ppp = (ItemPanel) component;
        ItemWrapper iw = (ItemWrapper) ppp.getModel().getObject();
        String key = iw.getDisplayName();
        QName qname = iw.getItemName();
        writeDataAttribute(component, ATTR_RESOURCE_KEY, key);
        writeDataAttribute(component, ATTR_QNAME, qnameToString(qname));
        return;
    }
    if (component instanceof PrismHeaderPanel) {
        PrismHeaderPanel php = (PrismHeaderPanel) component;
        String key = php.getLabel();
        writeDataAttribute(component, ATTR_RESOURCE_KEY, key);
        return;
    }
    IModel model = null;
    if (component.getDefaultModel() instanceof StringResourceModel) {
        model = component.getDefaultModel();
    } else if (component.getInnermostModel() instanceof StringResourceModel) {
        model = component.getInnermostModel();
    } else if (component.getDefaultModel() instanceof ReadOnlyModel) {
        try {
            if (component.getDefaultModelObject() instanceof String) {
                model = component.getDefaultModel();
            }
        } catch (Exception e) {
            LOGGER.error("Schrodinger localization handling failed", e);
        }
    }
    if (model == null) {
        return;
    }
    try {
        String key = model instanceof StringResourceModel ? (String) FieldUtils.readField(model, "resourceKey", true) : (String) model.getObject();
        if (key.startsWith("${")) {
            String expression = key.substring(2, key.length() - 1);
            key = new PropertyModel<String>(FieldUtils.readField(model, "model", true), expression).getObject();
        }
        if (key != null) {
            writeDataAttribute(component, ATTR_RESOURCE_KEY, key);
        }
    } catch (Exception ex) {
    // we don't care, should be all right, unless selenium tests starts failing
    }
}
Also used : ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) PrismPropertyPanel(com.evolveum.midpoint.gui.impl.prism.panel.PrismPropertyPanel) PrismHeaderPanel(com.evolveum.midpoint.web.component.prism.PrismHeaderPanel) IModel(org.apache.wicket.model.IModel) PrismReferencePanel(com.evolveum.midpoint.gui.impl.prism.panel.PrismReferencePanel) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) QName(javax.xml.namespace.QName) ItemPanel(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanel) PropertyModel(org.apache.wicket.model.PropertyModel) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 12 with ReadOnlyModel

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

the class WebComponentUtil method getIconUrlModel.

public static IModel<String> getIconUrlModel(IconType icon) {
    return new ReadOnlyModel<>(() -> {
        if (icon == null || StringUtils.isEmpty(icon.getImageUrl())) {
            return null;
        }
        String sUrl = icon.getImageUrl();
        if (URI.create(sUrl).isAbsolute()) {
            return sUrl;
        }
        List<String> segments = RequestCycle.get().getUrlRenderer().getBaseUrl().getSegments();
        if (segments == null || segments.size() < 2) {
            return sUrl;
        }
        String prefix = StringUtils.repeat("../", segments.size() - 1);
        if (!sUrl.startsWith("/")) {
            return prefix + sUrl;
        }
        return StringUtils.left(prefix, prefix.length() - 1) + sUrl;
    });
}
Also used : ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 13 with ReadOnlyModel

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

the class WebComponentUtil method createMappingDescription.

public static IModel<String> createMappingDescription(IModel<PrismContainerValueWrapper<MappingType>> model) {
    return new ReadOnlyModel<>(() -> {
        if (model == null || model.getObject() == null) {
            return null;
        }
        MappingType mappingType = model.getObject().getRealValue();
        if (mappingType == null) {
            return null;
        }
        List<VariableBindingDefinitionType> sources = mappingType.getSource();
        String sourceString = String.join(", ", sources.stream().map(s -> s != null && s.getPath() != null ? s.getPath().toString() : "").collect(Collectors.toList()));
        // String sourceString = "";
        // for (VariableBindingDefinitionType s : sources) {
        // if (s == null) {
        // continue;
        // }
        // sourceString += s.getPath().toString() + ", ";
        // }
        String strength = "";
        if (mappingType.getStrength() != null) {
            strength = mappingType.getStrength().toString();
        }
        String target = "";
        VariableBindingDefinitionType targetv = mappingType.getTarget();
        if (targetv != null) {
            target += targetv.getPath().toString();
        }
        if (target.isBlank()) {
            return sourceString + (strength.isBlank() ? "" : "(" + strength + ")");
        }
        return target + (strength.isBlank() ? "" : "(" + strength + ")");
    });
}
Also used : ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 14 with ReadOnlyModel

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

the class CompositedButtonPanel method initLayout.

private void initLayout() {
    WebMarkupContainer buttonContainer = new WebMarkupContainer(ID_COMPOSITED_BUTTON);
    add(buttonContainer);
    CompositedIconPanel compositedIconPanel = new CompositedIconPanel(ID_COMPOSITED_ICON, new PropertyModel<>(getModel(), CompositedIconButtonDto.F_COMPOSITED_ICON));
    buttonContainer.add(compositedIconPanel);
    Label label = new Label(ID_LABEL, new ReadOnlyModel<>(() -> {
        DisplayType displayType = getModelObject().getAdditionalButtonDisplayType();
        return WebComponentUtil.getTranslatedPolyString(displayType.getLabel());
    }));
    buttonContainer.add(label);
    buttonContainer.add(AttributeAppender.append("title", new ReadOnlyModel<>(() -> {
        DisplayType displayType = getModelObject().getAdditionalButtonDisplayType();
        return WebComponentUtil.getTranslatedPolyString(displayType.getTooltip());
    })));
    buttonContainer.add(new TooltipBehavior());
    buttonContainer.add(new AjaxEventBehavior("click") {

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            onButtonClicked(target, getModelObject());
        }

        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            attributes.setPreventDefault(true);
            super.updateAjaxAttributes(attributes);
        }
    });
// Label description = new Label(ID_DESCRIPTION, new ReadOnlyModel<>(() -> {
// DisplayType displayType = getModelObject().getAdditionalButtonDisplayType();
// return WebComponentUtil.getTranslatedPolyString(displayType.getTooltip());
// }));
// buttonContainer.add(description);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) CompositedIconPanel(com.evolveum.midpoint.gui.impl.component.data.column.CompositedIconPanel) TooltipBehavior(com.evolveum.midpoint.web.util.TooltipBehavior) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) DisplayType(com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType) AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 15 with ReadOnlyModel

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

the class FocusProjectionsTabPanel method initLayout.

private void initLayout() {
    IModel<Integer> deadShadows = new ReadOnlyModel<>(() -> 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) {

        private static final long serialVersionUID = 1L;

        @Override
        protected ISelectableDataProvider<ShadowType, PrismContainerValueWrapper<ShadowType>> createProvider() {
            return new ProjectionsListProvider(FocusProjectionsTabPanel.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 = new ArrayList<>(1);
            supportedTypes.add(ResourceType.COMPLEX_TYPE);
            PageBase pageBase = FocusProjectionsTabPanel.this.getPageBase();
            ObjectBrowserPanel<ResourceType> resourceSelectionPanel = new ObjectBrowserPanel<ResourceType>(pageBase.getMainPopupBodyId(), ResourceType.class, supportedTypes, true, pageBase) {

                private static final long serialVersionUID = 1L;

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

        @Override
        protected boolean isCreateNewObjectVisible() {
            PrismObjectDefinition<F> def = getObjectWrapper().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 UserProfileStorage.TableId.FOCUS_PROJECTION_TABLE;
        }

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

        @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()) {
                        ((PageAdminFocus) getPage()).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 FocusProjectionsTabPanel.this.getMultivalueContainerDetailsPanel(item);
        }
    };
    add(multivalueContainerListPanel);
    setOutputMarkupId(true);
}
Also used : PageAdminFocus(com.evolveum.midpoint.web.page.admin.PageAdminFocus) 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) 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)

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