Search in sources :

Example 1 with ColumnData

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);
    }
}
Also used : ColumnData(org.cytoscape.model.internal.column.ColumnData) CyRow(org.cytoscape.model.CyRow)

Example 2 with ColumnData

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);
                    }
                }
            }
        }
    }
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyColumn(org.cytoscape.model.CyColumn) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo) ColumnData(org.cytoscape.model.internal.column.ColumnData) CyRow(org.cytoscape.model.CyRow)

Example 3 with ColumnData

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));
}
Also used : ColumnNameChangedEvent(org.cytoscape.model.events.ColumnNameChangedEvent) CyColumn(org.cytoscape.model.CyColumn) ColumnData(org.cytoscape.model.internal.column.ColumnData)

Example 4 with ColumnData

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);
    }
}
Also used : ColumnData(org.cytoscape.model.internal.column.ColumnData) CyRow(org.cytoscape.model.CyRow)

Example 5 with ColumnData

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);
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyColumn(org.cytoscape.model.CyColumn) Equation(org.cytoscape.equations.Equation) ColumnData(org.cytoscape.model.internal.column.ColumnData) CyRow(org.cytoscape.model.CyRow) RowsSetEvent(org.cytoscape.model.events.RowsSetEvent) CyTable(org.cytoscape.model.CyTable) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ColumnData (org.cytoscape.model.internal.column.ColumnData)12 CyRow (org.cytoscape.model.CyRow)6 CyColumn (org.cytoscape.model.CyColumn)5 RowSetRecord (org.cytoscape.model.events.RowSetRecord)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Equation (org.cytoscape.equations.Equation)2 CyTable (org.cytoscape.model.CyTable)2 RowsSetEvent (org.cytoscape.model.events.RowsSetEvent)2 IdentityHashMap (java.util.IdentityHashMap)1 List (java.util.List)1 Set (java.util.Set)1 SavePolicy (org.cytoscape.model.SavePolicy)1 VirtualColumnInfo (org.cytoscape.model.VirtualColumnInfo)1 ColumnNameChangedEvent (org.cytoscape.model.events.ColumnNameChangedEvent)1 RowsDeletedEvent (org.cytoscape.model.events.RowsDeletedEvent)1