use of com.haulmont.cuba.gui.components.Table in project cuba by cuba-platform.
the class GroupTableLoader method loadColumns.
@Override
protected List<Table.Column> loadColumns(final Table component, Element columnsElement, CollectionDatasource ds) {
List<Table.Column> columns = new ArrayList<>();
Element groupElement = columnsElement.element("group");
if (groupElement != null) {
columns.addAll(super.loadColumns(component, groupElement, ds));
final List<Object> groupProperties = new ArrayList<>(columns.size());
for (Table.Column column : columns) {
if (column.isCollapsed()) {
String msg = String.format("Can't group by collapsed column: %s", column.getId());
throw new GuiDevelopmentException(msg, context.getFullFrameId());
}
if (column.isGroupAllowed()) {
groupProperties.add(column.getId());
}
}
context.addPostInitTask((context1, window) -> ((GroupTable) component).groupBy(groupProperties.toArray()));
}
columns.addAll(super.loadColumns(component, columnsElement, ds));
return columns;
}
use of com.haulmont.cuba.gui.components.Table in project cuba by cuba-platform.
the class LinkColumnHelper method initColumn.
public static void initColumn(Table table, final String propertyName, final Handler handler) {
final ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.NAME);
table.addGeneratedColumn(propertyName, new Table.ColumnGenerator() {
@Override
public Component generateCell(final Entity entity) {
// //process properties like building.house.room
String[] props = propertyName.split("\\.");
Instance nestedEntity = entity;
for (int i = 0; i < props.length - 1; i++) {
nestedEntity = nestedEntity.getValue(props[i]);
if (nestedEntity == null) {
break;
}
}
final Object value = (nestedEntity == null) ? null : nestedEntity.getValue(props[props.length - 1]);
if (value != null) {
Button button = componentsFactory.createComponent(Button.class);
button.setStyleName("link");
button.setAction(new AbstractAction("open") {
@Override
public void actionPerform(Component component) {
handler.onClick(entity);
}
@Override
public String getCaption() {
String str;
Datatype datatype = Datatypes.get(value.getClass());
if (datatype != null) {
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
str = datatype.format(value, sessionSource.getLocale());
} else {
str = value.toString();
}
return str;
}
});
button.setStyleName("link");
return button;
}
return null;
}
});
}
use of com.haulmont.cuba.gui.components.Table in project cuba by cuba-platform.
the class WebAbstractTable method initComponent.
protected void initComponent(final T component) {
component.setMultiSelect(false);
component.setImmediate(true);
component.setValidationVisible(false);
component.setShowBufferedSourceException(false);
component.setBeforePaintListener(() -> {
com.vaadin.ui.Table.CellStyleGenerator generator = component.getCellStyleGenerator();
if (generator instanceof WebAbstractTable.StyleGeneratorAdapter) {
// noinspection unchecked
((StyleGeneratorAdapter) generator).resetExceptionHandledFlag();
}
});
Messages messages = AppBeans.get(Messages.NAME);
component.setSortAscendingLabel(messages.getMainMessage("tableSort.ascending"));
component.setSortResetLabel(messages.getMainMessage("tableSort.reset"));
component.setSortDescendingLabel(messages.getMainMessage("tableSort.descending"));
setClientCaching(component);
int defaultRowHeaderWidth = 16;
ThemeConstants theme = App.getInstance().getThemeConstants();
if (theme != null) {
defaultRowHeaderWidth = theme.getInt("cuba.web.Table.defaultRowHeaderWidth");
}
// CAUTION: vaadin considers null as row header property id;
// todo get width from theme
component.setColumnWidth(null, defaultRowHeaderWidth);
contextMenuPopup.setParent(component);
component.setContextMenuPopup(contextMenuPopup);
shortcutsDelegate.setAllowEnterShortcut(false);
component.addValueChangeListener(event -> {
if (datasource == null) {
return;
}
final Set<? extends Entity> selected = getSelected();
if (selected.isEmpty()) {
Entity dsItem = datasource.getItemIfValid();
datasource.setItem(null);
if (dsItem == null) {
// in this case item change event will not be generated
refreshActionsState();
}
} else {
// reset selection and select new item
if (isMultiSelect()) {
datasource.setItem(null);
}
Entity newItem = selected.iterator().next();
Entity dsItem = datasource.getItemIfValid();
datasource.setItem(newItem);
if (Objects.equals(dsItem, newItem)) {
// in this case item change event will not be generated
refreshActionsState();
}
}
LookupSelectionChangeEvent selectionChangeEvent = new LookupSelectionChangeEvent(this);
getEventRouter().fireEvent(LookupSelectionChangeListener.class, LookupSelectionChangeListener::lookupValueChanged, selectionChangeEvent);
});
component.addShortcutListener(new ShortcutListener("tableEnter", com.vaadin.event.ShortcutAction.KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
if (target == WebAbstractTable.this.component) {
if (enterPressAction != null) {
enterPressAction.actionPerform(WebAbstractTable.this);
} else {
handleClickAction();
}
}
}
});
component.addItemClickListener(event -> {
if (event.isDoubleClick() && event.getItem() != null) {
handleClickAction();
}
});
component.setSelectable(true);
component.setTableFieldFactory(createFieldFactory());
component.setColumnCollapsingAllowed(true);
component.setColumnReorderingAllowed(true);
setEditable(false);
componentComposition = new TableComposition();
componentComposition.setTable(component);
componentComposition.setPrimaryStyleName("c-table-composition");
componentComposition.addComponent(component);
component.setCellStyleGenerator(createStyleGenerator());
component.addColumnCollapseListener(this::handleColumnCollapsed);
// force default sizes
componentComposition.setHeightUndefined();
componentComposition.setWidthUndefined();
}
Aggregations