use of org.cytoscape.model.internal.column.ColumnData in project cytoscape-impl by cytoscape.
the class CyTableImpl method getMatchingKeys.
@Override
public <T> Collection<T> getMatchingKeys(String columnName, Object value, Class<T> type) {
synchronized (lock) {
final String normalizedColName = normalizeColumnName(columnName);
final VirtualColumn virtColumn = virtualColumnMap.get(normalizedColName);
if (virtColumn != null)
return virtColumn.getMatchingKeys(value, type);
if (normalizedColName.equals(normalizeColumnName(primaryKey))) {
final CyRow matchingRow = rows.get(value);
return matchingRow == null ? Collections.emptyList() : Collections.singletonList(type.cast(value));
}
final ColumnData keyToValueMap = attributes.get(normalizedColName);
return keyToValueMap.getMatchingKeys(value, type);
}
}
use of org.cytoscape.model.internal.column.ColumnData in project cytoscape-impl by cytoscape.
the class CyTableImpl method fireVirtualColumnRowSetEvent.
private void fireVirtualColumnRowSetEvent(CyTableImpl table, Object key, String columnName, Object newValue, Object newRawValue, Set<VirtualColumnInfo> seen) {
// Fire an event for this table
CyRow row = table.getRowNoCreate(key);
if (row == null) {
return;
}
eventHelper.addEventPayload((CyTable) table, new RowSetRecord(row, columnName, newValue, newRawValue), RowsSetEvent.class);
// ...then fire events for all dependents
Set<CyColumn> columnDependents;
synchronized (lock) {
String normalizedColumnName = normalizeColumnName(columnName);
columnDependents = dependents.get(normalizedColumnName);
if (columnDependents == null) {
return;
}
}
for (CyColumn dependent : columnDependents) {
VirtualColumnInfo info = dependent.getVirtualColumnInfo();
if (seen.contains(info)) {
continue;
}
seen.add(info);
CyTableImpl table2 = (CyTableImpl) dependent.getTable();
String targetJoinKey = info.getTargetJoinKey();
if (targetJoinKey.equals(table2.getPrimaryKey().getName())) {
fireVirtualColumnRowSetEvent(table2, key, dependent.getName(), newValue, newRawValue, seen);
} else {
String normalizedTargetJoinKey = table2.normalizeColumnName(targetJoinKey);
ColumnData keyToValueMap = table2.attributes.get(normalizedTargetJoinKey);
if (keyToValueMap != null) {
for (Object key2 : keyToValueMap.keySet()) {
if (keyToValueMap.get(key2).equals(key)) {
fireVirtualColumnRowSetEvent(table2, key2, dependent.getName(), newValue, newRawValue, seen);
}
}
}
}
}
}
use of org.cytoscape.model.internal.column.ColumnData in project cytoscape-impl by cytoscape.
the class CyTableImpl method updateColumnName.
void updateColumnName(final String oldColumnName, final String newColumnName) {
synchronized (lock) {
if (currentlyActiveAttributes.remove(oldColumnName)) {
currentlyActiveAttributes.add(newColumnName);
}
String normalizedOldColName = normalizeColumnName(oldColumnName);
String normalizedNewColName = normalizeColumnName(newColumnName);
final ColumnData keyValuePairs = attributes.get(normalizedOldColName);
if (keyValuePairs != null) {
attributes.remove(normalizedOldColName);
attributes.put(normalizedNewColName, keyValuePairs);
}
final CyColumn column = types.get(normalizedOldColName);
types.remove(normalizedOldColName);
types.put(normalizedNewColName, column);
final VirtualColumn virtualColumn = virtualColumnMap.get(normalizedOldColName);
if (virtualColumn != null) {
virtualColumnMap.remove(normalizedOldColName);
virtualColumnMap.put(normalizedNewColName, virtualColumn);
}
final Set<CyColumn> columnDependents = dependents.get(normalizedOldColName);
if (columnDependents != null) {
dependents.remove(normalizedOldColName);
dependents.put(normalizedNewColName, columnDependents);
}
}
eventHelper.fireEvent(new ColumnNameChangedEvent(this, oldColumnName, newColumnName));
}
use of org.cytoscape.model.internal.column.ColumnData in project cytoscape-impl by cytoscape.
the class CyTableImpl method getMatchingRows.
@Override
public Collection<CyRow> getMatchingRows(final String columnName, final Object value) {
synchronized (lock) {
final String normalizedColName = normalizeColumnName(columnName);
final VirtualColumn virtColumn = virtualColumnMap.get(normalizedColName);
if (virtColumn != null)
return virtColumn.getMatchingRows(value);
if (normalizedColName.equals(normalizeColumnName(primaryKey))) {
final CyRow matchingRow = rows.get(value);
return matchingRow == null ? Collections.emptyList() : Collections.singletonList(matchingRow);
}
final ColumnData keyToValueMap = attributes.get(normalizedColName);
return keyToValueMap.getMatchingRows(rows, value);
}
}
use of org.cytoscape.model.internal.column.ColumnData in project cytoscape-impl by cytoscape.
the class CyTableImpl method setListX.
private final void setListX(final Object key, final String columnName, final Object value) {
Object newValue;
final Object rawValue;
synchronized (lock) {
final String normalizedColName = normalizeColumnName(columnName);
final CyColumn column = types.get(normalizedColName);
CyRow row = rows.get(key);
final Class<?> type = column.getListElementType();
if (value instanceof CyListImpl) {
rawValue = value;
} else if (value instanceof List) {
final List list = (List) value;
if (!list.isEmpty())
checkType(list.get(0));
List<?> listData = columnFactory.createList(type, list);
rawValue = new CyListImpl(type, listData, eventHelper, row, column, this);
} else if (!(value instanceof Equation)) {
throw new IllegalArgumentException("value is a " + value.getClass().getName() + " and not a List for column '" + columnName + "'.");
} else if (!EqnSupport.listEquationIsCompatible((Equation) value, type)) {
throw new IllegalArgumentException("value is not a List equation of a compatible type for column '" + columnName + "'.");
} else {
rawValue = value;
}
final VirtualColumn virtColumn = virtualColumnMap.get(normalizedColName);
if (virtColumn != null) {
virtColumn.setValue(key, rawValue);
newValue = virtColumn.getListValue(key);
} else {
ColumnData keyToValueMap = attributes.get(normalizedColName);
// TODO this is an implicit addRow - not sure if we want to refactor this or not
keyToValueMap.put(key, rawValue);
if (rawValue instanceof Equation) {
final StringBuilder errorMsg = new StringBuilder();
newValue = EqnSupport.evalEquation((Equation) rawValue, suid, interpreter, currentlyActiveAttributes, columnName, errorMsg, this);
lastInternalError = errorMsg.toString();
} else {
newValue = rawValue;
}
}
}
if (fireEvents)
eventHelper.addEventPayload((CyTable) this, new RowSetRecord(getRow(key), columnName, newValue, rawValue), RowsSetEvent.class);
}
Aggregations