Search in sources :

Example 6 with VirtualColumnInfo

use of org.cytoscape.model.VirtualColumnInfo in project cytoscape-impl by cytoscape.

the class RowsSetViewUpdater method updateView.

private final void updateView(final RowsSetEvent e) {
    boolean refreshView = false;
    boolean refreshOtherViews = false;
    // Acquire services once to avoid performance overhead of repeated lookup
    final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
    final CyColumnIdentifierFactory columnIdentifierFactory = serviceRegistrar.getService(CyColumnIdentifierFactory.class);
    final CyNetworkViewManager networkViewManager = serviceRegistrar.getService(CyNetworkViewManager.class);
    final VisualMappingManager visualMappingManager = serviceRegistrar.getService(VisualMappingManager.class);
    final RenderingEngine<CyNetwork> renderer = applicationManager.getCurrentRenderingEngine();
    final CyNetwork network = applicationManager.getCurrentNetwork();
    if (network == null)
        return;
    // 1: Update current network view
    final Collection<CyNetworkView> views = networkViewManager.getNetworkViews(network);
    CyNetworkView networkView = null;
    if (views.isEmpty())
        return;
    else
        networkView = views.iterator().next();
    final VisualStyle vs = visualMappingManager.getVisualStyle(networkView);
    Map<CyRow, View<? extends CyIdentifiable>> rowViewMap = tracker.getRowViewMap(networkView);
    for (final RowSetRecord record : e.getPayloadCollection()) {
        final CyRow row = record.getRow();
        final String columnName = record.getColumn();
        final CyColumn column = row.getTable().getColumn(columnName);
        if (column == null)
            continue;
        final VirtualColumnInfo virtualColInfo = column.getVirtualColumnInfo();
        final boolean virtual = virtualColInfo.isVirtual();
        final View<? extends CyIdentifiable> v = rowViewMap.get(row);
        if (v == null)
            continue;
        if (v.getModel() instanceof CyNode) {
            final CyNode node = (CyNode) v.getModel();
            if (network.containsNode(node) && isStyleAffected(vs, columnName, renderer, columnIdentifierFactory)) {
                vs.apply(row, v);
                refreshView = false;
            }
        } else if (v.getModel() instanceof CyEdge) {
            final CyEdge edge = (CyEdge) v.getModel();
            if (network.containsEdge(edge) && isStyleAffected(vs, columnName, renderer, columnIdentifierFactory)) {
                vs.apply(row, v);
                refreshView = false;
            }
        }
        // If virtual, it may be used in other networks.
        if (refreshView && virtual)
            refreshOtherViews = true;
    // if (refreshView)
    // vs.apply(record.getRow(), (View<? extends CyIdentifiable>) v);
    }
    if (refreshView) {
        vs.apply(networkView);
        networkView.updateView();
        if (refreshOtherViews) {
            // Check other views. If update is required, set the flag.
            for (final CyNetworkView view : networkViewManager.getNetworkViewSet()) {
                if (view == networkView)
                    continue;
                final VisualStyle style = visualMappingManager.getVisualStyle(view);
                if (style == vs) {
                    // Same style is in use. Need to apply.
                    netViewMediator.setUpdateFlag(view);
                }
            }
        }
    }
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyColumnIdentifierFactory(org.cytoscape.view.presentation.property.values.CyColumnIdentifierFactory) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 7 with VirtualColumnInfo

use of org.cytoscape.model.VirtualColumnInfo in project cytoscape-impl by cytoscape.

the class AttributeValueUtil method handleAttribute.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected ParseState handleAttribute(Attributes atts) throws SAXParseException {
    ParseState parseState = ParseState.NONE;
    final String name = atts.getValue("name");
    String type = atts.getValue("type");
    String cyType = atts.getValue("cy:type");
    if ("has_nested_network".equals(name))
        type = ObjectType.BOOLEAN.getXgmmlValue();
    final boolean isEquation = ObjectTypeMap.fromXGMMLBoolean(atts.getValue("cy:equation"));
    final boolean isHidden = ObjectTypeMap.fromXGMMLBoolean(atts.getValue("cy:hidden"));
    final CyIdentifiable curElement = manager.getCurrentElement();
    CyNetwork curNet = manager.getCurrentNetwork();
    // under the group subgraph, but the edge will be created on the root-network only,
    if (curElement instanceof CyNode || curElement instanceof CyEdge) {
        boolean containsElement = (curElement instanceof CyNode && curNet.containsNode((CyNode) curElement));
        containsElement |= (curElement instanceof CyEdge && curNet.containsEdge((CyEdge) curElement));
        // So if the current network does not contain this element, the CyRootNetwork should contain it
        if (!containsElement)
            curNet = manager.getRootNetwork();
    }
    CyRow row = null;
    if (isHidden) {
        row = curNet.getRow(curElement, CyNetwork.HIDDEN_ATTRS);
    } else {
        // Network name must be local, right? What about other network attributes?
        if (CyNetwork.SELECTED.equals(name) || (curElement instanceof CyNetwork))
            row = curNet.getRow(curElement, CyNetwork.LOCAL_ATTRS);
        else
            // Will be created in the shared table
            row = curNet.getRow(curElement, CyNetwork.DEFAULT_ATTRS);
    }
    CyTable table = row.getTable();
    CyColumn column = table.getColumn(name);
    if (column != null) {
        // Check if it's a virtual column
        // It's necessary because the source row may not exist yet, which would throw an exception
        // when the value is set. Doing this forces the creation of the source row.
        final VirtualColumnInfo info = column.getVirtualColumnInfo();
        if (info.isVirtual()) {
            final CyTable srcTable = info.getSourceTable();
            final CyColumn srcColumn = srcTable.getColumn(info.getSourceColumn());
            final Class<?> jkColType = table.getColumn(info.getTargetJoinKey()).getType();
            final Object jkValue = row.get(info.getTargetJoinKey(), jkColType);
            final Collection<CyRow> srcRowList = srcTable.getMatchingRows(info.getSourceJoinKey(), jkValue);
            final CyRow srcRow;
            if (srcRowList == null || srcRowList.isEmpty()) {
                if (info.getTargetJoinKey().equals(CyIdentifiable.SUID)) {
                    // Try to create the row
                    srcRow = srcTable.getRow(jkValue);
                } else {
                    logger.error("Unable to import virtual column \"" + name + "\": The source table \"" + srcTable.getTitle() + "\" does not have any matching rows for join key \"" + info.getSourceJoinKey() + "=" + jkValue + "\".");
                    return parseState;
                }
            } else {
                srcRow = srcRowList.iterator().next();
            }
            // Use the source table instead
            table = srcTable;
            column = srcColumn;
            row = srcRow;
        }
    } else {
        // Also check if the column exists in a network's local table
        final Class<? extends CyIdentifiable> tableType;
        if (curElement instanceof CyNode)
            tableType = CyNode.class;
        else if (curElement instanceof CyEdge)
            tableType = CyEdge.class;
        else
            tableType = CyNetwork.class;
        if (existsInLocalTable(name, tableType, manager.getRootNetwork()))
            row = curNet.getRow(curElement, CyNetwork.LOCAL_ATTRS);
    }
    Object value = null;
    final ObjectType objType = typeMap.fromXgmml(cyType, type);
    if (isEquation) {
        // It is an equation...
        String formula = atts.getValue("value");
        if (name != null && formula != null) {
            manager.addEquationString(row, name, formula);
        }
    } else {
        // Regular attribute value...
        value = getTypedAttributeValue(objType, atts, name);
    }
    switch(objType) {
        case BOOLEAN:
            if (name != null)
                setAttribute(row, name, Boolean.class, (Boolean) value);
            break;
        case REAL:
            if (name != null) {
                if (SUIDUpdater.isUpdatable(name))
                    setAttribute(row, name, Long.class, (Long) value);
                else
                    setAttribute(row, name, Double.class, (Double) value);
            }
            break;
        case INTEGER:
            if (name != null) {
                if (SUIDUpdater.isUpdatable(name))
                    setAttribute(row, name, Long.class, (Long) value);
                else
                    setAttribute(row, name, Integer.class, (Integer) value);
            }
            break;
        case LONG:
            if (name != null)
                setAttribute(row, name, Long.class, (Long) value);
            break;
        case STRING:
            if (name != null)
                setAttribute(row, name, String.class, (String) value);
            break;
        // must make sure to clear out any existing values before we parse.
        case LIST:
            manager.currentAttributeID = name;
            manager.setCurrentRow(row);
            if (column != null && List.class.isAssignableFrom(column.getType()))
                row.set(name, null);
            if (column == null) {
                // Since Cytoscape v3.3
                final String elementType = atts.getValue("cy:elementType");
                if (elementType != null) {
                    final ObjectType elementObjType = typeMap.fromXgmml(elementType, null);
                    final Class<?> clazz = typeMap.getClass(elementObjType, name);
                    table.createListColumn(name, clazz, false, new ArrayList());
                    column = row.getTable().getColumn(name);
                    manager.listAttrHolder = new ArrayList<Object>();
                }
            }
            return ParseState.LIST_ATT;
    }
    return parseState;
}
Also used : CyColumn(org.cytoscape.model.CyColumn) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) ParseState(org.cytoscape.io.internal.read.xgmml.ParseState) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) CyTable(org.cytoscape.model.CyTable) ObjectType(org.cytoscape.io.internal.util.xgmml.ObjectType) CyNode(org.cytoscape.model.CyNode) ArrayList(java.util.ArrayList) List(java.util.List) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 8 with VirtualColumnInfo

use of org.cytoscape.model.VirtualColumnInfo in project cytoscape-impl by cytoscape.

the class CyTableImpl method removeAllVirtColumns.

// Warning: This method is only to be used by CyTableManagerImpl!!!  That's also the reason
// why no ColumnDeletedEvent events are being fired by it!  Also this deletes
// (intentionally!) immutable columns!
void removeAllVirtColumns() {
    synchronized (lock) {
        if (getDependentCount() > 0)
            return;
        for (final String columnName : virtualColumnMap.keySet()) {
            final CyColumn column = types.get(columnName);
            types.remove(columnName);
            colList.remove(column);
            VirtualColumnInfo info = column.getVirtualColumnInfo();
            ((CyTableImpl) info.getSourceTable()).removeDependent(info.getSourceColumn(), column);
        }
        virtualColumnMap.clear();
    }
}
Also used : CyColumn(org.cytoscape.model.CyColumn) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo)

Example 9 with VirtualColumnInfo

use of org.cytoscape.model.VirtualColumnInfo in project cytoscape-impl by cytoscape.

the class CyTableImpl method deleteColumn.

@Override
public void deleteColumn(final String columnName) {
    synchronized (lock) {
        if (columnName == null)
            throw new NullPointerException("\"columnName\" must not be null.");
        final String normalizedColName = normalizeColumnName(columnName);
        final CyColumn column = types.get(normalizedColName);
        if (column == null)
            return;
        if (column.isImmutable())
            throw new IllegalArgumentException("cannot delete immutable column \"" + columnName + "\".");
        final VirtualColumn virtColumn = virtualColumnMap.get(normalizedColName);
        if (attributes.containsKey(normalizedColName) || virtColumn != null) {
            if (virtColumn != null) {
                final CyColumn cyColumn = types.get(normalizedColName);
                virtualColumnMap.remove(normalizedColName);
                attributes.remove(normalizedColName);
                types.remove(normalizedColName);
                colList.remove(cyColumn);
                VirtualColumnInfo info = cyColumn.getVirtualColumnInfo();
                ((CyTableImpl) info.getSourceTable()).removeDependent(info.getSourceColumn(), cyColumn);
            } else {
                attributes.remove(normalizedColName);
                colList.remove(types.get(normalizedColName));
                types.remove(normalizedColName);
            }
        }
    }
    // This event must be synchronous!
    eventHelper.fireEvent(new ColumnDeletedEvent(this, columnName));
}
Also used : CyColumn(org.cytoscape.model.CyColumn) ColumnDeletedEvent(org.cytoscape.model.events.ColumnDeletedEvent) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo)

Example 10 with VirtualColumnInfo

use of org.cytoscape.model.VirtualColumnInfo in project cytoscape-impl by cytoscape.

the class CloneNetworkTask method cloneRow.

private void cloneRow(final CyNetwork newNet, final Class<? extends CyIdentifiable> tableType, final CyRow from, final CyRow to) {
    final CyRootNetwork newRoot = rootNetMgr.getRootNetwork(newNet);
    Map<String, CyTable> rootTables = netTableMgr.getTables(newRoot, tableType);
    for (final CyColumn col : to.getTable().getColumns()) {
        final String name = col.getName();
        if (name.equals(CyIdentifiable.SUID))
            continue;
        final VirtualColumnInfo info = col.getVirtualColumnInfo();
        // then we have to set the value, because the rows of the new root table may not have been copied yet
        if (!info.isVirtual() || rootTables.containsValue(info.getSourceTable()))
            to.set(name, from.getRaw(name));
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Aggregations

VirtualColumnInfo (org.cytoscape.model.VirtualColumnInfo)13 CyColumn (org.cytoscape.model.CyColumn)11 CyTable (org.cytoscape.model.CyTable)5 CyRow (org.cytoscape.model.CyRow)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CyEdge (org.cytoscape.model.CyEdge)2 CyIdentifiable (org.cytoscape.model.CyIdentifiable)2 CyNetwork (org.cytoscape.model.CyNetwork)2 CyNode (org.cytoscape.model.CyNode)2 ColumnCreatedEvent (org.cytoscape.model.events.ColumnCreatedEvent)2 RowSetRecord (org.cytoscape.model.events.RowSetRecord)2 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)2 CyApplicationManager (org.cytoscape.application.CyApplicationManager)1 ParseState (org.cytoscape.io.internal.read.xgmml.ParseState)1 CyTables (org.cytoscape.io.internal.util.cytables.model.CyTables)1 VirtualColumn (org.cytoscape.io.internal.util.cytables.model.VirtualColumn)1 VirtualColumns (org.cytoscape.io.internal.util.cytables.model.VirtualColumns)1 ObjectType (org.cytoscape.io.internal.util.xgmml.ObjectType)1 CyTableMetadata (org.cytoscape.model.CyTableMetadata)1