Search in sources :

Example 1 with ColumnGenerator

use of com.vaadin.v7.ui.Table.ColumnGenerator in project SORMAS-Project by hzi-braunschweig.

the class AbstractTableField method createEditColumn.

protected void createEditColumn(Table table) {
    ColumnGenerator editColumnGenerator = new ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            return generateEditCell(itemId);
        }
    };
    table.addGeneratedColumn(EDIT_COLUMN_ID, editColumnGenerator);
    table.setColumnWidth(EDIT_COLUMN_ID, 20);
    table.setColumnHeader(EDIT_COLUMN_ID, "");
    table.addItemClickListener(new ItemClickListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void itemClick(ItemClickEvent event) {
            if (event.isDoubleClick() || EDIT_COLUMN_ID.equals(event.getPropertyId())) {
                final E entry = (E) event.getItemId();
                if (entry != null) {
                    editEntry(entry, false, result -> onEntryChanged(result));
                }
            }
        }
    });
}
Also used : Arrays(java.util.Arrays) ItemClickListener(com.vaadin.v7.event.ItemClickEvent.ItemClickListener) ConversionException(com.vaadin.v7.data.util.converter.Converter.ConversionException) ColumnGenerator(com.vaadin.v7.ui.Table.ColumnGenerator) Table(com.vaadin.v7.ui.Table) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) VerticalLayout(com.vaadin.ui.VerticalLayout) LoggerFactory(org.slf4j.LoggerFactory) Alignment(com.vaadin.ui.Alignment) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EntityDto(de.symeda.sormas.api.EntityDto) BeanItemContainer(com.vaadin.v7.data.util.BeanItemContainer) CssStyles(de.symeda.sormas.ui.utils.CssStyles) ObjectUtils(org.apache.commons.lang3.ObjectUtils) FieldAccessCellStyleGenerator(de.symeda.sormas.ui.utils.FieldAccessCellStyleGenerator) Label(com.vaadin.ui.Label) VaadinIcons(com.vaadin.icons.VaadinIcons) LinkedHashSet(java.util.LinkedHashSet) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) ValoTheme(com.vaadin.ui.themes.ValoTheme) Property(com.vaadin.v7.data.Property) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DataHelper(de.symeda.sormas.api.utils.DataHelper) Collection(java.util.Collection) Set(java.util.Set) InvalidValueException(com.vaadin.v7.data.Validator.InvalidValueException) Captions(de.symeda.sormas.api.i18n.Captions) Consumer(java.util.function.Consumer) ItemSetChangeEvent(com.vaadin.v7.data.Container.ItemSetChangeEvent) List(java.util.List) Button(com.vaadin.ui.Button) ItemClickEvent(com.vaadin.v7.event.ItemClickEvent) HorizontalLayout(com.vaadin.ui.HorizontalLayout) CustomField(com.vaadin.v7.ui.CustomField) ItemSetChangeListener(com.vaadin.v7.data.Container.ItemSetChangeListener) CloneFailedException(org.apache.commons.lang3.exception.CloneFailedException) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) Component(com.vaadin.ui.Component) Table(com.vaadin.v7.ui.Table) ItemClickListener(com.vaadin.v7.event.ItemClickEvent.ItemClickListener) ColumnGenerator(com.vaadin.v7.ui.Table.ColumnGenerator) ItemClickEvent(com.vaadin.v7.event.ItemClickEvent)

Example 2 with ColumnGenerator

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

Example 3 with ColumnGenerator

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

the class CmsUserTable method init.

/**
 * initializes table.
 * @param showAll boolean
 */
protected void init(boolean showAll) {
    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.addUserContainerProperties(m_container);
    setContainerDataSource(m_container);
    setItemIconPropertyId(TableProperty.Icon);
    setRowHeaderMode(RowHeaderMode.ICON_ONLY);
    setColumnWidth(null, 40);
    setColumnWidth(TableProperty.STATUS, 100);
    setSelectable(true);
    setMultiSelect(true);
    setVisibleColumns(TableProperty.Name, TableProperty.OU);
    fillContainer(showAll);
    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> userIds = new HashSet<String>();
                for (CmsUser user : (Set<CmsUser>) getValue()) {
                    userIds.add(user.getId().getStringValue());
                }
                m_menu.setEntries(getMenuEntries(), userIds);
                m_menu.openForTable(event, event.getItemId(), event.getPropertyId(), CmsUserTable.this);
            } else if (event.getButton().equals(MouseButton.LEFT) && TableProperty.Name.equals(event.getPropertyId())) {
                CmsUser user = ((Set<CmsUser>) getValue()).iterator().next();
                try {
                    openInfoDialog(user.getId());
                } catch (CmsException e) {
                    LOG.error("Error on opening user info dialog", e);
                }
            }
        }
    });
    setCellStyleGenerator(new CellStyleGenerator() {

        private static final long serialVersionUID = 4685652851810828147L;

        public String getStyle(Table source, Object itemId, Object propertyId) {
            if (TableProperty.STATUS.equals(propertyId)) {
                return getStatusStyleForItem(source.getItem(itemId), (CmsUser) itemId);
            }
            String css = " ";
            if (((Boolean) (source.getItem(itemId).getItemProperty(TableProperty.FROMOTHEROU).getValue())).booleanValue()) {
                css += OpenCmsTheme.EXPIRED;
            }
            if (TableProperty.Name.equals(propertyId)) {
                css += " " + OpenCmsTheme.HOVER_COLUMN;
            }
            if (((Boolean) source.getItem(itemId).getItemProperty(TableProperty.INDIRECT).getValue()).booleanValue()) {
                return css + " " + OpenCmsTheme.TABLE_CELL_DISABLED;
            }
            return css.length() == 1 ? null : css;
        }

        private String getStatusStyleForItem(Item item, CmsUser user) {
            if (((Boolean) item.getItemProperty(TableProperty.DISABLED).getValue()).booleanValue()) {
                return OpenCmsTheme.TABLE_COLUMN_BOX_GRAY;
            }
            if (OpenCms.getLoginManager().isUserTempDisabled(user.getName())) {
                return OpenCmsTheme.TABLE_COLUMN_BOX_RED;
            }
            if (((Boolean) item.getItemProperty(TableProperty.NEWUSER).getValue()).booleanValue()) {
                return OpenCmsTheme.TABLE_COLUMN_BOX_BLUE;
            }
            if (isUserPasswordReset(user)) {
                return OpenCmsTheme.TABLE_COLUMN_BOX_ORANGE;
            }
            return OpenCmsTheme.TABLE_COLUMN_BOX_GREEN;
        }
    });
    addGeneratedColumn(TableProperty.STATUS, new ColumnGenerator() {

        private static final long serialVersionUID = -2144476865774782965L;

        public Object generateCell(Table source, Object itemId, Object columnId) {
            return getStatus((CmsUser) itemId, ((Boolean) source.getItem(itemId).getItemProperty(TableProperty.DISABLED).getValue()).booleanValue(), ((Boolean) source.getItem(itemId).getItemProperty(TableProperty.NEWUSER).getValue()).booleanValue());
        }
    });
    addGeneratedColumn(TableProperty.LastLogin, new ColumnGenerator() {

        private static final long serialVersionUID = -6781906011584975559L;

        public Object generateCell(Table source, Object itemId, Object columnId) {
            long lastLogin = ((Long) source.getItem(itemId).getItemProperty(TableProperty.LastLogin).getValue()).longValue();
            return lastLogin == 0L ? CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_NEVER_LOGGED_IN_0) : CmsDateUtil.getDateTime(new Date(lastLogin), DateFormat.SHORT, A_CmsUI.get().getLocale());
        }
    });
    addGeneratedColumn(TableProperty.Created, new ColumnGenerator() {

        private static final long serialVersionUID = -6781906011584975559L;

        public Object generateCell(Table source, Object itemId, Object columnId) {
            long created = ((Long) source.getItem(itemId).getItemProperty(TableProperty.Created).getValue()).longValue();
            return created == 0L ? "" : CmsDateUtil.getDateTime(new Date(created), DateFormat.SHORT, A_CmsUI.get().getLocale());
        }
    });
    setItemDescriptionGenerator(new ItemDescriptionGenerator() {

        private static final long serialVersionUID = 7367011213487089661L;

        public String generateDescription(Component source, Object itemId, Object propertyId) {
            if (TableProperty.STATUS.equals(propertyId)) {
                return getStatusHelp((CmsUser) itemId, ((Boolean) ((Table) source).getItem(itemId).getItemProperty(TableProperty.DISABLED).getValue()).booleanValue(), ((Boolean) ((Table) source).getItem(itemId).getItemProperty(TableProperty.NEWUSER).getValue()).booleanValue());
            }
            return null;
        }
    });
    setVisibleColumns(TableProperty.STATUS, TableProperty.Name, TableProperty.FullName, TableProperty.OU, TableProperty.LastLogin, TableProperty.Created);
}
Also used : CmsContextMenu(org.opencms.ui.contextmenu.CmsContextMenu) ItemClickListener(com.vaadin.v7.event.ItemClickEvent.ItemClickListener) Set(java.util.Set) HashSet(java.util.HashSet) Table(com.vaadin.v7.ui.Table) IndexedContainer(com.vaadin.v7.data.util.IndexedContainer) CmsUser(org.opencms.file.CmsUser) ItemClickEvent(com.vaadin.v7.event.ItemClickEvent) Date(java.util.Date) Item(com.vaadin.v7.data.Item) CmsException(org.opencms.main.CmsException) CmsObject(org.opencms.file.CmsObject) Component(com.vaadin.ui.Component)

Aggregations

ItemClickEvent (com.vaadin.v7.event.ItemClickEvent)3 ItemClickListener (com.vaadin.v7.event.ItemClickEvent.ItemClickListener)3 Table (com.vaadin.v7.ui.Table)3 Component (com.vaadin.ui.Component)2 Item (com.vaadin.v7.data.Item)2 IndexedContainer (com.vaadin.v7.data.util.IndexedContainer)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 CmsObject (org.opencms.file.CmsObject)2 CmsException (org.opencms.main.CmsException)2 CmsContextMenu (org.opencms.ui.contextmenu.CmsContextMenu)2 VaadinIcons (com.vaadin.icons.VaadinIcons)1 Alignment (com.vaadin.ui.Alignment)1 Button (com.vaadin.ui.Button)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Label (com.vaadin.ui.Label)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 ValoTheme (com.vaadin.ui.themes.ValoTheme)1