Search in sources :

Example 1 with CmsContextMenu

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

the class CmsRoleTable method init.

/**
 * initializes table.
 *
 * @param roles list of user
 */
private void init(List<CmsRole> roles) {
    CmsRole.applySystemRoleOrder(roles);
    m_menu = new CmsContextMenu();
    m_menu.setAsTableContextMenu(this);
    m_container = new IndexedContainer();
    for (TableProperty prop : TableProperty.values()) {
        m_container.addContainerProperty(prop, prop.getType(), prop.getDefault());
        setColumnHeader(prop, prop.getName());
    }
    setContainerDataSource(m_container);
    setItemIconPropertyId(TableProperty.Icon);
    setRowHeaderMode(RowHeaderMode.ICON_ONLY);
    setColumnWidth(null, 40);
    setSelectable(true);
    setVisibleColumns(TableProperty.Name, TableProperty.OU);
    for (CmsRole role : roles) {
        Item item = m_container.addItem(role);
        item.getItemProperty(TableProperty.Name).setValue(role.getName(A_CmsUI.get().getLocale()));
        item.getItemProperty(TableProperty.Description).setValue(role.getDescription(A_CmsUI.get().getLocale()));
        item.getItemProperty(TableProperty.OU).setValue(role.getOuFqn());
    }
    addItemClickListener(new ItemClickListener() {

        private static final long serialVersionUID = 4807195510202231174L;

        public void itemClick(ItemClickEvent event) {
            setValue(null);
            select(event.getItemId());
            if (event.getButton().equals(MouseButton.RIGHT) || (event.getPropertyId() == null)) {
                m_menu.setEntries(getMenuEntries(), Collections.singleton(((CmsRole) getValue()).getId().getStringValue()));
                m_menu.openForTable(event, event.getItemId(), event.getPropertyId(), CmsRoleTable.this);
            } else if (event.getButton().equals(MouseButton.LEFT) && event.getPropertyId().equals(TableProperty.Name)) {
                updateApp((CmsRole) getValue());
            }
        }
    });
    setCellStyleGenerator(new CellStyleGenerator() {

        private static final long serialVersionUID = 1L;

        public String getStyle(Table source, Object itemId, Object propertyId) {
            if (TableProperty.Name.equals(propertyId)) {
                return " " + OpenCmsTheme.HOVER_COLUMN;
            }
            return "";
        }
    });
    setVisibleColumns(TableProperty.Name, TableProperty.Description, TableProperty.OU);
}
Also used : Item(com.vaadin.v7.data.Item) CmsContextMenu(org.opencms.ui.contextmenu.CmsContextMenu) CmsRole(org.opencms.security.CmsRole) ItemClickListener(com.vaadin.v7.event.ItemClickEvent.ItemClickListener) Table(com.vaadin.v7.ui.Table) IndexedContainer(com.vaadin.v7.data.util.IndexedContainer) CmsObject(org.opencms.file.CmsObject) ItemClickEvent(com.vaadin.v7.event.ItemClickEvent)

Example 2 with CmsContextMenu

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

the class CmsMessageBundleEditor method createTable.

/**
 * Creates the (filled) table UI component.
 * @return the (filled) table
 * @throws IOException thrown if reading the properties file fails.
 * @throws CmsException thrown if some read action for getting the table contentFilter fails.
 */
private FilterTable createTable() throws IOException, CmsException {
    final FilterTable table = new FilterTable();
    table.setSizeFull();
    table.setContainerDataSource(m_model.getContainerForCurrentLocale());
    table.setColumnHeader(TableProperty.KEY, m_configurableMessages.getColumnHeader(TableProperty.KEY));
    table.setColumnCollapsible(TableProperty.KEY, false);
    table.setColumnHeader(TableProperty.DEFAULT, m_configurableMessages.getColumnHeader(TableProperty.DEFAULT));
    table.setColumnCollapsible(TableProperty.DEFAULT, true);
    table.setColumnHeader(TableProperty.DESCRIPTION, m_configurableMessages.getColumnHeader(TableProperty.DESCRIPTION));
    table.setColumnCollapsible(TableProperty.DESCRIPTION, true);
    table.setColumnHeader(TableProperty.TRANSLATION, m_configurableMessages.getColumnHeader(TableProperty.TRANSLATION));
    table.setColumnCollapsible(TableProperty.TRANSLATION, false);
    table.setColumnHeader(TableProperty.OPTIONS, m_configurableMessages.getColumnHeader(TableProperty.OPTIONS));
    table.setFilterDecorator(new CmsMessageBundleEditorFilterDecorator());
    table.setFilterBarVisible(true);
    table.setColumnCollapsible(TableProperty.OPTIONS, false);
    table.setSortEnabled(true);
    table.setEditable(true);
    table.setSelectable(true);
    table.setImmediate(true);
    table.setMultiSelect(false);
    table.setColumnCollapsingAllowed(m_model.hasDescriptor());
    table.setColumnReorderingAllowed(false);
    m_optionsColumn = generateOptionsColumn(table);
    if (m_model.isShowOptionsColumn(m_model.getEditMode())) {
        table.setFilterFieldVisible(TableProperty.OPTIONS, false);
        table.addGeneratedColumn(TableProperty.OPTIONS, m_optionsColumn);
    }
    table.setColumnWidth(TableProperty.OPTIONS, CmsMessageBundleEditorTypes.OPTION_COLUMN_WIDTH);
    table.setColumnExpandRatio(TableProperty.KEY, 1f);
    table.setColumnExpandRatio(TableProperty.DESCRIPTION, 1f);
    table.setColumnExpandRatio(TableProperty.DEFAULT, 1f);
    table.setColumnExpandRatio(TableProperty.TRANSLATION, 1f);
    table.setPageLength(30);
    table.setCacheRate(1);
    table.sort(new Object[] { TableProperty.KEY }, new boolean[] { true });
    table.addContextClickListener(new ContextClickListener() {

        private static final long serialVersionUID = 1L;

        public void contextClick(ContextClickEvent event) {
            Object itemId = m_table.getValue();
            CmsContextMenu contextMenu = m_model.getContextMenuForItem(itemId);
            if (null != contextMenu) {
                contextMenu.setAsContextMenuOf(m_table);
                contextMenu.setOpenAutomatically(false);
                contextMenu.open(event.getClientX(), event.getClientY());
            }
        }
    });
    table.setNullSelectionAllowed(false);
    table.select(table.getCurrentPageFirstItemId());
    return table;
}
Also used : CmsContextMenu(org.opencms.ui.contextmenu.CmsContextMenu) ContextClickListener(com.vaadin.event.ContextClickEvent.ContextClickListener) ContextClickEvent(com.vaadin.event.ContextClickEvent) CmsObject(org.opencms.file.CmsObject) FilterTable(org.tepi.filtertable.FilterTable)

Example 3 with CmsContextMenu

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

the class CmsMessageBundleEditorModel method getContextMenuForItem.

/**
 * Returns the context menu for the table item.
 * @param itemId the table item.
 * @return the context menu for the given item.
 */
public CmsContextMenu getContextMenuForItem(Object itemId) {
    CmsContextMenu result = null;
    try {
        final Item item = m_container.getItem(itemId);
        Property<?> keyProp = item.getItemProperty(TableProperty.KEY);
        String key = (String) keyProp.getValue();
        if ((null != key) && !key.isEmpty()) {
            loadAllRemainingLocalizations();
            final Map<Locale, String> localesWithEntries = new HashMap<Locale, String>();
            for (Locale l : m_localizations.keySet()) {
                if (l != m_locale) {
                    String value = m_localizations.get(l).getProperty(key);
                    if ((null != value) && !value.isEmpty()) {
                        localesWithEntries.put(l, value);
                    }
                }
            }
            if (!localesWithEntries.isEmpty()) {
                result = new CmsContextMenu();
                ContextMenuItem mainItem = result.addItem(Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_BUNDLE_EDITOR_CONTEXT_COPY_LOCALE_0));
                for (final Locale l : localesWithEntries.keySet()) {
                    ContextMenuItem menuItem = mainItem.addItem(l.getDisplayName(UI.getCurrent().getLocale()));
                    menuItem.addItemClickListener(new ContextMenuItemClickListener() {

                        public void contextMenuItemClicked(ContextMenuItemClickEvent event) {
                            item.getItemProperty(TableProperty.TRANSLATION).setValue(localesWithEntries.get(l));
                        }
                    });
                }
            }
        }
    } catch (Exception e) {
        LOG.error(e.getLocalizedMessage(), e);
    // TODO: Improve
    }
    return result;
}
Also used : Locale(java.util.Locale) Item(com.vaadin.v7.data.Item) ContextMenuItem(org.opencms.ui.contextmenu.CmsContextMenu.ContextMenuItem) CmsContextMenu(org.opencms.ui.contextmenu.CmsContextMenu) ContextMenuItem(org.opencms.ui.contextmenu.CmsContextMenu.ContextMenuItem) ContextMenuItemClickEvent(org.opencms.ui.contextmenu.CmsContextMenu.ContextMenuItemClickEvent) HashMap(java.util.HashMap) ContextMenuItemClickListener(org.opencms.ui.contextmenu.CmsContextMenu.ContextMenuItemClickListener) CmsMessageException(org.opencms.i18n.CmsMessageException) CmsXmlException(org.opencms.xml.CmsXmlException) CmsException(org.opencms.main.CmsException) CmsVfsResourceNotFoundException(org.opencms.file.CmsVfsResourceNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CmsLoaderException(org.opencms.loader.CmsLoaderException) CmsIllegalArgumentException(org.opencms.main.CmsIllegalArgumentException) IOException(java.io.IOException)

Example 4 with CmsContextMenu

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

the class CmsGroupTable method init.

/**
 * Initializes the table.<p>
 *
 * @param ou name
 */
protected void init(String ou) {
    m_menu = new CmsContextMenu();
    m_menu.setAsTableContextMenu(this);
    m_container = new IndexedContainer();
    for (TableProperty prop : TableProperty.values()) {
        m_container.addContainerProperty(prop, prop.getType(), prop.getDefault());
        setColumnHeader(prop, prop.getName());
    }
    m_app.addGroupContainerProperties(m_container);
    setContainerDataSource(m_container);
    setItemIconPropertyId(TableProperty.Icon);
    setRowHeaderMode(RowHeaderMode.ICON_ONLY);
    setColumnWidth(null, 40);
    setSelectable(true);
    setMultiSelect(true);
    for (CmsGroup group : m_groups) {
        Item item = m_container.addItem(group);
        m_app.fillGroupItem(item, group, m_indirects);
    }
    addItemClickListener(new ItemClickListener() {

        private static final long serialVersionUID = 4807195510202231174L;

        @SuppressWarnings("unchecked")
        public void itemClick(ItemClickEvent event) {
            changeValueIfNotMultiSelect(event.getItemId());
            if (event.getButton().equals(MouseButton.RIGHT) || (event.getPropertyId() == null)) {
                Set<String> groupIds = new HashSet<String>();
                for (CmsGroup group : (Set<CmsGroup>) getValue()) {
                    groupIds.add(group.getId().getStringValue());
                }
                m_menu.setEntries(getMenuEntries(), groupIds);
                m_menu.openForTable(event, event.getItemId(), event.getPropertyId(), CmsGroupTable.this);
                return;
            }
            if (event.getButton().equals(MouseButton.LEFT) && event.getPropertyId().equals(TableProperty.Name)) {
                updateApp((((Set<CmsGroup>) getValue()).iterator().next()).getId().getStringValue());
            }
        }
    });
    setCellStyleGenerator(new CellStyleGenerator() {

        private static final long serialVersionUID = 1L;

        public String getStyle(Table source, Object itemId, Object propertyId) {
            String css = "";
            if (((Boolean) source.getItem(itemId).getItemProperty(TableProperty.INDIRECT).getValue()).booleanValue()) {
                css += " " + OpenCmsTheme.TABLE_CELL_DISABLED + " " + OpenCmsTheme.EXPIRED;
            }
            if (TableProperty.Name.equals(propertyId)) {
                css += " " + OpenCmsTheme.HOVER_COLUMN;
            }
            return css;
        }
    });
    setVisibleColumns(TableProperty.Name, TableProperty.Description, TableProperty.OU);
}
Also used : CmsContextMenu(org.opencms.ui.contextmenu.CmsContextMenu) ItemClickListener(com.vaadin.v7.event.ItemClickEvent.ItemClickListener) HashSet(java.util.HashSet) Set(java.util.Set) Table(com.vaadin.v7.ui.Table) IndexedContainer(com.vaadin.v7.data.util.IndexedContainer) CmsGroup(org.opencms.file.CmsGroup) ItemClickEvent(com.vaadin.v7.event.ItemClickEvent) Item(com.vaadin.v7.data.Item) CmsObject(org.opencms.file.CmsObject)

Example 5 with CmsContextMenu

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

the class CmsOUTable method init.

/**
 * initializes table.<p>
 *
 * @param parentOu ou name
 */
private void init(String parentOu) {
    m_parentOu = parentOu;
    m_menu = new CmsContextMenu();
    m_menu.setAsTableContextMenu(this);
    m_container = new IndexedContainer();
    setContainerDataSource(m_container);
    for (TableProperty prop : TableProperty.values()) {
        m_container.addContainerProperty(prop, prop.getType(), prop.getDefault());
        setColumnHeader(prop, prop.getName());
    }
    setContainerDataSource(m_container);
    setItemIconPropertyId(TableProperty.Icon);
    setRowHeaderMode(RowHeaderMode.ICON_ONLY);
    setColumnWidth(null, 40);
    setSelectable(true);
    addGeneratedColumn(TableProperty.Ressources, new ColumnGenerator() {

        private static final long serialVersionUID = 4624734503799549261L;

        public Object generateCell(Table source, Object itemId, Object columnId) {
            String out = "";
            try {
                boolean isOu = true;
                for (I_CmsOuTreeType type : m_app.getTreeTypeProvider().getTreeTypes()) {
                    if (type.getId().equals(itemId)) {
                        isOu = false;
                    }
                }
                if (isOu) {
                    List<CmsResource> resources = OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit(m_cms, (String) itemId);
                    if (!resources.isEmpty()) {
                        out = resources.get(0).getRootPath();
                        int i = 1;
                        while ((resources.size() > i) & (out.length() < 50)) {
                            out += ", " + resources.get(i).getRootPath();
                        }
                        if (resources.size() > i) {
                            out += " ...";
                        }
                    }
                }
            } catch (CmsException e) {
                LOG.error("unable to read resources.", e);
            }
            return out;
        }
    });
    setVisibleColumns(TableProperty.Name, TableProperty.Description, TableProperty.Ressources);
    try {
        m_cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
        m_cms.getRequestContext().setSiteRoot("");
    } catch (CmsException e) {
        m_cms = A_CmsUI.getCmsObject();
    }
    try {
        if (m_app.isOUManagable(m_parentOu)) {
            for (I_CmsOuTreeType treeType : m_app.getTreeTypeProvider().getTreeTypes()) {
                if (treeType.showInOuTable() && treeType.isValidForOu(m_cms, m_parentOu)) {
                    Item item = m_container.addItem(treeType.getId());
                    item.getItemProperty(TableProperty.Name).setValue(treeType.getName());
                    item.getItemProperty(TableProperty.Icon).setValue(treeType.getIcon());
                    item.getItemProperty(TableProperty.Type).setValue(treeType);
                }
            }
        }
        List<CmsOrganizationalUnit> webOus = new ArrayList<CmsOrganizationalUnit>();
        for (CmsOrganizationalUnit ou : OpenCms.getOrgUnitManager().getOrganizationalUnits(m_cms, parentOu, false)) {
            if (ou.hasFlagWebuser()) {
                webOus.add(ou);
            } else {
                addOuToTable(ou);
            }
        }
        for (CmsOrganizationalUnit ou : webOus) {
            addOuToTable(ou);
        }
    } catch (CmsException e) {
        LOG.error("Unable to read ous", e);
    }
    addItemClickListener(new ItemClickListener() {

        private static final long serialVersionUID = 4807195510202231174L;

        public void itemClick(ItemClickEvent event) {
            setValue(null);
            select(event.getItemId());
            if (event.getButton().equals(MouseButton.RIGHT) || (event.getPropertyId() == null)) {
                m_menu.setEntries(getMenuEntries(), Collections.singleton((String) getValue()));
                m_menu.openForTable(event, event.getItemId(), event.getPropertyId(), CmsOUTable.this);
                return;
            }
            if (event.getButton().equals(MouseButton.LEFT) && event.getPropertyId().equals(TableProperty.Name)) {
                updateApp((String) getValue());
            }
        }
    });
    setCellStyleGenerator(new CellStyleGenerator() {

        private static final long serialVersionUID = 1L;

        public String getStyle(Table source, Object itemId, Object propertyId) {
            if (TableProperty.Name.equals(propertyId)) {
                return " " + OpenCmsTheme.HOVER_COLUMN;
            }
            return "";
        }
    });
}
Also used : CmsContextMenu(org.opencms.ui.contextmenu.CmsContextMenu) Table(com.vaadin.v7.ui.Table) ItemClickListener(com.vaadin.v7.event.ItemClickEvent.ItemClickListener) IndexedContainer(com.vaadin.v7.data.util.IndexedContainer) ArrayList(java.util.ArrayList) ItemClickEvent(com.vaadin.v7.event.ItemClickEvent) CmsOrganizationalUnit(org.opencms.security.CmsOrganizationalUnit) Item(com.vaadin.v7.data.Item) CmsException(org.opencms.main.CmsException) CmsObject(org.opencms.file.CmsObject) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

CmsContextMenu (org.opencms.ui.contextmenu.CmsContextMenu)7 Item (com.vaadin.v7.data.Item)6 IndexedContainer (com.vaadin.v7.data.util.IndexedContainer)5 CmsObject (org.opencms.file.CmsObject)5 ItemClickEvent (com.vaadin.v7.event.ItemClickEvent)4 ItemClickListener (com.vaadin.v7.event.ItemClickEvent.ItemClickListener)4 Table (com.vaadin.v7.ui.Table)4 CmsException (org.opencms.main.CmsException)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 CmsUser (org.opencms.file.CmsUser)2 CmsOrganizationalUnit (org.opencms.security.CmsOrganizationalUnit)2 ContextClickEvent (com.vaadin.event.ContextClickEvent)1 ContextClickListener (com.vaadin.event.ContextClickEvent.ContextClickListener)1 Component (com.vaadin.ui.Component)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1