Search in sources :

Example 26 with CompositedIconBuilder

use of com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder in project midpoint by Evolveum.

the class SearchPanel method initLayout.

private <S extends SearchItem, T extends Serializable> void initLayout() {
    moreDialogModel = new LoadableModel<MoreDialogDto>(false) {

        private static final long serialVersionUID = 1L;

        @Override
        protected MoreDialogDto load() {
            MoreDialogDto dto = new MoreDialogDto();
            dto.setProperties(createPropertiesList());
            return dto;
        }

        @Override
        public MoreDialogDto getObject() {
            if (SearchPanel.this.getModelObject() != null && SearchPanel.this.getModelObject().isTypeChanged()) {
                reset();
            }
            return super.getObject();
        }
    };
    MidpointForm<?> form = new MidpointForm<>(ID_FORM);
    add(form);
    AjaxButton debug = new AjaxButton(ID_DEBUG, createStringResource("SearchPanel.debug")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            debugPerformed();
        }
    };
    debug.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return SearchBoxModeType.ADVANCED.equals(getModelObject().getSearchType()) && queryPlaygroundAccessible;
        }
    });
    form.add(debug);
    PropertyModel<ObjectCollectionSearchItem> collectionModel = new PropertyModel<>(getModel(), Search.F_COLLECTION);
    SearchObjectCollectionPanel collectionPanel = new SearchObjectCollectionPanel(ID_COLLECTION_REF_PANEL, collectionModel);
    form.add(collectionPanel);
    collectionPanel.add(new VisibleBehaviour(() -> collectionModel != null && collectionModel.getObject() != null && getModelObject().isCollectionItemVisible()));
    PropertyModel<ContainerTypeSearchItem> typeModel = new PropertyModel<>(getModel(), Search.F_TYPE);
    SearchTypePanel typePanel = new SearchTypePanel(ID_TYPE_PANEL, typeModel) {

        @Override
        protected void searchPerformed(AjaxRequestTarget target) {
            resetMoreDialogModel();
            SearchPanel.this.searchPerformed(target);
        }
    };
    form.add(typePanel);
    typePanel.add(new VisibleBehaviour(() -> typeModel != null && typeModel.getObject() != null && typeModel.getObject().isVisible() && !SearchBoxModeType.OID.equals(getModelObject().getSearchType())));
    ListView<SearchItem> specialItems = createSpecialItemsPanel(ID_SPECIAL_ITEMS, new PropertyModel<>(getModel(), Search.F_SPECIAL_ITEMS));
    form.add(specialItems);
    ListView<SearchItem> compositedItems = createSpecialItemsPanel(ID_COMPOSITED_SPECIAL_ITEMS, new PropertyModel(getModel(), Search.F_COMPOSITED_SPECIAL_ITEMS + "." + AbstractRoleCompositedSearchItem.F_SEARCH_ITEMS));
    form.add(compositedItems);
    ListView<S> items = new ListView<S>(ID_ITEMS, new PropertyModel<>(getModel(), Search.F_ITEMS)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<S> item) {
            AbstractSearchItemPanel searchItem;
            if (item.getModelObject() instanceof FilterSearchItem) {
                searchItem = new SearchFilterPanel(ID_ITEM, (IModel<FilterSearchItem>) item.getModel()) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    protected boolean canRemoveSearchItem() {
                        return super.canRemoveSearchItem() && SearchPanel.this.getModelObject().isCanConfigure();
                    }

                    @Override
                    protected void searchPerformed(AjaxRequestTarget target) {
                        SearchPanel.this.searchPerformed(target);
                    }
                };
            } else {
                searchItem = new SearchPropertyPanel<T>(ID_ITEM, (IModel<PropertySearchItem<T>>) item.getModel()) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    protected boolean canRemoveSearchItem() {
                        return super.canRemoveSearchItem() && SearchPanel.this.getModelObject().isCanConfigure();
                    }

                    @Override
                    protected void searchPerformed(AjaxRequestTarget target) {
                        SearchPanel.this.searchPerformed(target);
                    }
                };
            }
            item.add(searchItem);
        }
    };
    items.add(createVisibleBehaviour(SearchBoxModeType.BASIC));
    form.add(items);
    SearchSpecialItemPanel oidItem = new SearchSpecialItemPanel<String>(ID_OID_ITEM, new PropertyModel<String>(getModel(), Search.F_OID)) {

        @Override
        protected WebMarkupContainer initSearchItemField(String id) {
            TextPanel<String> inputPanel = new TextPanel<String>(id, getModelValue());
            inputPanel.getBaseFormComponent().add(AttributeAppender.append("style", "width: 220px; max-width: 400px !important;"));
            return inputPanel;
        }

        @Override
        protected IModel<String> createLabelModel() {
            return getPageBase().createStringResource("SearchPanel.oid");
        }

        @Override
        protected IModel<String> createHelpModel() {
            return getPageBase().createStringResource("SearchPanel.oid.help");
        }
    };
    oidItem.add(createVisibleBehaviour(SearchBoxModeType.OID));
    form.add(oidItem);
    WebMarkupContainer moreGroup = new WebMarkupContainer(ID_MORE_GROUP);
    moreGroup.add(new VisibleBehaviour(() -> createVisibleBehaviour(SearchBoxModeType.BASIC).isVisible()));
    form.add(moreGroup);
    AjaxLink<Void> more = new AjaxLink<Void>(ID_MORE) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            resetMoreDialogModel();
            Component popover = SearchPanel.this.get(createComponentPath(ID_POPOVER));
            Component button = SearchPanel.this.get(createComponentPath(ID_FORM, ID_MORE_GROUP, ID_MORE));
            togglePopover(target, button, popover, 14);
        }
    };
    more.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            Search search = getModelObject();
            return !search.getAvailableDefinitions().isEmpty();
        }
    });
    more.setOutputMarkupId(true);
    moreGroup.add(more);
    WebMarkupContainer searchContainer = new WebMarkupContainer(ID_SEARCH_CONTAINER);
    searchContainer.setOutputMarkupId(true);
    form.add(searchContainer);
    final CompositedIconBuilder builder = new CompositedIconBuilder();
    builder.setBasicIcon(GuiStyleConstants.CLASS_ICON_SEARCH, IconCssStyle.IN_ROW_STYLE);
    IconType plusIcon = new IconType();
    plusIcon.setColor("white");
    builder.appendLayerIcon(getIconLabelByModeModel(), plusIcon, LayeredIconCssStyle.BOTTOM_RIGHT_STYLE);
    AjaxCompositedIconSubmitButton searchButtonBeforeDropdown = new AjaxCompositedIconSubmitButton(ID_SEARCH_BUTTON_BEFORE_DROPDOWN, builder.build(), getPageBase().createStringResource("SearchPanel.search")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(form);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            searchPerformed(target);
        }
    };
    IModel<String> buttonRightPaddingModel = () -> {
        boolean isLongButton = SearchBoxModeType.BASIC.equals(getModelObject().getSearchType()) || SearchBoxModeType.AXIOM_QUERY.equals(getModelObject().getSearchType());
        String style = "padding-right: " + (isLongButton ? "23" : "16") + "px;";
        if (getModelObject().getAllowedSearchType().size() == 1) {
            style = style + "border-top-right-radius: 3px; border-bottom-right-radius: 3px;";
        }
        return style;
    };
    searchButtonBeforeDropdown.add(AttributeAppender.append("style", buttonRightPaddingModel));
    searchButtonBeforeDropdown.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            if (SearchBoxModeType.ADVANCED.equals(getModelObject().getSearchType()) || SearchBoxModeType.AXIOM_QUERY.equals(getModelObject().getSearchType())) {
                Search search = getModelObject();
                PrismContext ctx = getPageBase().getPrismContext();
                return search.isAdvancedQueryValid(ctx);
            }
            return true;
        }

        @Override
        public boolean isVisible() {
            Search search = getModelObject();
            if (search.getAllowedSearchType().size() == 1 && SearchBoxModeType.BASIC.equals(search.getAllowedSearchType().get(0))) {
                return !search.getItems().isEmpty() || !search.getAvailableDefinitions().isEmpty();
            }
            return true;
        }
    });
    searchButtonBeforeDropdown.setOutputMarkupId(true);
    searchContainer.add(searchButtonBeforeDropdown);
    form.setDefaultButton(searchButtonBeforeDropdown);
    WebMarkupContainer dropdownButton = new WebMarkupContainer(ID_SEARCH_BUTTON_DROPDOWN);
    dropdownButton.add(new VisibleBehaviour(() -> getModelObject().getAllowedSearchType().size() != 1));
    searchContainer.add(dropdownButton);
    List<InlineMenuItem> searchItems = new ArrayList<>();
    InlineMenuItem searchItem = new InlineMenuItem(createStringResource("SearchPanel.basic")) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new InlineMenuItemAction() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    searchTypeUpdated(target, SearchBoxModeType.BASIC);
                }
            };
        }

        @Override
        public IModel<Boolean> getVisible() {
            return Model.of(getModelObject().isAllowedSearchMode(SearchBoxModeType.BASIC));
        }
    };
    searchItems.add(searchItem);
    searchItem = new InlineMenuItem(createStringResource("SearchPanel.advanced")) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new InlineMenuItemAction() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    searchTypeUpdated(target, SearchBoxModeType.ADVANCED);
                }
            };
        }

        @Override
        public IModel<Boolean> getVisible() {
            return Model.of(getModelObject().isAllowedSearchMode(SearchBoxModeType.ADVANCED));
        }
    };
    searchItems.add(searchItem);
    searchItem = new InlineMenuItem(createStringResource("SearchPanel.fullText")) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new InlineMenuItemAction() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    searchTypeUpdated(target, SearchBoxModeType.FULLTEXT);
                }
            };
        }

        @Override
        public IModel<Boolean> getVisible() {
            return Model.of(isFullTextSearchEnabled() && getModelObject().isAllowedSearchMode(SearchBoxModeType.FULLTEXT));
        }
    };
    searchItems.add(searchItem);
    searchItem = new InlineMenuItem(createStringResource("SearchPanel.oid")) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new InlineMenuItemAction() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    searchTypeUpdated(target, SearchBoxModeType.OID);
                }
            };
        }

        @Override
        public IModel<Boolean> getVisible() {
            return Model.of(getModelObject().isOidSearchEnabled() && getModelObject().isAllowedSearchMode(SearchBoxModeType.OID));
        }
    };
    searchItems.add(searchItem);
    searchItem = new InlineMenuItem(createStringResource("SearchPanel.axiomQuery")) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new InlineMenuItemAction() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    searchTypeUpdated(target, SearchBoxModeType.AXIOM_QUERY);
                }
            };
        }

        @Override
        public IModel<Boolean> getVisible() {
            return Model.of(WebModelServiceUtils.isEnableExperimentalFeature(getPageBase()) && getModelObject().isAllowedSearchMode(SearchBoxModeType.AXIOM_QUERY));
        }
    };
    searchItems.add(searchItem);
    ListView<InlineMenuItem> li = new ListView<InlineMenuItem>(ID_MENU_ITEM, Model.ofList(searchItems)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<InlineMenuItem> item) {
            WebMarkupContainer menuItemBody = new MenuLinkPanel(ID_MENU_ITEM_BODY, item.getModel());
            menuItemBody.setRenderBodyOnly(true);
            item.add(menuItemBody);
            menuItemBody.add(new VisibleEnableBehaviour() {

                @Override
                public boolean isVisible() {
                    return Boolean.TRUE.equals(item.getModelObject().getVisible().getObject());
                }
            });
        }
    };
    searchContainer.add(li);
    initPopover();
    WebMarkupContainer fullTextContainer = new WebMarkupContainer(ID_FULL_TEXT_CONTAINER);
    fullTextContainer.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return isFullTextSearchEnabled() && getModelObject().getSearchType().equals(SearchBoxModeType.FULLTEXT);
        }
    });
    fullTextContainer.setOutputMarkupId(true);
    form.add(fullTextContainer);
    TextField<String> fullTextInput = new TextField<>(ID_FULL_TEXT_FIELD, new PropertyModel<>(getModel(), Search.F_FULL_TEXT));
    fullTextInput.add(new AjaxFormComponentUpdatingBehavior("blur") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
        }
    });
    fullTextInput.add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
    fullTextInput.setOutputMarkupId(true);
    fullTextInput.add(new AttributeAppender("placeholder", createStringResource("SearchPanel.fullTextSearch")));
    fullTextInput.add(createVisibleBehaviour(SearchBoxModeType.FULLTEXT));
    fullTextContainer.add(fullTextInput);
    WebMarkupContainer advancedGroup = new WebMarkupContainer(ID_ADVANCED_GROUP);
    advancedGroup.add(createVisibleBehaviour(SearchBoxModeType.ADVANCED, SearchBoxModeType.AXIOM_QUERY));
    advancedGroup.add(AttributeAppender.append("class", createAdvancedGroupStyle()));
    advancedGroup.setOutputMarkupId(true);
    form.add(advancedGroup);
    Label advancedCheck = new Label(ID_ADVANCED_CHECK);
    advancedCheck.add(AttributeAppender.append("class", createAdvancedGroupLabelStyle()));
    advancedCheck.setOutputMarkupId(true);
    advancedGroup.add(advancedCheck);
    TextArea<?> advancedArea = new TextArea<>(ID_ADVANCED_AREA, new PropertyModel<>(getModel(), Search.F_ADVANCED_QUERY));
    advancedArea.add(new AjaxFormComponentUpdatingBehavior("keyup") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateAdvancedArea(advancedArea, target);
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setThrottlingSettings(new ThrottlingSettings(ID_ADVANCED_AREA, Duration.ofMillis(500), true));
        }
    });
    advancedArea.add(AttributeAppender.append("placeholder", getPageBase().createStringResource("SearchPanel.insertFilterXml")));
    advancedArea.add(createVisibleBehaviour(SearchBoxModeType.ADVANCED));
    advancedGroup.add(advancedArea);
    TextField<String> queryDslField = new TextField<>(ID_AXIOM_QUERY_FIELD, new PropertyModel<>(getModel(), Search.F_DSL_QUERY));
    queryDslField.add(new AjaxFormComponentUpdatingBehavior("keyup") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateQueryDSLArea(advancedCheck, advancedGroup, target);
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setThrottlingSettings(new ThrottlingSettings(ID_AXIOM_QUERY_FIELD, Duration.ofMillis(500), true));
            attributes.setChannel(new AjaxChannel("Drop", AjaxChannel.Type.DROP));
        }
    });
    queryDslField.add(AttributeAppender.append("placeholder", getPageBase().createStringResource("SearchPanel.insertAxiomQuery")));
    queryDslField.add(createVisibleBehaviour(SearchBoxModeType.AXIOM_QUERY));
    advancedGroup.add(queryDslField);
    WebMarkupContainer advancedErrorGroup = new WebMarkupContainer(ID_ADVANCED_ERROR_GROUP);
    advancedErrorGroup.setOutputMarkupId(true);
    advancedGroup.add(advancedErrorGroup);
    Label advancedError = new Label(ID_ADVANCED_ERROR, new PropertyModel<String>(getModel(), Search.F_ADVANCED_ERROR));
    advancedError.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            Search search = getModelObject();
            if (!search.isShowAdvanced()) {
                return false;
            }
            return StringUtils.isNotEmpty(search.getAdvancedError());
        }
    });
    advancedErrorGroup.add(advancedError);
}
Also used : VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) TextArea(org.apache.wicket.markup.html.form.TextArea) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel) AbstractRoleCompositedSearchItem(com.evolveum.midpoint.web.page.admin.roles.AbstractRoleCompositedSearchItem) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) ListView(org.apache.wicket.markup.html.list.ListView) CompositedIconBuilder(com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder) TextField(org.apache.wicket.markup.html.form.TextField) AjaxChannel(org.apache.wicket.ajax.AjaxChannel) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) IconType(com.evolveum.midpoint.xml.ns._public.common.common_3.IconType) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ThrottlingSettings(org.apache.wicket.ajax.attributes.ThrottlingSettings) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) Component(org.apache.wicket.Component) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) IModel(org.apache.wicket.model.IModel) PropertyModel(org.apache.wicket.model.PropertyModel) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) MenuLinkPanel(com.evolveum.midpoint.web.component.menu.cog.MenuLinkPanel) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) ListItem(org.apache.wicket.markup.html.list.ListItem) AjaxCompositedIconSubmitButton(com.evolveum.midpoint.web.component.AjaxCompositedIconSubmitButton)

Example 27 with CompositedIconBuilder

use of com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder in project midpoint by Evolveum.

the class FocusListInlineMenuHelper method createRowActions.

public List<InlineMenuItem> createRowActions(Class<F> objectType) {
    List<InlineMenuItem> menu = new ArrayList<>();
    ButtonInlineMenuItem enableItem = new ButtonInlineMenuItem(parentPage.createStringResource("FocusListInlineMenuHelper.menu.enable")) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new ColumnMenuAction<SelectableBeanImpl<F>>() {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    if (getRowModel() == null) {
                        updateActivationPerformed(target, true, null);
                    } else {
                        SelectableBeanImpl<F> rowDto = getRowModel().getObject();
                        updateActivationPerformed(target, true, rowDto.getValue());
                    }
                }
            };
        }

        @Override
        public CompositedIconBuilder getIconCompositedBuilder() {
            return getDefaultCompositedIconBuilder(getEnableActionDefaultIcon(objectType));
        }

        @Override
        public IModel<String> getConfirmationMessageModel() {
            String actionName = parentPage.createStringResource("pageUsers.message.enableAction").getString();
            return FocusListInlineMenuHelper.this.getConfirmationMessageModel((ColumnMenuAction) getAction(), actionName);
        }
    };
    enableItem.setVisibilityChecker(FocusListInlineMenuHelper::isObjectDisabled);
    menu.add(enableItem);
    ButtonInlineMenuItem disableItem = new ButtonInlineMenuItem(parentPage.createStringResource("FocusListInlineMenuHelper.menu.disable")) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new ColumnMenuAction<SelectableBeanImpl<F>>() {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    if (getRowModel() == null) {
                        updateActivationPerformed(target, false, null);
                    } else {
                        SelectableBeanImpl<F> rowDto = getRowModel().getObject();
                        updateActivationPerformed(target, false, rowDto.getValue());
                    }
                }
            };
        }

        @Override
        public IModel<String> getConfirmationMessageModel() {
            String actionName = parentPage.createStringResource("pageUsers.message.disableAction").getString();
            return FocusListInlineMenuHelper.this.getConfirmationMessageModel((ColumnMenuAction) getAction(), actionName);
        }

        @Override
        public CompositedIconBuilder getIconCompositedBuilder() {
            CompositedIconBuilder builder = getDefaultCompositedIconBuilder(getEnableActionDefaultIcon(objectType));
            builder.appendLayerIcon(WebComponentUtil.createIconType(GuiStyleConstants.CLASS_BAN), IconCssStyle.BOTTOM_RIGHT_STYLE);
            return builder;
        }
    };
    disableItem.setVisibilityChecker(FocusListInlineMenuHelper::isObjectEnabled);
    menu.add(disableItem);
    menu.add(new ButtonInlineMenuItem(parentPage.createStringResource("FocusListInlineMenuHelper.menu.reconcile")) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new ColumnMenuAction<SelectableBeanImpl<F>>() {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    if (getRowModel() == null) {
                        reconcilePerformed(target, null);
                    } else {
                        SelectableBeanImpl<F> rowDto = getRowModel().getObject();
                        reconcilePerformed(target, rowDto.getValue());
                    }
                }
            };
        }

        @Override
        public CompositedIconBuilder getIconCompositedBuilder() {
            return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_RECONCILE_MENU_ITEM);
        }

        @Override
        public IModel<String> getConfirmationMessageModel() {
            String actionName = parentPage.createStringResource("pageUsers.message.reconcileAction").getString();
            return FocusListInlineMenuHelper.this.getConfirmationMessageModel((ColumnMenuAction) getAction(), actionName);
        }
    });
    menu.add(new InlineMenuItem(parentPage.createStringResource("FocusListInlineMenuHelper.menu.delete")) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new ColumnMenuAction<SelectableBeanImpl<F>>() {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    if (getRowModel() == null) {
                        deleteConfirmedPerformed(target, null);
                    } else {
                        SelectableBeanImpl<F> rowDto = getRowModel().getObject();
                        deleteConfirmedPerformed(target, rowDto.getValue());
                    }
                }
            };
        }

        @Override
        public IModel<String> getConfirmationMessageModel() {
            String actionName = parentPage.createStringResource("pageUsers.message.deleteAction").getString();
            return FocusListInlineMenuHelper.this.getConfirmationMessageModel((ColumnMenuAction) getAction(), actionName);
        }
    });
    return menu;
}
Also used : IModel(org.apache.wicket.model.IModel) ArrayList(java.util.ArrayList) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) CompositedIconBuilder(com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) ColumnMenuAction(com.evolveum.midpoint.web.component.data.column.ColumnMenuAction) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem)

Example 28 with CompositedIconBuilder

use of com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder in project midpoint by Evolveum.

the class WebComponentUtil method createAccountIcon.

public static CompositedIcon createAccountIcon(ShadowType shadow, PageBase pageBase, boolean isColumn) {
    List<TriggerType> triggerType = shadow.getTrigger();
    String iconCssClass = WebComponentUtil.createShadowIcon(shadow.asPrismObject());
    CompositedIconBuilder builder = new CompositedIconBuilder();
    String title = createTriggerTooltip(triggerType, pageBase);
    if (StringUtils.isNotBlank(title)) {
        IconType icon = new IconType();
        icon.setCssClass("fa fa-clock-o " + GuiStyleConstants.BLUE_COLOR);
        if (isColumn) {
            builder.appendLayerIcon(icon, IconCssStyle.TOP_RIGHT_FOR_COLUMN_STYLE);
        } else {
            builder.appendLayerIcon(icon, IconCssStyle.TOP_RIGHT_STYLE);
        }
    }
    builder.setBasicIcon(iconCssClass, IconCssStyle.BOTTOM_RIGHT_FOR_COLUMN_STYLE);
    if (shadow.getResourceRef().getObject() == null && !isColumn) {
        Task task = pageBase.createSimpleTask("Load Resource");
        try {
            ResourceType resource = pageBase.getModelObjectResolver().resolve(shadow.getResourceRef(), ResourceType.class, null, "Load Resource", task, task.getResult());
            shadow.getResourceRef().asReferenceValue().setObject(resource.asPrismObject());
        } catch (CommonException e) {
        // ignore exception
        }
    }
    if (shadow.getResourceRef() != null && shadow.getResourceRef().getObject() != null && ResourceTypeUtil.isInMaintenance(shadow.getResourceRef().getObject())) {
        IconType icon = new IconType();
        icon.setCssClass("fa fa-wrench " + GuiStyleConstants.CLASS_ICON_STYLE_MAINTENANCE);
        if (isColumn) {
            builder.appendLayerIcon(icon, IconCssStyle.BOTTOM_LEFT_FOR_COLUMN_STYLE);
        } else {
            builder.appendLayerIcon(icon, IconCssStyle.BOTTOM_LEFT_STYLE);
        }
        if (StringUtils.isNotBlank(title)) {
            title = title + "\n " + pageBase.createStringResource("ChangePasswordPanel.legendMessage.maintenance").getString();
        } else {
            title = pageBase.createStringResource("ChangePasswordPanel.legendMessage.maintenance").getString();
        }
    }
    if (BooleanUtils.isTrue(shadow.isDead())) {
        IconType icon = new IconType();
        icon.setCssClass("fa fa-times-circle " + GuiStyleConstants.RED_COLOR);
        if (isColumn) {
            builder.appendLayerIcon(icon, IconCssStyle.BOTTOM_RIGHT_FOR_COLUMN_STYLE);
        } else {
            builder.appendLayerIcon(icon, IconCssStyle.BOTTOM_RIGHT_STYLE);
        }
        builder.setTitle(pageBase.createStringResource("FocusProjectionsTabPanel.deadShadow").getString() + (StringUtils.isNotBlank(title) ? ("\n" + title) : ""));
        return builder.build();
    }
    if (shadow.getResourceRef() != null && shadow.getResourceRef().getObject() != null && !ResourceTypeUtil.isActivationCapabilityEnabled((ResourceType) shadow.getResourceRef().getObject().asObjectable(), null)) {
        IconType icon = new IconType();
        icon.setCssClass("fa fa-ban " + GuiStyleConstants.RED_COLOR);
        if (isColumn) {
            builder.appendLayerIcon(icon, IconCssStyle.BOTTOM_RIGHT_FOR_COLUMN_STYLE);
        } else {
            builder.appendLayerIcon(icon, IconCssStyle.BOTTOM_RIGHT_STYLE);
        }
        builder.setTitle(pageBase.createStringResource("accountIcon.activation.notSupported").getString() + (StringUtils.isNotBlank(title) ? ("\n" + title) : ""));
        return builder.build();
    }
    ActivationType activation = shadow.getActivation();
    if (activation == null) {
        builder.setTitle(pageBase.createStringResource("accountIcon.activation.unknown").getString() + (StringUtils.isNotBlank(title) ? ("\n" + title) : ""));
        appendUndefinedIcon(builder);
        return builder.build();
    }
    LockoutStatusType lockoutStatus = activation.getLockoutStatus();
    XMLGregorianCalendar lockoutExpirationTimestamp = activation.getLockoutExpirationTimestamp();
    if ((lockoutStatus != null && LockoutStatusType.LOCKED == lockoutStatus) || (lockoutExpirationTimestamp != null && pageBase.getClock().isPast((lockoutExpirationTimestamp)))) {
        IconType icon = new IconType();
        icon.setCssClass("fa fa-lock " + GuiStyleConstants.RED_COLOR);
        if (isColumn) {
            builder.appendLayerIcon(icon, IconCssStyle.BOTTOM_RIGHT_FOR_COLUMN_STYLE);
        } else {
            builder.appendLayerIcon(icon, IconCssStyle.BOTTOM_RIGHT_STYLE);
        }
        builder.setTitle(pageBase.createStringResource("LockoutStatusType.LOCKED").getString() + (StringUtils.isNotBlank(title) ? ("\n" + title) : ""));
        return builder.build();
    }
    ActivationStatusType value = activation.getAdministrativeStatus();
    if (value == null) {
        builder.setTitle(pageBase.createStringResource("accountIcon.activation.unknown").getString() + (StringUtils.isNotBlank(title) ? ("\n" + title) : ""));
        appendUndefinedIcon(builder);
        return builder.build();
    }
    builder.setTitle(pageBase.createStringResource("ActivationStatusType." + value).getString() + (StringUtils.isNotBlank(title) ? ("\n" + title) : ""));
    switch(value) {
        case DISABLED:
            if (isColumn) {
                appendIcon(builder, "fe fe-no-line " + GuiStyleConstants.RED_COLOR, IconCssStyle.CENTER_FOR_COLUMN_STYLE);
            } else {
                appendIcon(builder, "fe fe-no-line " + GuiStyleConstants.RED_COLOR, IconCssStyle.CENTER_STYLE);
            }
            return builder.build();
        case ARCHIVED:
            if (isColumn) {
                appendIcon(builder, "fa fa-archive " + GuiStyleConstants.RED_COLOR, IconCssStyle.BOTTOM_RIGHT_FOR_COLUMN_STYLE);
            } else {
                appendIcon(builder, "fa fa-archive " + GuiStyleConstants.RED_COLOR, IconCssStyle.BOTTOM_RIGHT_STYLE);
            }
            return builder.build();
    }
    return builder.build();
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Task(com.evolveum.midpoint.task.api.Task) PageTask(com.evolveum.midpoint.web.page.admin.server.PageTask) CompositedIconBuilder(com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 29 with CompositedIconBuilder

use of com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder in project midpoint by Evolveum.

the class WebComponentUtil method createCompositeIconForObject.

// TODO unify createAccountIcon with createCompositeIconForObject
public static <O extends ObjectType> CompositedIcon createCompositeIconForObject(O obj, OperationResult result, PageBase pageBase) {
    if (obj instanceof ShadowType) {
        return createAccountIcon((ShadowType) obj, pageBase, true);
    }
    DisplayType basicIconDisplayType = GuiDisplayTypeUtil.getDisplayTypeForObject(obj, result, pageBase);
    CompositedIconBuilder iconBuilder = new CompositedIconBuilder();
    if (basicIconDisplayType == null) {
        return new CompositedIconBuilder().build();
    }
    // TODO trigger
    IconType lifecycleStateIcon = getIconForLifecycleState(obj);
    IconType activationStatusIcon = getIconForActivationStatus(obj);
    String iconColor = getIconColor(basicIconDisplayType);
    CompositedIconBuilder builder = iconBuilder.setBasicIcon(getIconCssClass(basicIconDisplayType), IconCssStyle.IN_ROW_STYLE).appendColorHtmlValue(StringUtils.isNotEmpty(iconColor) ? iconColor : "");
    StringBuilder title = new StringBuilder(getOrigStringFromPolyOrEmpty(basicIconDisplayType.getTooltip()));
    if (lifecycleStateIcon != null) {
        // TODO: do we really want to expect not null icon for layerIcon?
        builder.appendLayerIcon(lifecycleStateIcon, IconCssStyle.BOTTOM_LEFT_FOR_COLUMN_STYLE);
        appendLifecycleState(title, lifecycleStateIcon, obj, pageBase);
    }
    if (activationStatusIcon != null) {
        builder.appendLayerIcon(activationStatusIcon, IconCssStyle.BOTTOM_RIGHT_FOR_COLUMN_STYLE);
        appendActivationStatus(title, activationStatusIcon, obj, pageBase);
    }
    addMultiNodeTaskInformation(obj, builder);
    if (StringUtils.isNotEmpty(title.toString())) {
        builder.setTitle(title.toString());
    }
    return builder.build();
}
Also used : CompositedIconBuilder(com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 30 with CompositedIconBuilder

use of com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder in project midpoint by Evolveum.

the class WebComponentUtil method getAssignmentRelationIconBuilder.

@Contract("_,_,_,null -> null")
public static CompositedIconBuilder getAssignmentRelationIconBuilder(PageBase pageBase, AssignmentObjectRelation relationSpec, IconType relationIcon, IconType actionButtonIcon) {
    CompositedIconBuilder builder = new CompositedIconBuilder();
    if (relationSpec == null) {
        if (actionButtonIcon == null) {
            return null;
        }
        builder.setBasicIcon(actionButtonIcon, IconCssStyle.IN_ROW_STYLE).appendColorHtmlValue(actionButtonIcon.getColor());
        return builder;
    }
    DisplayType objectTypeDisplay = null;
    if (CollectionUtils.isNotEmpty(relationSpec.getArchetypeRefs())) {
        try {
            String operation = pageBase.getClass().getSimpleName() + "." + "loadArchetypeObject";
            ArchetypeType archetype = pageBase.getModelObjectResolver().resolve(relationSpec.getArchetypeRefs().get(0), ArchetypeType.class, null, null, pageBase.createSimpleTask(operation), new OperationResult(operation));
            if (archetype != null && archetype.getArchetypePolicy() != null) {
                objectTypeDisplay = archetype.getArchetypePolicy().getDisplay();
            }
        } catch (Exception ex) {
            LOGGER.error("Couldn't load archetype object, " + ex.getLocalizedMessage());
        }
    }
    if (objectTypeDisplay == null) {
        objectTypeDisplay = new DisplayType();
    }
    if (objectTypeDisplay.getIcon() == null) {
        objectTypeDisplay.setIcon(new IconType());
    }
    QName objectType = CollectionUtils.isNotEmpty(relationSpec.getObjectTypes()) ? relationSpec.getObjectTypes().get(0) : null;
    if (StringUtils.isEmpty(WebComponentUtil.getIconCssClass(objectTypeDisplay)) && objectType != null) {
        objectTypeDisplay.getIcon().setCssClass(WebComponentUtil.createDefaultBlackIcon(objectType));
    }
    if (StringUtils.isNotEmpty(WebComponentUtil.getIconCssClass(objectTypeDisplay))) {
        builder.setBasicIcon(objectTypeDisplay.getIcon(), IconCssStyle.IN_ROW_STYLE).appendColorHtmlValue(WebComponentUtil.getIconColor(objectTypeDisplay)).appendLayerIcon(actionButtonIcon, IconCssStyle.BOTTOM_RIGHT_STYLE).appendLayerIcon(relationIcon, IconCssStyle.TOP_RIGHT_STYLE);
    } else {
        builder.setBasicIcon(actionButtonIcon, IconCssStyle.IN_ROW_STYLE).appendColorHtmlValue(actionButtonIcon.getColor());
    }
    return builder;
}
Also used : QName(javax.xml.namespace.QName) CompositedIconBuilder(com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) InvocationTargetException(java.lang.reflect.InvocationTargetException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) Contract(org.jetbrains.annotations.Contract)

Aggregations

CompositedIconBuilder (com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder)57 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)32 ButtonInlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem)26 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)26 InlineMenuItemAction (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction)26 ArrayList (java.util.ArrayList)26 IModel (org.apache.wicket.model.IModel)17 ColumnMenuAction (com.evolveum.midpoint.web.component.data.column.ColumnMenuAction)11 CompositedIconButtonDto (com.evolveum.midpoint.web.component.CompositedIconButtonDto)9 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)9 AssignmentObjectRelation (com.evolveum.midpoint.model.api.AssignmentObjectRelation)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)7 SelectableBeanImpl (com.evolveum.midpoint.web.component.util.SelectableBeanImpl)7 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)6 CompositedIcon (com.evolveum.midpoint.gui.impl.component.icon.CompositedIcon)6 PrismContainerValueWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper)5 CompositedIconColumn (com.evolveum.midpoint.gui.impl.component.data.column.CompositedIconColumn)4 InlineMenuButtonColumn (com.evolveum.midpoint.web.component.data.column.InlineMenuButtonColumn)4 UserProfileStorage (com.evolveum.midpoint.web.session.UserProfileStorage)4