use of com.haulmont.cuba.gui.components.data.meta.EntityTableItems in project cuba by cuba-platform.
the class WebAbstractTable method tableSourceItemSetChanged.
@Override
public void tableSourceItemSetChanged(TableItems.ItemSetChangeEvent<E> event) {
// replacement for collectionChangeSelectionListener
// #PL-2035, reload selection from ds
Set<Object> selectedItemIds = getSelectedItemIds();
if (selectedItemIds == null) {
selectedItemIds = Collections.emptySet();
}
Set<Object> newSelection = new LinkedHashSet<>();
TableItems<E> tableItems = event.getSource();
for (Object entityId : selectedItemIds) {
if (tableItems.getItem(entityId) != null) {
newSelection.add(entityId);
}
}
if (tableItems.getState() == BindingState.ACTIVE && tableItems instanceof EntityTableItems) {
EntityTableItems entityTableSource = (EntityTableItems) tableItems;
if (entityTableSource.getSelectedItem() != null) {
newSelection.add(entityTableSource.getSelectedItem().getId());
}
}
if (newSelection.isEmpty()) {
setSelected((E) null);
} else {
setSelectedIds(newSelection);
}
refreshActionsState();
}
use of com.haulmont.cuba.gui.components.data.meta.EntityTableItems in project cuba by cuba-platform.
the class WebAbstractTable method applyColumnSettings.
protected void applyColumnSettings(Element element, boolean presentationSettings) {
Element columnsElem = getColumnsElement(element);
Object[] oldColumns = component.getVisibleColumns();
List<Object> newColumns = new ArrayList<>();
// add columns from saved settings
for (Element colElem : columnsElem.elements("columns")) {
for (Object column : oldColumns) {
if (column.toString().equals(colElem.attributeValue("id"))) {
newColumns.add(column);
String width = colElem.attributeValue("width");
if (width != null) {
component.setColumnWidth(column, Integer.parseInt(width));
} else {
component.setColumnWidth(column, -1);
}
String visible = colElem.attributeValue("visible");
if (visible != null) {
if (component.isColumnCollapsingAllowed()) {
// throws exception if not
component.setColumnCollapsed(column, !Boolean.parseBoolean(visible));
}
}
break;
}
}
}
// add columns not saved in settings (perhaps new)
for (Object column : oldColumns) {
if (!newColumns.contains(column)) {
newColumns.add(column);
}
}
// if the table contains only one column, always show it
if (newColumns.size() == 1) {
if (component.isColumnCollapsingAllowed()) {
// throws exception if not
component.setColumnCollapsed(newColumns.get(0), false);
}
}
component.setVisibleColumns(newColumns.toArray());
@SuppressWarnings("unchecked") EntityTableItems<E> entityTableSource = (EntityTableItems) getItems();
if (isSortable() && !isApplyDataLoadingSettings()) {
String sortProp = columnsElem.attributeValue("sortProperty");
if (!StringUtils.isEmpty(sortProp)) {
MetaPropertyPath sortProperty = entityTableSource.getEntityMetaClass().getPropertyPath(sortProp);
if (newColumns.contains(sortProperty)) {
boolean sortAscending = Boolean.parseBoolean(columnsElem.attributeValue("sortAscending"));
component.setSortContainerPropertyId(null);
component.setSortAscending(sortAscending);
component.setSortContainerPropertyId(sortProperty);
}
} else {
component.setSortContainerPropertyId(null);
}
}
}
use of com.haulmont.cuba.gui.components.data.meta.EntityTableItems in project cuba by cuba-platform.
the class WebGroupTable method applyColumnSettings.
@Override
public void applyColumnSettings(Element element, boolean presentationSettings) {
super.applyColumnSettings(element, presentationSettings);
Element groupPropertiesElement = element.element("groupProperties");
if (groupPropertiesElement != null) {
MetaClass metaClass = ((EntityTableItems) getItems()).getEntityMetaClass();
List elements = groupPropertiesElement.elements("property");
List<MetaPropertyPath> properties = new ArrayList<>(elements.size());
for (Object o : elements) {
String id = ((Element) o).attributeValue("id");
MetaPropertyPath property = DynamicAttributesUtils.isDynamicAttribute(id) ? dynamicAttributesTools.getMetaPropertyPath(metaClass, id) : metaClass.getPropertyPath(id);
if (property != null) {
properties.add(property);
} else {
LoggerFactory.getLogger(WebGroupTable.class).warn("Ignored group property '{}'", id);
}
}
groupBy(properties.toArray());
} else if (presentationSettings) {
// Ungroup only for presentation, otherwise, it might be
// a table with a declaratively defined grouping.
ungroup();
}
}
Aggregations