Search in sources :

Example 1 with CellStyleGenerator

use of com.vaadin.v7.ui.Table.CellStyleGenerator 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 CellStyleGenerator

use of com.vaadin.v7.ui.Table.CellStyleGenerator 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 3 with CellStyleGenerator

use of com.vaadin.v7.ui.Table.CellStyleGenerator in project opencms-core by alkacon.

the class CmsPropertyTable method init.

/**
 * Fills table with items.<p>
 */
public void init() {
    try {
        List<CmsPropertyDefinition> properties = A_CmsUI.getCmsObject().readAllPropertyDefinitions();
        m_container = new IndexedContainer();
        for (TableColumn col : TableColumn.values()) {
            m_container.addContainerProperty(col, col.getType(), col.getDefaultValue());
        }
        setContainerDataSource(m_container);
        setItemIconPropertyId(TableColumn.Icon);
        setRowHeaderMode(RowHeaderMode.ICON_ONLY);
        setVisibleColumns(TableColumn.Name);
        for (CmsPropertyDefinition prop : properties) {
            Item item = m_container.addItem(prop);
            item.getItemProperty(TableColumn.Name).setValue(prop.getName());
        }
        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(((CmsPropertyDefinition) getValue()).getName()));
                    m_menu.openForTable(event, event.getItemId(), event.getPropertyId(), CmsPropertyTable.this);
                } else if (TableColumn.Name.equals(event.getPropertyId())) {
                    showResources(((CmsPropertyDefinition) getValue()).getName());
                }
            }
        });
        setCellStyleGenerator(new CellStyleGenerator() {

            private static final long serialVersionUID = 1L;

            public String getStyle(Table source, Object itemId, Object propertyId) {
                if (TableColumn.Name.equals(propertyId)) {
                    return " " + OpenCmsTheme.HOVER_COLUMN;
                }
                return null;
            }
        });
    } catch (CmsException e) {
    // 
    }
}
Also used : ItemClickListener(com.vaadin.v7.event.ItemClickEvent.ItemClickListener) Table(com.vaadin.v7.ui.Table) IndexedContainer(com.vaadin.v7.data.util.IndexedContainer) ItemClickEvent(com.vaadin.v7.event.ItemClickEvent) CmsPropertyDefinition(org.opencms.file.CmsPropertyDefinition) Item(com.vaadin.v7.data.Item) CmsException(org.opencms.main.CmsException)

Example 4 with CellStyleGenerator

use of com.vaadin.v7.ui.Table.CellStyleGenerator 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 CellStyleGenerator

use of com.vaadin.v7.ui.Table.CellStyleGenerator 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

Item (com.vaadin.v7.data.Item)6 Table (com.vaadin.v7.ui.Table)6 IndexedContainer (com.vaadin.v7.data.util.IndexedContainer)5 ItemClickEvent (com.vaadin.v7.event.ItemClickEvent)5 ItemClickListener (com.vaadin.v7.event.ItemClickEvent.ItemClickListener)5 CmsObject (org.opencms.file.CmsObject)5 CmsContextMenu (org.opencms.ui.contextmenu.CmsContextMenu)4 CmsException (org.opencms.main.CmsException)3 Component (com.vaadin.ui.Component)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 HorizontalSplitPanel (com.vaadin.ui.HorizontalSplitPanel)1 ValueChangeEvent (com.vaadin.v7.data.Property.ValueChangeEvent)1 ValueChangeListener (com.vaadin.v7.data.Property.ValueChangeListener)1 TextChangeEvent (com.vaadin.v7.event.FieldEvents.TextChangeEvent)1 TextChangeListener (com.vaadin.v7.event.FieldEvents.TextChangeListener)1