Search in sources :

Example 1 with MenuMultiButtonPanel

use of com.evolveum.midpoint.web.component.data.MenuMultiButtonPanel in project midpoint by Evolveum.

the class InlineMenuButtonColumn method getPanel.

private Component getPanel(String componentId, IModel<T> rowModel, int numberOfButtons, boolean isHeaderPanel) {
    List<InlineMenuItem> filteredMenuItems = new ArrayList<>();
    for (InlineMenuItem menuItem : menuItems) {
        if (isHeaderPanel && !menuItem.isHeaderMenuItem()) {
            continue;
        }
        if (rowModel != null && menuItem.getAction() != null && menuItem.getAction() instanceof ColumnMenuAction) {
            ((ColumnMenuAction) menuItem.getAction()).setRowModel(rowModel);
        }
        if (menuItem.getVisibilityChecker() != null && !menuItem.getVisibilityChecker().isVisible(rowModel, isHeaderPanel)) {
            continue;
        }
        filteredMenuItems.add(menuItem);
    }
    List<ButtonInlineMenuItem> buttonMenuItems = new ArrayList<>();
    menuItems.forEach(menuItem -> {
        if (menuItem instanceof ButtonInlineMenuItem) {
            if (isHeaderPanel && !menuItem.isHeaderMenuItem() || !menuItem.getVisible().getObject()) {
                return;
            }
            if (menuItem.getVisibilityChecker() != null && !menuItem.getVisibilityChecker().isVisible(rowModel, isHeaderPanel)) {
                return;
            }
            buttonMenuItems.add((ButtonInlineMenuItem) menuItem);
        }
    });
    if (filteredMenuItems.isEmpty()) {
        // this is hack, TODO: cleanup and refactor soif there aren't any inline (row) actions, nothing is displayed
        return new Label(componentId);
    }
    return new MenuMultiButtonPanel<T>(componentId, rowModel, buttonMenuItems.size(), Model.ofList(filteredMenuItems)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Component createButton(int index, String componentId, IModel<T> model) {
            CompositedIconBuilder builder = getIconCompositedBuilder(index, buttonMenuItems);
            AjaxCompositedIconButton btn = new AjaxCompositedIconButton(componentId, builder.build(), Model.of(getButtonTitle(index, buttonMenuItems))) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    setRowModelToButtonAction(rowModel, buttonMenuItems);
                    buttonMenuItemClickPerformed(index, buttonMenuItems, target);
                }
            };
            btn.add(AttributeAppender.append("class", " btn btn-default btn-xs"));
            btn.add(new EnableBehaviour(() -> isButtonMenuItemEnabled(model)));
            return btn;
        }

        @Override
        protected void onBeforeClickMenuItem(AjaxRequestTarget target, InlineMenuItemAction action, IModel<InlineMenuItem> item) {
            if (action instanceof ColumnMenuAction) {
                if (!isHeaderPanel) {
                    ((ColumnMenuAction) action).setRowModel(rowModel);
                } else {
                    ((ColumnMenuAction) action).setRowModel(null);
                }
            }
        }
    };
}
Also used : AjaxCompositedIconButton(com.evolveum.midpoint.gui.impl.component.AjaxCompositedIconButton) IModel(org.apache.wicket.model.IModel) MenuMultiButtonPanel(com.evolveum.midpoint.web.component.data.MenuMultiButtonPanel) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) 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) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour)

Example 2 with MenuMultiButtonPanel

use of com.evolveum.midpoint.web.component.data.MenuMultiButtonPanel in project midpoint by Evolveum.

the class OrgTreeFolderContent method initLayout.

private void initLayout() {
    SelectableFolderContent folder = new SelectableFolderContent(ID_FOLDER, tree, getModel(), selected) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onClick(Optional<AjaxRequestTarget> target) {
            super.onClick(target);
            OrgTreeFolderContent.this.setSelectedItem(selected.getObject(), orgTreeStorage);
            selectTreeItemPerformed(selected.getObject(), target.get());
            Component component = get("table");
            if (component != null) {
                target.get().add(component);
            }
        }
    };
    folder.setOutputMarkupId(true);
    addOrReplace(folder);
    if (selected.getObject().equals(getModelObject())) {
        getParent().add(AttributeAppender.append("class", "success"));
    } else {
        getParent().add(new AttributeAppender("class", "success", " ") {

            @Override
            protected Serializable newValue(String currentValue, String removeValue) {
                currentValue = getSeparator() + currentValue + getSeparator();
                removeValue = getSeparator() + removeValue + getSeparator();
                return currentValue.replace(removeValue, getSeparator());
            }
        });
    }
    MenuMultiButtonPanel<OrgType> menuButtons = new MenuMultiButtonPanel<>(ID_MENU, new PropertyModel<>(getModel(), TreeSelectableBean.F_VALUE), 2, createInlineMenuItemsModel());
    menuButtons.setOutputMarkupId(true);
    addOrReplace(menuButtons);
    CheckBoxPanel checkBoxPanel = new CheckBoxPanel(ID_CHECK, getCheckboxModel(getModel())) {

        @Override
        public void onUpdate(AjaxRequestTarget target) {
            getModelObject().setSelected(!getModelObject().isSelected());
            OrgTreeFolderContent.this.onUpdateCheckbox(target);
        }
    };
    checkBoxPanel.add(new VisibleBehaviour(() -> selectable));
    addOrReplace(checkBoxPanel);
}
Also used : SelectableFolderContent(com.evolveum.midpoint.web.page.admin.users.component.SelectableFolderContent) Serializable(java.io.Serializable) MenuMultiButtonPanel(com.evolveum.midpoint.web.component.data.MenuMultiButtonPanel) Optional(java.util.Optional) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) CheckBoxPanel(com.evolveum.midpoint.gui.api.component.form.CheckBoxPanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) Component(org.apache.wicket.Component) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Aggregations

MenuMultiButtonPanel (com.evolveum.midpoint.web.component.data.MenuMultiButtonPanel)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 CheckBoxPanel (com.evolveum.midpoint.gui.api.component.form.CheckBoxPanel)1 AjaxCompositedIconButton (com.evolveum.midpoint.gui.impl.component.AjaxCompositedIconButton)1 CompositedIconBuilder (com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder)1 ButtonInlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem)1 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)1 InlineMenuItemAction (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction)1 EnableBehaviour (com.evolveum.midpoint.web.component.util.EnableBehaviour)1 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)1 SelectableFolderContent (com.evolveum.midpoint.web.page.admin.users.component.SelectableFolderContent)1 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 Component (org.apache.wicket.Component)1 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)1 Label (org.apache.wicket.markup.html.basic.Label)1 IModel (org.apache.wicket.model.IModel)1