use of com.vaadin.v7.ui.AbstractSelect.ItemDescriptionGenerator 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);
}
use of com.vaadin.v7.ui.AbstractSelect.ItemDescriptionGenerator 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