Search in sources :

Example 11 with RowSetRecord

use of org.cytoscape.model.events.RowSetRecord 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 12 with RowSetRecord

use of org.cytoscape.model.events.RowSetRecord in project clusterMaker2 by RBVI.

the class TreeView method handleEvent.

public void handleEvent(RowsSetEvent e) {
    if (!e.containsColumn(CyNetwork.SELECTED))
        return;
    if (ignoreSelection) {
        return;
    }
    // System.out.println("Got selection event");
    CyTable table = e.getSource();
    CyNetwork net = networkTableManager.getNetworkForTable(table);
    Class<?> type = networkTableManager.getTableType(table);
    if (pendingSelections == null)
        pendingSelections = new HashSet<CyIdentifiable>();
    if (type.equals(CyNode.class)) {
        // if (dataModel.isSymmetrical()) return;
        for (RowSetRecord record : e.getColumnRecords(CyNetwork.SELECTED)) {
            Long nodeSUID = record.getRow().get(CyIdentifiable.SUID, Long.class);
            CyNode node = net.getNode(nodeSUID);
            if ((Boolean) record.getValue()) {
                if (node != null)
                    pendingSelections.add(node);
            } else if (pendingSelections.contains(node)) {
                pendingSelections.remove(node);
            }
        }
    /*
			List<CyNode> selectedNodes = CyTableUtil.getNodesInState(net, CyNetwork.SELECTED, true);
			setNodeSelection(selectedNodes, true);
			*/
    } else if (type.equals(CyEdge.class) && dataModel.isSymmetrical()) {
        // System.out.println("Edge selection");
        for (RowSetRecord record : e.getColumnRecords(CyNetwork.SELECTED)) {
            Long edgeSUID = record.getRow().get(CyIdentifiable.SUID, Long.class);
            CyEdge edge = net.getEdge(edgeSUID);
            if ((Boolean) record.getValue()) {
                if (edge != null)
                    pendingSelections.add(edge);
            } else if (pendingSelections.contains(edge)) {
                pendingSelections.remove(edge);
            }
        }
    // List<CyEdge> selectedEdges = CyTableUtil.getEdgesInState(net, CyNetwork.SELECTED, true);
    // setEdgeSelection(selectedEdges, true);
    }
    if (selectionTimer == null) {
        selectionTimer = new Timer(200, new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                // System.out.println("Selection Timer fired");
                List<CyEdge> edges = new ArrayList<CyEdge>();
                List<CyNode> nodes = new ArrayList<CyNode>();
                for (CyIdentifiable id : pendingSelections) {
                    if (CyEdge.class.isAssignableFrom(id.getClass())) {
                        edges.add((CyEdge) id);
                    } else if (CyNode.class.isAssignableFrom(id.getClass())) {
                        nodes.add((CyNode) id);
                    }
                }
                if (edges.size() > 0) {
                    setEdgeSelection(edges, true);
                // System.out.println("Selecting "+edges.size()+" edges");
                } else {
                    setNodeSelection(nodes, true);
                // System.out.println("Selecting "+nodes.size()+" nodes");
                }
            // pendingSelections.clear();
            }
        });
        selectionTimer.setCoalesce(true);
        selectionTimer.setRepeats(false);
        selectionTimer.start();
    } else if (selectionTimer.isRunning()) {
    // Don't do anything
    } else {
        selectionTimer.restart();
    }
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) CyTable(org.cytoscape.model.CyTable) Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) CyNode(org.cytoscape.model.CyNode) HashSet(java.util.HashSet) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 13 with RowSetRecord

use of org.cytoscape.model.events.RowSetRecord in project clusterMaker2 by RBVI.

the class NetworkSelectionLinker method handleEvent.

public void handleEvent(RowsSetEvent e) {
    if (!e.containsColumn(CyNetwork.SELECTED) || ignoreSelection)
        return;
    // System.out.println("Select");
    CyNetworkView currentNetworkView = clusterManager.getNetworkView();
    ignoreSelection = true;
    Map<CyNetwork, Boolean> stateMap = new HashMap<CyNetwork, Boolean>();
    for (CySubNetwork subNetwork : rootNetwork.getSubNetworkList()) {
        if (e.getSource().equals(subNetwork.getTable(CyNode.class, CyNetwork.LOCAL_ATTRS))) {
            for (RowSetRecord record : e.getColumnRecords(CyNetwork.SELECTED)) {
                Long suid = record.getRow().get(CyIdentifiable.SUID, Long.class);
                Boolean value = (Boolean) record.getValue();
                for (CySubNetwork sub2 : rootNetwork.getSubNetworkList()) {
                    if (subNetwork.equals(sub2) || sub2.getDefaultNodeTable().getRow(suid) == null)
                        continue;
                    // System.out.println("Selecting row "+suid);
                    sub2.getDefaultNodeTable().getRow(suid).set(CyNetwork.SELECTED, value);
                }
            }
        }
        if (viewManager.viewExists(subNetwork)) {
            for (CyNetworkView view : viewManager.getNetworkViews(subNetwork)) {
                if (!view.equals(currentNetworkView)) {
                    view.updateView();
                }
            }
        }
    }
    eventHelper.flushPayloadEvents();
    ignoreSelection = false;
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) HashMap(java.util.HashMap) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 14 with RowSetRecord

use of org.cytoscape.model.events.RowSetRecord in project cytoscape-api by cytoscape.

the class AbstractViewUpdaterTest method testHandleEvent.

@Test
public void testHandleEvent() {
    rows = new ArrayList<RowSetRecord>();
    RowSetRecord rec1 = new RowSetRecord(row, "test", value, rawValue);
    rows.add(rec1);
    RowsSetEvent event = new RowsSetEvent(source, rows);
    updater.handleEvent(event);
    verify(row, times(0)).getAllValues();
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) RowsSetEvent(org.cytoscape.model.events.RowsSetEvent) Test(org.junit.Test)

Example 15 with RowSetRecord

use of org.cytoscape.model.events.RowSetRecord in project cytoscape-impl by cytoscape.

the class CyTableImpl method unSetX.

private void unSetX(final Object key, final String columnName) {
    synchronized (lock) {
        final String normalizedColName = normalizeColumnName(columnName);
        final VirtualColumn virtColumn = virtualColumnMap.get(normalizedColName);
        if (virtColumn != null)
            virtColumn.setValue(key, null);
        else {
            final ColumnData keyToValueMap = attributes.get(normalizedColName);
            if (!types.containsKey(normalizedColName) || keyToValueMap == null)
                throw new IllegalArgumentException("column: '" + columnName + "' does not yet exist.");
            final Object value = keyToValueMap.get(key);
            if (value == null)
                return;
            keyToValueMap.remove(key);
        }
    }
    if (fireEvents)
        eventHelper.addEventPayload((CyTable) this, new RowSetRecord(getRow(key), columnName, null, null), RowsSetEvent.class);
}
Also used : CyTable(org.cytoscape.model.CyTable) RowSetRecord(org.cytoscape.model.events.RowSetRecord) ColumnData(org.cytoscape.model.internal.column.ColumnData) RowsSetEvent(org.cytoscape.model.events.RowsSetEvent)

Aggregations

RowSetRecord (org.cytoscape.model.events.RowSetRecord)26 CyTable (org.cytoscape.model.CyTable)11 CyNetwork (org.cytoscape.model.CyNetwork)8 ArrayList (java.util.ArrayList)6 CyRow (org.cytoscape.model.CyRow)6 RowsSetEvent (org.cytoscape.model.events.RowsSetEvent)6 Test (org.junit.Test)6 CyNode (org.cytoscape.model.CyNode)5 CyNetworkView (org.cytoscape.view.model.CyNetworkView)5 CyColumn (org.cytoscape.model.CyColumn)4 CyIdentifiable (org.cytoscape.model.CyIdentifiable)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Equation (org.cytoscape.equations.Equation)3 CyEdge (org.cytoscape.model.CyEdge)3 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)3 ColumnData (org.cytoscape.model.internal.column.ColumnData)3 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)3 List (java.util.List)2 CyApplicationManager (org.cytoscape.application.CyApplicationManager)2