blob: ca03ee064e326f5bd95196fee737b062cc98fb49 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*/
package org.eclipse.osbp.xtext.table.common;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.osbp.blob.component.BlobUploadComponent;
import org.eclipse.osbp.bpm.api.BPMStatus;
import org.eclipse.osbp.runtime.common.historized.UUIDHist;
import org.eclipse.osbp.ui.api.customfields.IBlobService;
import org.eclipse.osbp.ui.api.metadata.IDSLMetadataService;
import org.eclipse.osbp.ui.api.themes.IThemeResourceService;
import org.eclipse.osbp.ui.api.user.IUser;
import org.eclipse.osbp.xtext.datamart.common.olap.DerivedAxis;
import org.eclipse.osbp.xtext.datamart.common.olap.DerivedCell;
import org.eclipse.osbp.xtext.datamart.common.olap.DerivedCellSet;
import org.eclipse.osbp.xtext.datamart.common.olap.DerivedLevel;
import org.eclipse.osbp.xtext.datamart.common.olap.DerivedMember;
import org.eclipse.osbp.xtext.datamart.common.olap.DerivedPosition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tepi.filtertable.FilterTable;
import org.tepi.filtertable.paged.PagedFilterTable;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.Component;
import com.vaadin.ui.CustomTable;
public class CellSetIndexedContainer extends IndexedContainer {
private static final long serialVersionUID = 5556029714794178000L;
private static final Logger log = LoggerFactory.getLogger(CellSetIndexedContainer.class);
private transient Map<String, PropertyLookup> propertyLookupMap = new HashMap<>();
private transient DerivedCellSet cellSet = null;
private transient List<Integer> coordinateSystem = null;
private transient Map<Integer, PositionInfo> positionMap = new HashMap<>();
private transient Map<DerivedPosition, Class<?>> valueTypes = new HashMap<>();
private String rowStyle = null;
private final transient IThemeResourceService themeResourceService;
private final transient IDSLMetadataService dslMetadataService;
private final transient IBlobService blobService;
private boolean isCrossTab = false;
private Locale locale;
public CellSetIndexedContainer(IEclipseContext eclipseContext,
Map<String, PropertyLookup> propertyLookupMap, final DerivedCellSet cellSet, List<Integer> coordinateSystem, boolean isCrossTab) {
super();
this.themeResourceService = eclipseContext.get(IThemeResourceService.class);
this.dslMetadataService = eclipseContext.get(IDSLMetadataService.class);
this.blobService = eclipseContext.get(IBlobService.class);
this.cellSet = cellSet;
this.coordinateSystem = coordinateSystem;
this.isCrossTab = isCrossTab;
this.setLocale(eclipseContext.get(IUser.class).getLocale());
addPropertyLookup(propertyLookupMap);
fillContainer();
}
@Override
public List<Object> getAllItemIds() {
return super.getAllItemIds();
}
@Override
public List<Object> getFilteredItemIds() {
return super.getFilteredItemIds();
}
public DerivedCellSet getCellSet() {
return cellSet;
}
public void setCellSet(DerivedCellSet cellSet) {
this.cellSet = cellSet;
}
public String getRowStyle() {
return rowStyle;
}
public void setRowStyle(String rowStyle) {
this.rowStyle = rowStyle;
}
public Map<String, PropertyLookup> getPropertyLookupMap() {
return propertyLookupMap;
}
public void addPropertyLookup(Map<String, PropertyLookup> propertyLookupMap) {
this.propertyLookupMap.putAll(propertyLookupMap);
}
public void addPropertyLookup(String columnName, PropertyLookup lookup) {
propertyLookupMap.put(columnName, lookup);
}
public void removePropertyLookup(String columnName) {
if (propertyLookupMap.containsKey(columnName)) {
propertyLookupMap.remove(columnName);
}
}
public DerivedPosition getColumnPosition(Object propertyId) {
if (positionMap.containsKey((Integer) propertyId)) {
return positionMap.get((Integer) propertyId).getPosition();
}
return null;
}
public Class<?> getColumnType(Object propertyId) {
if (positionMap.containsKey((Integer) propertyId)) {
return positionMap.get((Integer) propertyId).getType();
}
return null;
}
private PropertyLookup findColumnProperty(DerivedPosition column) {
String colName = column.toUppercaseString();
for (String key : propertyLookupMap.keySet()) {
// in cross tabs we must allow partly match
if (isCrossTab) {
if (colName.contains(key)) {
return propertyLookupMap.get(key);
}
} else {
if (colName.equals(key)) {
return propertyLookupMap.get(key);
}
}
}
return null;
}
private boolean addCellSetContainerProperty(DerivedPosition column, Object value, Object defaultValue, boolean isHeader) {
PropertyLookup lookup = null;
// resolve ordinal column properties
String tmpColname = "#";
if (isHeader) {
tmpColname += "ROWS";
} else {
tmpColname += "COLUMNS";
}
tmpColname += (new Integer(column.getOrdinal())).toString();
if (propertyLookupMap.containsKey(tmpColname)) {
propertyLookupMap.put(column.toUppercaseString(), propertyLookupMap.remove(tmpColname));
}
// resolve all columns properties
tmpColname = "?";
if (isHeader) {
tmpColname += "ROWS";
} else {
tmpColname += "COLUMNS";
}
if (propertyLookupMap.containsKey(tmpColname)) {
propertyLookupMap.put(column.toUppercaseString(), propertyLookupMap.get(tmpColname));
}
// for crossjoined cube columns the column name is a combination of both, so a partly match is ok
lookup = findColumnProperty(column);
// add default styles if not found
if (lookup == null) {
lookup = new PropertyLookup(themeResourceService, dslMetadataService, blobService, locale);
addPropertyLookup(column.toUppercaseString(), lookup);
}
Class<?> type = String.class;
if (value != null) {
// change type if applied
type = lookup.getPropertyType(value.getClass());
valueTypes.put(column, type);
}
// add default styles
lookup.setDefaultStyle(type, isHeader);
// create position map
positionMap.put(column.getOrdinal(), new PositionInfo(column, lookup.getValueObject(value)));
return addContainerProperty(column.getOrdinal(), type, defaultValue);
}
@SuppressWarnings("unchecked")
private boolean setCellSetContainerValue(DerivedPosition row, DerivedPosition column, Object value) {
PropertyLookup lookup = findColumnProperty(column);
if (lookup != null) {
if (getContainerProperty(row.getOrdinal(), column.getOrdinal()) != null) {
getContainerProperty(row.getOrdinal(), column.getOrdinal()).setValue(lookup.getValueObject(value));
}
return true;
}
if (!getContainerProperty(row.getOrdinal(), column.getOrdinal()).getType().isAssignableFrom(value.getClass())) {
return false;
}
getContainerProperty(row.getOrdinal(), column.getOrdinal()).setValue(value);
return true;
}
private DerivedPosition findColumn(String columnName) {
for (DerivedPosition column : cellSet.getAxes().get(DerivedAxis.AXIS_COLUMNS).getPositions()) {
if (columnName.equals(column.toUppercaseString())) {
return column;
}
}
return null;
}
public Object getOrdinalCellValue(Integer rowOrdinal, String columnName) {
return getCellValue(cellSet.getAxes().get(DerivedAxis.AXIS_ROWS).getPositionByOrdinal(rowOrdinal), findColumn(columnName));
}
public Object getCellValue(DerivedPosition row, DerivedPosition column) {
if (row == null || column == null || row.getOrdinal() == -1 || column.getOrdinal() == -1) {
return null;
}
List<Integer> coordinates = new ArrayList<>(coordinateSystem);
coordinates.set(DerivedAxis.AXIS_ROWS, row.getOrdinal());
coordinates.set(DerivedAxis.AXIS_COLUMNS, column.getOrdinal());
return cellSet.getCell(coordinates).getValue();
}
private boolean objectChanged(Object newValue, Object oldValue) {
if ((newValue == null && oldValue != null) || (newValue != null && oldValue == null)) {
return true;
}
if (newValue == null && oldValue == null) { // NOSONAR
return false;
}
if (newValue.getClass().equals(double.class)) {
if (Double.compare((double) newValue, (double) oldValue) != 0)
return true;
} else if (newValue.getClass().equals(Double.class)) {
if (((Double) newValue).compareTo((Double) oldValue) != 0)
return true;
} else if (newValue.getClass().equals(float.class)) {
if (Float.compare((float) newValue, (float) oldValue) != 0)
return true;
} else if (newValue.getClass().equals(Float.class)) {
if (((Float) newValue).compareTo((Float) oldValue) != 0)
return true;
} else if (newValue.getClass().equals(int.class)) {
if (Integer.compare((int) newValue, (int) oldValue) != 0)
return true;
} else if (newValue.getClass().equals(Integer.class)) {
if (((Integer) newValue).compareTo((Integer) oldValue) != 0)
return true;
} else if (newValue.getClass().equals(long.class)) {
if (Long.compare((long) newValue, (long) oldValue) != 0)
return true;
} else if (newValue.getClass().equals(Long.class)) {
if (((Long) newValue).compareTo((Long) oldValue) != 0)
return true;
} else if (newValue.getClass().equals(BigDecimal.class)) {
if (((BigDecimal) newValue).compareTo((BigDecimal) oldValue) != 0)
return true;
} else if (newValue.getClass().equals(String.class)) {
if (((String) newValue).compareTo((String) oldValue) != 0)
return true;
} else if (newValue.getClass().equals(Date.class)) {
if (((Date) newValue).compareTo((Date) oldValue) != 0)
return true;
} else if (newValue.getClass().equals(Timestamp.class)) {
if (((Timestamp) newValue).compareTo((Timestamp) oldValue) != 0)
return true;
}
return !newValue.equals(oldValue);
}
private void createRow(DerivedPosition row) {
addItem(row.getOrdinal());
for (DerivedMember member : row.getMembers()) {
String[] tokens = member.getUniqueName().split("\\]\\.\\[");
for (int token = 1; token < tokens.length; token++) {
if (!positionMap.containsKey(-1 * token)) {
DerivedPosition position = new DerivedPosition(row.getMembers(), -1 * token, row.getContainer());
addCellSetContainerProperty(position, "", null, true);
}
setCellSetContainerValue(row, positionMap.get(-1 * token).getPosition(), tokens[token].replace("]", ""));
}
}
}
private void createColumn(DerivedPosition row, DerivedPosition column) {
List<Integer> coordinates = new ArrayList<>(coordinateSystem);
coordinates.set(DerivedAxis.AXIS_ROWS, row.getOrdinal());
coordinates.set(DerivedAxis.AXIS_COLUMNS, column.getOrdinal());
Object value = null;
value = cellSet.getCell(coordinates).getValue();
if (value != null || !columnIsNull(column)) {
if(!valueTypes.containsKey(column)) {
// if (getContainerProperty(row.getOrdinal(), column.getOrdinal()) == null) {
addCellSetContainerProperty(column, value, null, false);
}
setCellSetContainerValue(row, column, value);
} else {
log.debug("'null' value on row:" + row.getOrdinal() + "/column:" + column.getOrdinal() + ", thus no cell created");
}
}
private boolean columnIsNull(DerivedPosition column) {
List<Integer> coordinates = new ArrayList<>(coordinateSystem);
coordinates.set(DerivedAxis.AXIS_COLUMNS, column.getOrdinal());
for (DerivedPosition row : cellSet.getAxes().get(DerivedAxis.AXIS_ROWS).getPositions()) {
coordinates.set(DerivedAxis.AXIS_ROWS, row.getOrdinal());
Object value = cellSet.getCell(coordinates).getValue();
if (value != null) {
if (getContainerProperty(row.getOrdinal(), column.getOrdinal()) == null) {
addCellSetContainerProperty(column, value, null, false);
}
return false;
}
}
return true;
}
public void clearContainer() {
removeAllContainerFilters();
removeAllItems();
}
public boolean updateContainer(final DerivedCellSet newCellSet) {
if(cellSet == null && newCellSet == null) {
log.debug("{}", "cellsets are null - no refresh");
return true;
}
if (cellSet == null && newCellSet != null || cellSet != null && newCellSet == null) {
removeAllContainerFilters();
removeAllItems();
log.debug("{}", "only one cellset is null - full refresh");
return false;
}
Iterator<DerivedPosition> oldIterator = cellSet.getAxes().get(DerivedAxis.AXIS_ROWS).getPositions().iterator();
Iterator<DerivedPosition> newIterator = newCellSet.getAxes().get(DerivedAxis.AXIS_ROWS).getPositions().iterator();
if (!oldIterator.hasNext() && newIterator.hasNext() || oldIterator.hasNext() && !newIterator.hasNext()) {
removeAllContainerFilters();
removeAllItems();
log.debug("{}", "cellsets different - full refresh");
return false;
}
if(cellSet.getAxes().get(DerivedAxis.AXIS_ROWS).getPositions().size() != newCellSet.getAxes().get(DerivedAxis.AXIS_ROWS).getPositions().size()) {
removeAllContainerFilters();
removeAllItems();
log.debug("{}", "cellsets have different num row - full refresh");
return false;
}
List<Integer> coordinatesForBoth = new ArrayList<>(coordinateSystem);
for (DerivedPosition newRow : newCellSet.getAxes().get(DerivedAxis.AXIS_ROWS).getPositions()) {
boolean rowFound = true;
DerivedPosition oldRow = null;
if (oldIterator.hasNext()) {
oldRow = oldIterator.next();
} else {
rowFound = false;
log.debug("{}", "row not found - append");
}
coordinatesForBoth.set(DerivedAxis.AXIS_ROWS, newRow.getOrdinal());
if (rowFound) {
if (!cellSet.idsMatch(newCellSet, coordinatesForBoth, newRow.getOrdinal())) {
log.debug("{}", "primary keys do not match - full refresh");
return false;
}
}
if ((newRow != null) && (oldRow != null)) {
List<DerivedMember> oldRowMembers = oldRow.getMembers();
List<DerivedMember> newRowMembers = newRow.getMembers();
if (oldRowMembers.size() != newRowMembers.size()) {
log.debug("{}", "count of row keys do not match - full refresh");
return false;
}
for (int memberIndex = 0; memberIndex < oldRowMembers.size(); memberIndex++) {
String[] oldTokens = oldRowMembers.get(memberIndex).getUniqueName().split("\\]\\.\\[");
String[] newTokens = newRowMembers.get(memberIndex).getUniqueName().split("\\]\\.\\[");
if (oldTokens.length != newTokens.length) {
log.debug("{}", "count of row key tokens do not match - full refresh");
return false;
}
for (int tokenIndex = 1; tokenIndex < oldTokens.length; tokenIndex++) {
if (!oldTokens[tokenIndex].equals(newTokens[tokenIndex])) {
if (!positionMap.containsKey(-1 * tokenIndex)) {
DerivedPosition position = new DerivedPosition(newRow.getMembers(), -1 * tokenIndex, newRow.getContainer());
addCellSetContainerProperty(position, "", null, true);
}
if (!setCellSetContainerValue(newRow, positionMap.get(-1 * tokenIndex).getPosition(), newTokens[tokenIndex].replace("]", ""))) {
// the container cell differs in type, mostly caused by changing pivot table
// full refresh required
log.debug("{}", "column type differs - full refresh");
return false;
}
}
}
}
}
for (DerivedPosition newColumn : newCellSet.getAxes().get(DerivedAxis.AXIS_COLUMNS).getPositions()) {
coordinatesForBoth.set(DerivedAxis.AXIS_COLUMNS, newColumn.getOrdinal());
boolean valueFound = true;
Object newValue = null;
Object oldValue = null;
try {
newValue = newCellSet.getCell(coordinatesForBoth).getValue();
} catch (NullPointerException e1) { // NOSONAR
log.error("{}", e1);
}
if (rowFound) {
try {
oldValue = cellSet.getCell(coordinatesForBoth).getValue();
} catch (NullPointerException e) { // NOSONAR
valueFound = false;
}
} else {
valueFound = false;
}
boolean valueChanged = objectChanged(newValue, oldValue);
boolean exactlyOneValueGiven = oldValue == null && newValue != null || oldValue != null && newValue == null;
if (valueChanged && rowFound && exactlyOneValueGiven) {
return false;
}
if (newRow != null && getContainerProperty(newRow.getOrdinal(), newColumn.getOrdinal()) == null) {
rowFound = false;
valueFound = false;
}
if (!rowFound) {
createRow(newRow);
}
if (newRow == null) {
log.error("{}", "newRow == null");
return false;
}
if (!valueFound && newValue != null && getContainerProperty(newRow.getOrdinal(), newColumn.getOrdinal()) == null) {
addCellSetContainerProperty(newColumn, newValue, null, false);
}
if ((!valueFound || valueChanged) && (newValue != null) && !setCellSetContainerValue(newRow, newColumn, newValue)) {
// the container cell differs in type, mostly caused by changing pivot table
// full refresh required
log.debug("{}", "column type differs - full refresh");
return false;
}
}
}
// delete remaining old rows if new cellset has less rows
while (oldIterator.hasNext()) {
DerivedPosition row = oldIterator.next();
removeItem(row.getOrdinal());
}
cellSet = newCellSet;
return true;
}
public void fillContainer() {
for (DerivedPosition row : cellSet.getAxes().get(DerivedAxis.AXIS_ROWS).getPositions()) {
createRow(row);
for (DerivedPosition column : cellSet.getAxes().get(DerivedAxis.AXIS_COLUMNS).getPositions()) {
createColumn(row, column);
}
}
}
public List<Integer> getCoordinateSystem() {
return coordinateSystem;
}
@SuppressWarnings("serial")
public void addExtras(FilterTable table) {
// add format converter
for (Object propertyId : getContainerPropertyIds()) {
DerivedPosition column = getColumnPosition((Integer) propertyId);
if (column != null) {
PropertyLookup lookup = findColumnProperty(column);
if (lookup != null) {
// add converters
if (lookup.getFormat() != null) {
switch (lookup.getType()) {
case PropertyLookup.DATE:
table.setConverter(column.getOrdinal(), lookup.getDateConverter());
break;
case PropertyLookup.NUMBER:
table.setConverter(column.getOrdinal(), lookup.getNumberConverter());
break;
case PropertyLookup.INTEGER:
table.setConverter(column.getOrdinal(), lookup.getIntegerConverter());
break;
case PropertyLookup.BIGDECIMAL:
table.setConverter(column.getOrdinal(), lookup.getBigDecimalConverter());
break;
case PropertyLookup.STRING:
break;
}
}
// collapse column if applied
table.setColumnCollapsed(column.getOrdinal(), lookup.isCollapseColumn());
// disable filter if of type cellsetimage
if (positionMap.containsKey(column.getOrdinal())
&& (positionMap.get(column.getOrdinal()).getType() == CellSetImage.class || positionMap.get(column.getOrdinal()).getType() == BlobUploadComponent.class)) {
table.setFilterFieldVisible(column.getOrdinal(), false);
}
// add column icons
if (lookup.getColumnIcon() != null) {
table.setColumnIcon(column.getOrdinal(), lookup.getColumnIcon());
}
}
}
}
// add style generator
table.setCellStyleGenerator(new CustomTable.CellStyleGenerator() {
@Override
public String getStyle(CustomTable source, Object itemId, Object propertyId) {
if (source == null)
return null;
CellSetIndexedContainer container = (source instanceof PagedFilterTable) ? (CellSetIndexedContainer) ((PagedFilterTable<?>) source).getContainerDataSource()
.getContainer() : (CellSetIndexedContainer) source.getContainerDataSource();
if (container == null)
return null;
if (propertyId == null && itemId != null) {
// a row style is requested
return container.getRowStyle();
}
if (propertyId == null || itemId == null)
return null;
DerivedPosition column = getColumnPosition((Integer) propertyId);
DerivedPosition row = cellSet.getAxes().get(1).getPositionByOrdinal((Integer) itemId);
if (column == null || row == null)
return null;
PropertyLookup lookup = container.findColumnProperty(column);
if (lookup == null)
return null;
String defaultStyle = lookup.getDefaultStyle();
List<Integer> coordinates = new ArrayList<>(getCoordinateSystem());
if (column.getOrdinal() >= 0 && row.getOrdinal() >= 0) {
coordinates.set(0, column.getOrdinal());
coordinates.set(1, row.getOrdinal());
Object value = null;
try {
value = cellSet.getCell(coordinates).getValue();
if (value != null) {
String style = lookup.getValueStyle(value, (int) itemId);
// for odd rows use the darker -odd style as background-color
if (((int) itemId) % 2 != 0) {
style += "-odd";
}
if (style != null && style.length() > 0) {
log.debug("style for row:" + row.toUnformattedString() + " col:" + column.toUnformattedString() + " " + style + " " + defaultStyle);
return style + " " + defaultStyle;
}
}
} catch (NullPointerException e) { // NOSONAR
log.error("{}", e);
}
}
// for odd rows use the darker -odd style as background-color
if (((int) itemId) % 2 != 0 && defaultStyle != null && defaultStyle.endsWith("rowheader")) {
defaultStyle += "-odd";
}
log.debug("default style for row: {} col: {} {}", row.toUnformattedString(), column.toUnformattedString(), defaultStyle);
return defaultStyle;
}
});
// add tooltips
table.setItemDescriptionGenerator(new AbstractSelect.ItemDescriptionGenerator() {
@Override
public String generateDescription(Component source, Object itemId, Object propertyId) {
if (source == null)
return null;
CellSetIndexedContainer container = (source instanceof PagedFilterTable) ? (CellSetIndexedContainer) ((PagedFilterTable<?>) ((AbstractSelect) source))
.getContainerDataSource().getContainer() : (CellSetIndexedContainer) ((AbstractSelect) source).getContainerDataSource();
if (container == null)
return null;
if (propertyId == null || itemId == null)
return null;
DerivedPosition column = getColumnPosition((Integer) propertyId);
DerivedPosition row = cellSet.getAxes().get(DerivedAxis.AXIS_ROWS).getPositionByOrdinal((Integer) itemId);
if (column == null || row == null)
return null;
PropertyLookup lookup = container.findColumnProperty(column);
if (lookup == null)
return null;
List<Integer> coordinates = new ArrayList<>(getCoordinateSystem());
if (column.getOrdinal() >= 0 && row.getOrdinal() >= 0) {
coordinates.set(DerivedAxis.AXIS_COLUMNS, column.getOrdinal());
coordinates.set(DerivedAxis.AXIS_ROWS, row.getOrdinal());
Object value = null;
try {
value = cellSet.getCell(coordinates).getValue();
if (value != null) {
return lookup.getValueTooltip(value);
}
} catch (NullPointerException e) { // NOSONAR
log.error("{}", e);
}
} else if (column.getOrdinal() < 0 && row.getOrdinal() >= 0) {
Object value = null;
try {
value = getOrdinalCellValue(row.getOrdinal(), column.toUppercaseString());
if (value != null) { // NOSONAR
return lookup.getValueTooltip(value);
}
} catch (NullPointerException e) { // NOSONAR
log.error("{}", e);
}
} else {
return row.toUnformattedString();
// NOSONAR return lookupMap.get(column.toUppercaseString()).getDefaultStyle();
}
return null;
}
});
}
public String getStringValueByOrdinal(int itemId, int ordinal) {
String value = null;
DerivedCell cell = getCell(itemId, null, ordinal);
if (cell != null) {
value = cell.getFormattedValue();
}
return value;
}
public String getStringValueByAggregate(int itemId) {
return getCellTitle(itemId, null);
}
public String getStringValueByProperty(int itemId, String columnName) {
String value = getCellTitle(itemId, columnName);
if (value == null) {
DerivedCell cell = getCell(itemId, columnName, null);
if (cell != null) {
value = cell.getFormattedValue();
}
}
return value;
}
public Object getValueByProperty(int itemId, String columnName) {
String title = getCellTitle(itemId, columnName);
if (title != null) {
return title;
}
DerivedCell cell = getCell(itemId, columnName, null);
if (cell != null) {
if(columnName.contains("__id__")) {
String currentCellName = columnName.replace("__id__", "__validfrom__");
if(getCell(itemId, currentCellName, null) != null) {
return new UUIDHist((String)cell.getValue(), (long)getCell(itemId, currentCellName, null).getValue());
}
}
return cell.getValue();
}
return null;
}
public long getTaskId(int itemId) {
DerivedCell cell = getCell(itemId, "taskid", null);
if (cell != null) {
Object value = cell.getValue();
if (value.getClass().equals(Long.class)) {
return (long) value;
}
}
return -1;
}
public String getProcessId(int itemId) {
DerivedCell cell = getCell(itemId, "processid", null);
if (cell != null) {
Object value = cell.getValue();
if (value.getClass().equals(String.class)) {
return (String) value;
}
}
return null;
}
public String getTaskName(int itemId) {
DerivedCell cell = getCell(itemId, "name", null);
if (cell != null) {
Object value = cell.getValue();
if (value.getClass().equals(String.class)) {
return (String) value;
}
}
return null;
}
public BPMStatus getTaskStatus(int itemId) {
DerivedCell cell = getCell(itemId, "status", null);
if (cell != null) {
Object value = cell.getValue();
return BPMStatus.values()[(int)value];
}
return BPMStatus.Obsolete;
}
public String getCellTitle(int itemId, String columnName) {
String fullTitle = "";
List<Integer> coordinate = new ArrayList<>(getCoordinateSystem());
DerivedPosition rows = cellSet.getAxes().get(DerivedAxis.AXIS_ROWS).getPositionByOrdinal(itemId);
if (rows != null) {
coordinate.set(DerivedAxis.AXIS_ROWS, rows.getOrdinal());
for (DerivedMember member : rows.getMembers()) {
String[] tokens = member.getUniqueName().split("\\]\\.\\[");
if(columnName != null) {
int idx = 1; // index 0 is the main hierarchy name
for(DerivedLevel level : member.getHierarchy().getLevels()) {
if(level.getName().equals(columnName)) {
return tokens[idx].replace("]", "").replace("[", "");
}
idx ++;
}
} else {
for (int token = 0; token < tokens.length; token++) {
if (token > 0) { // full title without the first hierarchy as it is redundant
if (fullTitle.length() > 0) {
fullTitle += " ";
}
fullTitle += tokens[token].replace("]", "").replace("[", "");
}
}
}
}
}
if (columnName != null) {
return null;
} else {
return fullTitle;
}
}
public DerivedCell getCell(int itemId, String columnName, Integer ordinal) {
List<Integer> coordinate = new ArrayList<>(getCoordinateSystem());
DerivedPosition rows = cellSet.getAxes().get(DerivedAxis.AXIS_ROWS).getPositionByOrdinal(itemId);
if (rows != null) {
coordinate.set(DerivedAxis.AXIS_ROWS, rows.getOrdinal());
for (DerivedPosition columns : cellSet.getAxes().get(0).getPositions()) {
if (ordinal != null) {
if (columns.getOrdinal() == ordinal) {
coordinate.set(DerivedAxis.AXIS_COLUMNS, columns.getOrdinal());
return cellSet.getCell(coordinate);
}
} else {
for (DerivedMember colmember : columns.getMembers()) {
String colName = colmember.getCaption().toLowerCase();
if (colName.equals(columnName)) {
coordinate.set(DerivedAxis.AXIS_COLUMNS, columns.getOrdinal());
try {
return cellSet.getCell(coordinate);
} catch (NullPointerException e) { // NOSONAR
log.error("{}", e);
}
}
}
}
}
}
return null;
}
public void setSort(Object source, String columnName, boolean ascending) {
for (DerivedPosition columns : cellSet.getAxes().get(DerivedAxis.AXIS_COLUMNS).getPositions()) {
if (columns.toUppercaseString().equals(columnName)) {
if (source instanceof PagedFilterTable) {
((PagedFilterTable<?>) source).setSortContainerPropertyId(columns.getOrdinal());
if (ascending != ((PagedFilterTable<?>) source).isSortAscending()) {
((PagedFilterTable<?>) source).setSortAscending(ascending);
}
} else {
((FilterTable) source).setSortContainerPropertyId(columns.getOrdinal());
if (ascending != ((FilterTable) source).isSortAscending()) {
((FilterTable) source).setSortAscending(ascending);
}
}
break;
}
}
}
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
for (String lookup : propertyLookupMap.keySet()) {
propertyLookupMap.get(lookup).setLocale(locale);
}
this.fireContainerPropertySetChange();
}
}