Search in sources :

Example 1 with I_CmsContextMenuItem

use of org.opencms.ui.contextmenu.I_CmsContextMenuItem in project opencms-core by alkacon.

the class CmsWorkplaceAppManager method getDefaultAction.

/**
 * Returns the default action for the given context if available.<p>
 *
 * @param context the dialog context
 * @param menuItemProvider the menu item provider
 *
 * @return the default action
 */
public I_CmsDefaultAction getDefaultAction(I_CmsDialogContext context, I_CmsContextMenuItemProvider menuItemProvider) {
    I_CmsDefaultAction result = null;
    int resultRank = -1;
    if (context.getResources().size() == 1) {
        for (I_CmsContextMenuItem menuItem : menuItemProvider.getMenuItems()) {
            if ((menuItem instanceof CmsContextMenuActionItem) && (((CmsContextMenuActionItem) menuItem).getWorkplaceAction() instanceof I_CmsDefaultAction)) {
                I_CmsDefaultAction action = (I_CmsDefaultAction) ((CmsContextMenuActionItem) menuItem).getWorkplaceAction();
                if (action.getVisibility(context).isActive()) {
                    if (result == null) {
                        result = action;
                        resultRank = action.getDefaultActionRank(context);
                    } else {
                        int rank = action.getDefaultActionRank(context);
                        if (rank > resultRank) {
                            result = action;
                            resultRank = rank;
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : I_CmsContextMenuItem(org.opencms.ui.contextmenu.I_CmsContextMenuItem) CmsContextMenuActionItem(org.opencms.ui.actions.CmsContextMenuActionItem) I_CmsDefaultAction(org.opencms.ui.actions.I_CmsDefaultAction)

Example 2 with I_CmsContextMenuItem

use of org.opencms.ui.contextmenu.I_CmsContextMenuItem in project opencms-core by alkacon.

the class CmsToolBar method createMenuEntry.

/**
 * Creates the context menu entry and it's children.<p>
 *
 * @param parent the entry parent
 * @param node the item tree node
 * @param treeBuilder the tree builder
 */
private void createMenuEntry(MenuItem parent, final CmsTreeNode<I_CmsContextMenuItem> node, CmsContextMenuTreeBuilder treeBuilder) {
    Command entryCommand = null;
    if (node.getChildren().size() == 0) {
        entryCommand = new Command() {

            private static final long serialVersionUID = 1L;

            public void menuSelected(MenuItem selectedItem) {
                node.getData().executeAction(getDialogContext());
            }
        };
    }
    MenuItem entry = parent.addItem((node.getData().getTitle(A_CmsUI.get().getLocale())), entryCommand);
    for (CmsTreeNode<I_CmsContextMenuItem> child : node.getChildren()) {
        createMenuEntry(entry, child, treeBuilder);
    }
    if (treeBuilder.getVisibility(node.getData()).isInActive()) {
        entry.setEnabled(false);
    }
}
Also used : I_CmsContextMenuItem(org.opencms.ui.contextmenu.I_CmsContextMenuItem) Command(com.vaadin.ui.MenuBar.Command) MenuItem(com.vaadin.ui.MenuBar.MenuItem) I_CmsContextMenuItem(org.opencms.ui.contextmenu.I_CmsContextMenuItem)

Example 3 with I_CmsContextMenuItem

use of org.opencms.ui.contextmenu.I_CmsContextMenuItem in project opencms-core by alkacon.

the class CmsListManager method initUI.

/**
 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#initUI(org.opencms.ui.apps.I_CmsAppUIContext)
 */
@Override
public void initUI(I_CmsAppUIContext uiContext) {
    super.initUI(uiContext);
    m_publishButton = CmsToolBar.createButton(FontOpenCms.PUBLISH, CmsVaadinUtils.getMessageText(Messages.GUI_PUBLISH_BUTTON_TITLE_0));
    if (CmsAppWorkplaceUi.isOnlineProject()) {
        // disable publishing in online project
        m_publishButton.setEnabled(false);
        m_publishButton.setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_TOOLBAR_NOT_AVAILABLE_ONLINE_0));
    }
    m_publishButton.addClickListener(new ClickListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            publish();
        }
    });
    uiContext.addToolbarButton(m_publishButton);
    m_editCurrentButton = CmsToolBar.createButton(FontOpenCms.PEN, CmsVaadinUtils.getMessageText(Messages.GUI_LISTMANAGER_EDIT_CONFIG_0));
    m_editCurrentButton.addClickListener(new ClickListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            editListConfiguration(m_currentResource);
        }
    });
    uiContext.addToolbarButton(m_editCurrentButton);
    m_infoButton = CmsToolBar.createButton(FontOpenCms.INFO, CmsVaadinUtils.getMessageText(org.opencms.ui.Messages.GUI_RESOURCE_INFO_0));
    m_infoButton.addClickListener(new ClickListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            DialogContext context = new DialogContext(CmsProjectManagerConfiguration.APP_ID, ContextType.fileTable, m_resultTable, Collections.singletonList(m_currentResource));
            CmsResourceInfoAction action = new CmsResourceInfoAction();
            action.openDialog(context, CmsResourceStatusTabId.tabRelationsTo.name());
        }
    });
    uiContext.addToolbarButton(m_infoButton);
    m_toggleSeriesButton = CmsToolBar.createButton(FontOpenCms.LIST, CmsVaadinUtils.getMessageText(Messages.GUI_LISTMANAGER_TOGGLE_SERIES_BUTTON_0));
    m_toggleSeriesButton.addClickListener(new ClickListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            toggleDateSeries();
        }
    });
    uiContext.addToolbarButton(m_toggleSeriesButton);
    m_createNewButton = CmsToolBar.createButton(FontOpenCms.WAND, CmsVaadinUtils.getMessageText(Messages.GUI_LISTMANAGER_CREATE_NEW_0));
    m_createNewButton.addClickListener(new ClickListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            createNew();
        }
    });
    uiContext.addToolbarButton(m_createNewButton);
    m_rootLayout.setMainHeightFull(true);
    m_resultLayout = new HorizontalSplitPanel();
    m_resultLayout.setSizeFull();
    m_resultFacets = new CmsResultFacets(this);
    m_resultFacets.setWidth("100%");
    m_resultLayout.setFirstComponent(m_resultFacets);
    LinkedHashMap<CmsResourceTableProperty, Integer> tableColumns = new LinkedHashMap<CmsResourceTableProperty, Integer>();
    // insert columns a specific positions
    for (Map.Entry<CmsResourceTableProperty, Integer> columnsEntry : CmsFileTable.DEFAULT_TABLE_PROPERTIES.entrySet()) {
        if (columnsEntry.getKey().equals(CmsResourceTableProperty.PROPERTY_RESOURCE_NAME)) {
            tableColumns.put(INFO_PROPERTY_LABEL, Integer.valueOf(0));
        } else if (columnsEntry.getKey().equals(CmsResourceTableProperty.PROPERTY_RESOURCE_TYPE)) {
            tableColumns.put(INSTANCEDATE_PROPERTY, Integer.valueOf(0));
        }
        tableColumns.put(columnsEntry.getKey(), columnsEntry.getValue());
    }
    tableColumns.put(BLACKLISTED_PROPERTY, Integer.valueOf(CmsResourceTable.INVISIBLE));
    tableColumns.put(INFO_PROPERTY, Integer.valueOf(CmsResourceTable.INVISIBLE));
    m_resultTable = new CmsResultTable(null, tableColumns);
    m_resultTable.applyWorkplaceAppSettings();
    CmsResourceContextMenuBuilder menuBuilderOverView = new CmsResourceContextMenuBuilder();
    menuBuilderOverView.addMenuItemProvider(OpenCms.getWorkplaceAppManager().getMenuItemProvider());
    menuBuilderOverView.addMenuItemProvider(new I_CmsContextMenuItemProvider() {

        @Override
        public List<I_CmsContextMenuItem> getMenuItems() {
            return Arrays.<I_CmsContextMenuItem>asList(new CmsContextMenuActionItem(new CmsEditDialogAction() {

                @Override
                public void executeAction(I_CmsDialogContext context) {
                    editListConfiguration(context.getResources().get(0));
                }
            }, null, 10, 1000));
        }
    });
    CmsResourceContextMenuBuilder menuBuilder = new CmsResourceContextMenuBuilder();
    menuBuilder.addMenuItemProvider(OpenCms.getWorkplaceAppManager().getMenuItemProvider());
    menuBuilder.addMenuItemProvider(new I_CmsContextMenuItemProvider() {

        @Override
        public List<I_CmsContextMenuItem> getMenuItems() {
            return Arrays.<I_CmsContextMenuItem>asList(new CmsContextMenuActionItem(new A_CmsWorkplaceAction() {

                @Override
                public void executeAction(I_CmsDialogContext context) {
                    CmsUUID structureId = context.getResources().get(0).getStructureId();
                    m_currentConfig.getBlacklist().add(structureId);
                    saveBlacklist(m_currentConfig);
                    context.finish(Collections.singletonList(structureId));
                }

                @Override
                public String getId() {
                    return "hideresource";
                }

                @Override
                public String getTitleKey() {
                    return Messages.GUI_LISTMANAGER_BLACKLIST_MENU_ENTRY_0;
                }

                @Override
                public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, List<CmsResource> resources) {
                    if ((m_currentConfig != null) && (resources != null) && (resources.size() == 1) && !m_currentConfig.getBlacklist().contains(resources.get(0).getStructureId())) {
                        return CmsEditDialogAction.VISIBILITY.getVisibility(cms, Collections.singletonList(m_currentResource));
                    } else {
                        return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
                    }
                }
            }, null, 10, 0), new CmsContextMenuActionItem(new A_CmsWorkplaceAction() {

                @Override
                public void executeAction(I_CmsDialogContext context) {
                    CmsUUID structureId = context.getResources().get(0).getStructureId();
                    m_currentConfig.getBlacklist().remove(structureId);
                    saveBlacklist(m_currentConfig);
                    context.finish(Collections.singletonList(structureId));
                }

                @Override
                public String getId() {
                    return "showresource";
                }

                @Override
                public String getTitleKey() {
                    return Messages.GUI_LISTMANAGER_REMOVE_FROM_BLACKLIST_MENU_ENTRY_0;
                }

                @Override
                public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, List<CmsResource> resources) {
                    if ((m_currentConfig != null) && (resources != null) && (resources.size() == 1) && m_currentConfig.getBlacklist().contains(resources.get(0).getStructureId())) {
                        return CmsEditDialogAction.VISIBILITY.getVisibility(cms, Collections.singletonList(m_currentResource));
                    } else {
                        return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
                    }
                }
            }, null, 10, 0), new CmsContextMenuActionItem(new EditAction(), null, 10, 1000), new CmsContextMenuActionItem(new DeleteAction(), null, 10, 1000));
        }
    });
    m_resultTable.setMenuBuilder(menuBuilder);
    m_resultTable.addAdditionalStyleGenerator(new CellStyleGenerator() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getStyle(Table source, Object itemId, Object propertyId) {
            String style = "";
            Item item = source.getItem(itemId);
            Boolean blacklisted = (Boolean) item.getItemProperty(BLACKLISTED_PROPERTY).getValue();
            if (blacklisted.booleanValue()) {
                style += OpenCmsTheme.PROJECT_OTHER + " ";
            } else if (CmsResourceTableProperty.PROPERTY_TITLE.equals(propertyId) && ((item.getItemProperty(CmsResourceTableProperty.PROPERTY_RELEASED_NOT_EXPIRED) == null) || ((Boolean) item.getItemProperty(CmsResourceTableProperty.PROPERTY_RELEASED_NOT_EXPIRED).getValue()).booleanValue())) {
                style += OpenCmsTheme.IN_NAVIGATION + " ";
            }
            if (INFO_PROPERTY_LABEL.equals(propertyId)) {
                if (blacklisted.booleanValue()) {
                    style += OpenCmsTheme.TABLE_COLUMN_BOX_BLACK;
                } else {
                    Object value = item.getItemProperty(INFO_PROPERTY).getValue();
                    if (value == null) {
                        style += OpenCmsTheme.TABLE_COLUMN_BOX_GRAY;
                    } else {
                        I_CmsSerialDateValue.DateType type = I_CmsSerialDateValue.DateType.valueOf((String) value);
                        switch(type) {
                            case SERIES:
                                style += OpenCmsTheme.TABLE_COLUMN_BOX_BLUE_LIGHT;
                                break;
                            case SINGLE:
                                style += OpenCmsTheme.TABLE_COLUMN_BOX_GRAY;
                                break;
                            case EXTRACTED:
                                style += OpenCmsTheme.TABLE_COLUMN_BOX_ORANGE;
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            return style;
        }
    });
    final ItemDescriptionGenerator defaultDescriptionGenerator = new CmsResourceTable.DefaultItemDescriptionGenerator();
    m_resultTable.setsetItemDescriptionGenerator(new ItemDescriptionGenerator() {

        private static final long serialVersionUID = 1L;

        public String generateDescription(Component source, Object itemId, Object propertyId) {
            Item item = ((Table) source).getItem(itemId);
            if (INFO_PROPERTY_LABEL.equals(propertyId) && ((Boolean) item.getItemProperty(BLACKLISTED_PROPERTY).getValue()).booleanValue()) {
                return CmsVaadinUtils.getMessageText(Messages.GUI_LISTMANAGER_COLUMN_BLACKLISTED_0);
            }
            return defaultDescriptionGenerator.generateDescription(source, itemId, propertyId);
        }
    });
    m_resultTable.setContextProvider(this);
    m_resultTable.addPropertyProvider(this);
    m_resultTable.setSizeFull();
    m_resultLayout.setSecondComponent(m_resultTable);
    m_overviewTable = new CmsFileTable(this);
    m_overviewTable.applyWorkplaceAppSettings();
    m_overviewTable.setMenuBuilder(menuBuilderOverView);
    m_overviewTable.setSizeFull();
    m_tableFilter = new TextField();
    m_tableFilter.setIcon(FontOpenCms.FILTER);
    m_tableFilter.setInputPrompt(Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_EXPLORER_FILTER_0));
    m_tableFilter.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
    m_tableFilter.setWidth("200px");
    m_tableFilter.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void textChange(TextChangeEvent event) {
            filterTable(event.getText());
        }
    });
    m_infoLayout.addComponent(m_tableFilter);
    m_localeSelect = new ComboBox();
    m_localeSelect.setNullSelectionAllowed(false);
    m_localeSelect.setWidth("100px");
    m_localeSelect.addValueChangeListener(new ValueChangeListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            changeContentLocale((Locale) event.getProperty().getValue());
        }
    });
    m_infoLayout.addComponent(m_localeSelect);
    m_resultSorter = new ComboBox();
    m_resultSorter.setNullSelectionAllowed(false);
    m_resultSorter.setWidth("200px");
    for (int i = 0; i < SORT_OPTIONS[0].length; i++) {
        m_resultSorter.addItem(SORT_OPTIONS[0][i]);
        m_resultSorter.setItemCaption(SORT_OPTIONS[0][i], CmsVaadinUtils.getMessageText(SORT_OPTIONS[1][i]));
    }
    m_resultSorter.addValueChangeListener(new ValueChangeListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            sortResult();
        }
    });
    m_infoLayout.addComponent(m_resultSorter);
    m_textSearch = new TextField();
    m_textSearch.setIcon(FontOpenCms.SEARCH);
    m_textSearch.setInputPrompt(CmsVaadinUtils.getMessageText(Messages.GUI_LISTMANAGER_SEARCH_0));
    m_textSearch.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
    m_textSearch.setWidth("200px");
    m_textSearch.addValueChangeListener(new ValueChangeListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            search((String) event.getProperty().getValue());
        }
    });
    m_infoLayout.addComponent(m_textSearch);
    m_resultLayout.setSecondComponent(m_resultTable);
    m_resultLayout.setSplitPosition(CmsFileExplorer.LAYOUT_SPLIT_POSITION, Unit.PIXELS);
}
Also used : CmsResourceTableProperty(org.opencms.ui.components.CmsResourceTableProperty) Locale(java.util.Locale) CmsMenuItemVisibilityMode(org.opencms.ui.contextmenu.CmsMenuItemVisibilityMode) CmsResourceInfoAction(org.opencms.ui.actions.CmsResourceInfoAction) ClickEvent(com.vaadin.ui.Button.ClickEvent) CellStyleGenerator(com.vaadin.v7.ui.Table.CellStyleGenerator) I_CmsContextMenuItemProvider(org.opencms.ui.contextmenu.I_CmsContextMenuItemProvider) LinkedHashMap(java.util.LinkedHashMap) CmsContextMenuActionItem(org.opencms.ui.actions.CmsContextMenuActionItem) Item(com.vaadin.v7.data.Item) I_CmsContextMenuItem(org.opencms.ui.contextmenu.I_CmsContextMenuItem) CmsContextMenuActionItem(org.opencms.ui.actions.CmsContextMenuActionItem) CmsObject(org.opencms.file.CmsObject) ValueChangeListener(com.vaadin.v7.data.Property.ValueChangeListener) TextField(com.vaadin.v7.ui.TextField) ArrayList(java.util.ArrayList) List(java.util.List) CmsSolrResultList(org.opencms.search.solr.CmsSolrResultList) CmsUUID(org.opencms.util.CmsUUID) Component(com.vaadin.ui.Component) TextChangeListener(com.vaadin.v7.event.FieldEvents.TextChangeListener) ClickListener(com.vaadin.ui.Button.ClickListener) CmsResourceContextMenuBuilder(org.opencms.ui.contextmenu.CmsResourceContextMenuBuilder) Table(com.vaadin.v7.ui.Table) CmsFileTable(org.opencms.ui.components.CmsFileTable) CmsResourceTable(org.opencms.ui.components.CmsResourceTable) CmsFileTableDialogContext(org.opencms.ui.components.CmsFileTableDialogContext) I_CmsDialogContext(org.opencms.ui.I_CmsDialogContext) A_CmsWorkplaceAction(org.opencms.ui.actions.A_CmsWorkplaceAction) ComboBox(com.vaadin.v7.ui.ComboBox) ValueChangeEvent(com.vaadin.v7.data.Property.ValueChangeEvent) ItemDescriptionGenerator(com.vaadin.v7.ui.AbstractSelect.ItemDescriptionGenerator) I_CmsDialogContext(org.opencms.ui.I_CmsDialogContext) CmsResource(org.opencms.file.CmsResource) TextChangeEvent(com.vaadin.v7.event.FieldEvents.TextChangeEvent) HorizontalSplitPanel(com.vaadin.ui.HorizontalSplitPanel) CmsEditDialogAction(org.opencms.ui.actions.CmsEditDialogAction) CmsObject(org.opencms.file.CmsObject) CmsFileTable(org.opencms.ui.components.CmsFileTable) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 4 with I_CmsContextMenuItem

use of org.opencms.ui.contextmenu.I_CmsContextMenuItem in project opencms-core by alkacon.

the class CmsCoreService method getContextMenuEntries.

/**
 * Returns the context menu entries for the given URI.<p>
 *
 * @param cms the cms context
 * @param structureId the currently requested structure id
 * @param context the ade context (sitemap or containerpage)
 *
 * @return the context menu entries
 */
public static List<CmsContextMenuEntryBean> getContextMenuEntries(final CmsObject cms, CmsUUID structureId, final AdeContext context) {
    Map<String, CmsContextMenuEntryBean> entries = new LinkedHashMap<String, CmsContextMenuEntryBean>();
    try {
        final List<CmsResource> resources;
        CmsResource resource = cms.readResource(structureId, CmsResourceFilter.ALL.addRequireVisible());
        // in case of sitemap editor check visibility with empty list
        if (context.equals(AdeContext.sitemapeditor)) {
            resources = Collections.emptyList();
        } else {
            resources = Collections.singletonList(resource);
        }
        Locale locale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms);
        // context to check item visibility
        I_CmsDialogContext dcontext = new I_CmsDialogContextWithAdeContext() {

            public void error(Throwable error) {
            // not supported
            }

            public void finish(CmsProject project, String siteRoot) {
            // not supported
            }

            public void finish(Collection<CmsUUID> result) {
            // not supported
            }

            public void focus(CmsUUID id) {
            // not supported
            }

            public AdeContext getAdeContext() {
                return context;
            }

            public List<CmsUUID> getAllStructureIdsInView() {
                return null;
            }

            public String getAppId() {
                return context.name();
            }

            public CmsObject getCms() {
                return cms;
            }

            public ContextType getContextType() {
                ContextType type;
                switch(context) {
                    case pageeditor:
                    case editprovider:
                        type = ContextType.containerpageToolbar;
                        break;
                    case sitemapeditor:
                        type = ContextType.sitemapToolbar;
                        break;
                    default:
                        type = ContextType.fileTable;
                }
                return type;
            }

            public List<CmsResource> getResources() {
                return resources;
            }

            public void navigateTo(String appId) {
            // not supported
            }

            public void onViewChange() {
            // not supported
            }

            public void reload() {
            // not supported
            }

            public void setWindow(Window window) {
            // not supported
            }

            public void start(String title, Component dialog) {
            // not supported
            }

            public void start(String title, Component dialog, DialogWidth width) {
            // not supported
            }

            public void updateUserInfo() {
            // not supported
            }
        };
        CmsContextMenuTreeBuilder builder = new CmsContextMenuTreeBuilder(dcontext);
        List<I_CmsContextMenuItem> items = new ArrayList<I_CmsContextMenuItem>();
        CmsTreeNode<I_CmsContextMenuItem> root = builder.buildAll(OpenCms.getWorkplaceAppManager().getMenuItemProvider().getMenuItems());
        for (CmsTreeNode<I_CmsContextMenuItem> child : root.getChildren()) {
            child.addDataInPreOrder(items);
        }
        Map<String, List<CmsContextMenuEntryBean>> submenus = new HashMap<String, List<CmsContextMenuEntryBean>>();
        for (I_CmsContextMenuItem item : items) {
            if (!item.isLeafItem()) {
                CmsMenuItemVisibilityMode visibility = item.getVisibility(dcontext);
                entries.put(item.getId(), new CmsContextMenuEntryBean(visibility.isActive(), true, null, item.getTitle(locale), null, CmsStringUtil.isEmptyOrWhitespaceOnly(visibility.getMessageKey()) ? null : OpenCms.getWorkplaceManager().getMessages(locale).getString(visibility.getMessageKey()), false, new ArrayList<CmsContextMenuEntryBean>()));
            } else if ((item instanceof I_CmsADEAction) && ((I_CmsADEAction) item).isAdeSupported()) {
                CmsMenuItemVisibilityMode visibility = item.getVisibility(dcontext);
                String jspPath = ((I_CmsADEAction) item).getJspPath();
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(jspPath)) {
                    jspPath = OpenCms.getLinkManager().substituteLink(cms, jspPath);
                }
                CmsContextMenuEntryBean itemBean = new CmsContextMenuEntryBean(visibility.isActive(), true, jspPath, item.getTitle(locale), ((I_CmsADEAction) item).getCommandClassName(), CmsStringUtil.isEmptyOrWhitespaceOnly(visibility.getMessageKey()) ? null : OpenCms.getWorkplaceManager().getMessages(locale).getString(visibility.getMessageKey()), false, null);
                Map<String, String> params = ((I_CmsADEAction) item).getParams();
                if (params != null) {
                    params = new HashMap<String, String>(params);
                    for (Entry<String, String> param : params.entrySet()) {
                        String value = CmsVfsService.prepareFileNameForEditor(cms, resource, param.getValue());
                        param.setValue(value);
                    }
                    itemBean.setParams(params);
                }
                entries.put(item.getId(), itemBean);
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(item.getParentId())) {
                    List<CmsContextMenuEntryBean> submenu;
                    if (submenus.containsKey(item.getParentId())) {
                        submenu = submenus.get(item.getParentId());
                    } else {
                        submenu = new ArrayList<CmsContextMenuEntryBean>();
                        submenus.put(item.getParentId(), submenu);
                    }
                    submenu.add(itemBean);
                }
            }
        }
        List<CmsContextMenuEntryBean> result = new ArrayList<CmsContextMenuEntryBean>();
        for (I_CmsContextMenuItem item : items) {
            if (entries.containsKey(item.getId())) {
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(item.getParentId())) {
                    if (entries.containsKey(item.getParentId())) {
                        CmsContextMenuEntryBean parent = entries.get(item.getParentId());
                        if (parent.getSubMenu() != null) {
                            parent.getSubMenu().add(entries.get(item.getId()));
                        }
                    }
                } else {
                    result.add(entries.get(item.getId()));
                }
            }
        }
        return result;
    } catch (CmsException e) {
        // ignore, the user probably has not enough permissions to read the resource
        LOG.debug(e.getLocalizedMessage(), e);
    }
    return Collections.emptyList();
}
Also used : Locale(java.util.Locale) CmsMenuItemVisibilityMode(org.opencms.ui.contextmenu.CmsMenuItemVisibilityMode) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) I_CmsADEAction(org.opencms.ui.actions.I_CmsADEAction) LinkedHashMap(java.util.LinkedHashMap) CmsCategoryTreeEntry(org.opencms.gwt.shared.CmsCategoryTreeEntry) Entry(java.util.Map.Entry) CmsUUID(org.opencms.util.CmsUUID) List(java.util.List) ArrayList(java.util.ArrayList) Component(com.vaadin.ui.Component) Window(com.vaadin.ui.Window) I_CmsContextMenuItem(org.opencms.ui.contextmenu.I_CmsContextMenuItem) DialogWidth(org.opencms.ui.components.CmsBasicDialog.DialogWidth) CmsContextMenuTreeBuilder(org.opencms.ui.contextmenu.CmsContextMenuTreeBuilder) CmsContextMenuEntryBean(org.opencms.gwt.shared.CmsContextMenuEntryBean) CmsResource(org.opencms.file.CmsResource) I_CmsDialogContext(org.opencms.ui.I_CmsDialogContext) I_CmsDialogContextWithAdeContext(org.opencms.ui.I_CmsDialogContextWithAdeContext) CmsException(org.opencms.main.CmsException) Collection(java.util.Collection) CmsProject(org.opencms.file.CmsProject) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with I_CmsContextMenuItem

use of org.opencms.ui.contextmenu.I_CmsContextMenuItem in project opencms-core by alkacon.

the class CmsToolBar method initContextMenu.

/**
 * Initializes the context menu entries.<p>
 */
private void initContextMenu() {
    m_contextMenu.removeItems();
    MenuItem main = m_contextMenu.addItem("", null);
    main.setIcon(FontOpenCms.CONTEXT_MENU);
    main.setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_MENU_TITLE_0));
    CmsContextMenuTreeBuilder treeBuilder = new CmsContextMenuTreeBuilder(getDialogContext());
    CmsTreeNode<I_CmsContextMenuItem> tree = treeBuilder.buildAll(OpenCms.getWorkplaceAppManager().getMenuItemProvider().getMenuItems());
    for (CmsTreeNode<I_CmsContextMenuItem> node : tree.getChildren()) {
        createMenuEntry(main, node, treeBuilder);
    }
}
Also used : I_CmsContextMenuItem(org.opencms.ui.contextmenu.I_CmsContextMenuItem) CmsContextMenuTreeBuilder(org.opencms.ui.contextmenu.CmsContextMenuTreeBuilder) MenuItem(com.vaadin.ui.MenuBar.MenuItem) I_CmsContextMenuItem(org.opencms.ui.contextmenu.I_CmsContextMenuItem)

Aggregations

I_CmsContextMenuItem (org.opencms.ui.contextmenu.I_CmsContextMenuItem)5 Component (com.vaadin.ui.Component)2 MenuItem (com.vaadin.ui.MenuBar.MenuItem)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2 CmsResource (org.opencms.file.CmsResource)2 I_CmsDialogContext (org.opencms.ui.I_CmsDialogContext)2 CmsContextMenuActionItem (org.opencms.ui.actions.CmsContextMenuActionItem)2 CmsContextMenuTreeBuilder (org.opencms.ui.contextmenu.CmsContextMenuTreeBuilder)2 CmsMenuItemVisibilityMode (org.opencms.ui.contextmenu.CmsMenuItemVisibilityMode)2 CmsUUID (org.opencms.util.CmsUUID)2 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 HorizontalSplitPanel (com.vaadin.ui.HorizontalSplitPanel)1 Command (com.vaadin.ui.MenuBar.Command)1 Window (com.vaadin.ui.Window)1