use of com.vaadin.v7.event.ItemClickEvent.ItemClickListener 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);
}
Aggregations