Search in sources :

Example 51 with CyGroup

use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.

the class NodeChangeListener method updateNodeLocation.

private void updateNodeLocation(CyNetworkView networkView, View<CyNode> nodeView) {
    // double groupY = nodeView.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION);
    if (nodeView == null)
        return;
    CyNode node = nodeView.getModel();
    CyGroup group = node2GroupMap.get(networkView).get(node);
    if (group == null) {
        // System.out.println("Lost group: "+node);
        group = getGroupForNode(node, networkView);
        if (group == null)
            return;
        else
            node2GroupMap.get(networkView).put(node, group);
    }
    if (cyStyleManager == null)
        cyStyleManager = cyGroupManager.getService(VisualMappingManager.class);
    boolean lastIgnoreChanges = ignoreChanges;
    ignoreChanges = true;
    ViewUtils.styleCompoundNode(group, networkView, cyGroupManager, cyStyleManager, cyGroupSettings.getGroupViewType(group));
    final CyEventHelper cyEventHelper = cyGroupManager.getService(CyEventHelper.class);
    cyEventHelper.flushPayloadEvents();
    // OK, a little trickery here.  If our group is itself a node in another group, we
    // won't restyle appropriately because we were ignoring changes.  Deal with it here,
    // but only if our group is also a node in another group
    CyGroup g = getGroupForNode(group.getGroupNode(), networkView);
    if (g != null) {
        View<CyNode> nv = networkView.getNodeView(group.getGroupNode());
        if (nv != null) {
            updateNodeLocation(networkView, nv);
            // ViewUtils.styleCompoundNode(g, networkView, cyGroupManager, cyStyleManager,
            // cyGroupSettings.getGroupViewType(group));
            cyEventHelper.flushPayloadEvents();
        }
    }
    ignoreChanges = lastIgnoreChanges;
}
Also used : CyGroup(org.cytoscape.group.CyGroup) CyEventHelper(org.cytoscape.event.CyEventHelper) CyNode(org.cytoscape.model.CyNode)

Example 52 with CyGroup

use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.

the class NodeChangeListener method updateGroupLocation.

private void updateGroupLocation(CyNetworkView networkView, View<CyNode> nodeView) {
    double groupX = nodeView.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION);
    double groupY = nodeView.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION);
    CyGroup group = cyGroupManager.getGroup(nodeView.getModel(), networkView.getModel());
    if (group == null)
        return;
    // System.out.println("Updating group "+group+" location");
    Dimension lastPosition = ViewUtils.getLocation(networkView.getModel(), group);
    double xOffset = lastPosition.getWidth() - groupX;
    double yOffset = lastPosition.getHeight() - groupY;
    // System.out.println("Group node offset = "+xOffset+","+yOffset);
    List<View<CyNode>> groupNodeList = new ArrayList<>();
    boolean lastIgnoreChanges = ignoreChanges;
    ignoreChanges = true;
    // OK, move all of our nodes
    for (CyNode node : group.getNodeList()) {
        View<CyNode> nv = networkView.getNodeView(node);
        if (nv == null)
            continue;
        double x = nv.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION);
        double y = nv.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION);
        // System.out.println("Node location = "+x+","+y);
        Dimension d = new Dimension();
        // System.out.println("Moving node to "+(x-xOffset)+","+(y-yOffset));
        d.setSize(x - xOffset, y - yOffset);
        ViewUtils.moveNode(networkView, node, d);
        if (cyGroupManager.isGroup(node, networkView.getModel()))
            groupNodeList.add(nv);
    }
    final CyEventHelper cyEventHelper = cyGroupManager.getService(CyEventHelper.class);
    cyEventHelper.flushPayloadEvents();
    ViewUtils.updateGroupLocation(networkView.getModel(), group, groupX, groupY);
    if (groupNodeList.size() > 0) {
        for (View<CyNode> nv : groupNodeList) {
            updateGroupLocation(networkView, nv);
        }
    }
    ignoreChanges = lastIgnoreChanges;
    cyEventHelper.flushPayloadEvents();
}
Also used : CyGroup(org.cytoscape.group.CyGroup) CyEventHelper(org.cytoscape.event.CyEventHelper) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) Dimension(java.awt.Dimension) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 53 with CyGroup

use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.

the class NodeChangeListener method removeGroup.

public void removeGroup(CyGroup group, CyNetworkView networkView) {
    if (groupMap.containsKey(networkView)) {
        Set<CyNode> groups = groupMap.get(networkView);
        groups.remove(group.getGroupNode());
        if (groups.size() == 0)
            groupMap.remove(networkView);
    }
    Map<CyNode, CyGroup> node2Group = null;
    if (node2GroupMap.containsKey(networkView))
        node2Group = node2GroupMap.get(networkView);
    if (node2Group != null)
        node2Group.remove(group.getGroupNode());
    if (nodeMap.containsKey(networkView)) {
        Set<CyNode> nodes = nodeMap.get(networkView);
        for (CyNode node : group.getNodeList()) {
            nodes.remove(node);
            if (node2Group != null)
                node2Group.remove(node);
        }
        if (nodes.size() == 0)
            nodeMap.remove(networkView);
    }
}
Also used : CyGroup(org.cytoscape.group.CyGroup) CyNode(org.cytoscape.model.CyNode)

Example 54 with CyGroup

use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.

the class GroupUtil method getExpandedGroups.

public List<CyNode> getExpandedGroups(final CyNetwork network) {
    // Get all of our groups in this network
    final CyGroupManager groupMgr = serviceRegistrar.getService(CyGroupManager.class);
    Set<CyGroup> groupSet = groupMgr.getGroupSet(network);
    // For each group see if it's expanded, but present
    List<CyNode> groupNodes = new ArrayList<>();
    for (CyGroup group : groupSet) {
        if (!group.isCollapsed(network)) {
            if (network.containsNode(group.getGroupNode())) {
                // We're expanded, but present in the network.  Remove ourselves
                groupNodes.add(group.getGroupNode());
            }
        }
    }
    return groupNodes;
}
Also used : CyGroup(org.cytoscape.group.CyGroup) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyGroupManager(org.cytoscape.group.CyGroupManager)

Example 55 with CyGroup

use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.

the class GroupUtil method createGroups.

private void createGroups(final CySubNetwork net, final Set<CyNetworkView> viewSet, final Set<CyNode> collapsedChildren) {
    // Look for possible meta-nodes by inspecting the groups metadata in the network's hidden table
    final CyRootNetwork rootNet = net.getRootNetwork();
    final List<CyNode> nodes = net.getNodeList();
    final CyGroupFactory groupFactory = serviceRegistrar.getService(CyGroupFactory.class);
    // Iterate each node and check if they have network pointers
    for (final CyNode n : nodes) {
        final CyNetwork netPointer = n.getNetworkPointer();
        if (netPointer == null)
            continue;
        // Retrieve the internal nodes and edges
        final CyRow dnRow = net.getRow(n, CyNetwork.DEFAULT_ATTRS);
        final CyRow hnRow = net.getRow(n, CyNetwork.HIDDEN_ATTRS);
        final CyRow snRow = netPointer.getRow(netPointer, CyNetwork.HIDDEN_ATTRS);
        if (!dnRow.isSet(GROUP_STATE_ATTRIBUTE) && !hnRow.isSet(GROUP_STATE_ATTRIBUTE) && !hnRow.isSet(GROUP_ATTRIBUTE))
            continue;
        // Check for nested groups recursively
        createGroups((CySubNetwork) netPointer, null, collapsedChildren);
        boolean collapsed = false;
        boolean nodeShown = false;
        boolean cy2group = false;
        if (hnRow.isSet(GROUP_STATE_ATTRIBUTE)) {
            // 2.x metadata
            Integer grState = hnRow.get(GROUP_STATE_ATTRIBUTE, Integer.class);
            cy2group = true;
            if (grState.intValue() == 2)
                collapsed = true;
        } else if (dnRow.isSet(GROUP_STATE_ATTRIBUTE)) {
            // 2.x metadata
            Integer grState = dnRow.get(GROUP_STATE_ATTRIBUTE, Integer.class);
            cy2group = true;
            if (grState.intValue() == 2)
                collapsed = true;
        } else {
            List<Long> collapsedList = snRow.getList(GROUP_COLLAPSED_ATTRIBUTE, Long.class);
            if (collapsedList != null) {
                // Are we collapsed in this network?
                for (Long suid : collapsedList) {
                    if (suid.equals(net.getSUID())) {
                        collapsed = true;
                        break;
                    }
                }
            }
            List<Long> shownList = snRow.getList(GROUP_NODE_SHOWN_ATTRIBUTE, Long.class);
            if (shownList != null) {
                // Are we showing our group node in this network?
                for (Long suid : shownList) {
                    if (suid.equals(net.getSUID())) {
                        // Yup
                        nodeShown = true;
                        break;
                    }
                }
            }
        }
        // we create the group
        if (!collapsed) {
            if (!nodeShown) {
                net.removeNodes(Collections.singletonList(n));
                rootNet.restoreNode(n);
            }
            // Add our internal edges into the network (if they aren't already)
            for (CyEdge edge : netPointer.getEdgeList()) {
                if (net.containsEdge(edge))
                    continue;
                net.addEdge(edge);
            }
            // If we're a cy2 group, remember our state
            if (cy2group) {
                CyTable hnTable = rootNet.getTable(CyNode.class, CyNetwork.HIDDEN_ATTRS);
                if (hnTable.getColumn(GROUP_STATE_ATTRIBUTE) == null) {
                    hnTable.createColumn(GROUP_STATE_ATTRIBUTE, Integer.class, false);
                }
                hnTable.getRow(n.getSUID()).set(GROUP_STATE_ATTRIBUTE, 1);
            }
        }
        // Create the group
        final CyGroup group;
        // TODO: Do not create more than one instance of a CyGroup for the same group node.
        // if (groupMgr.isGroup(n, rootNet)) {
        // group = groupMgr.getGroup(n, rootNet);
        // group.addGroupToNetwork(net);
        // group.collapse(net);
        // } else {
        group = groupFactory.createGroup(net, n, true);
        // CyRow groupNodeRow = net.getRow(n, CyNetwork.HIDDEN_ATTRS);
        if (snRow.isSet(EXTERNAL_EDGE_ATTRIBUTE)) {
            List<Long> externalIDs = snRow.getList(EXTERNAL_EDGE_ATTRIBUTE, Long.class);
            List<CyEdge> externalEdges = new ArrayList<CyEdge>();
            for (Long suid : externalIDs) {
                CyEdge newEdge = rootNet.getEdge(suid);
                if (newEdge != null) {
                    // Don't add the edge if it already exists
                    if (!isMeta(group, newEdge) || !metaExists(group, newEdge)) {
                        externalEdges.add(newEdge);
                    }
                }
            }
            if (cy2group && collapsed) {
                updateMetaEdges(net, n);
            }
            group.addEdges(externalEdges);
        }
        // if we're collapsed.
        if (cy2group) {
            if (collapsed) {
                // Update the locations of child nodes
                updateChildOffsets(netPointer, net, n);
            }
            // If the group is collapsed, we need to provide the location information so we can expand it
            if (viewSet != null) {
                if (collapsed) {
                    for (CyNetworkView view : viewSet) {
                        if (view.getModel().equals(net))
                            updateGroupNodeLocation(view, n);
                        disableNestedNetworkIcon(view, n);
                    }
                }
            }
        }
        if (collapsed) {
            if (collapsedChildren.contains(n) && net.containsNode(n))
                net.removeNodes(Collections.singleton(n));
            collapsedChildren.addAll(netPointer.getNodeList());
        }
    }
    // TODO: If this is a 2.x group, clean up
    if (net.getDefaultNodeTable().getColumn(GROUP_STATE_ATTRIBUTE) != null)
        net.getDefaultNodeTable().deleteColumn(GROUP_STATE_ATTRIBUTE);
    if (net.getDefaultNodeTable().getColumn(GROUP_ISLOCAL_ATTRIBUTE) != null)
        net.getDefaultNodeTable().deleteColumn(GROUP_ISLOCAL_ATTRIBUTE);
}
Also used : ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) CyGroup(org.cytoscape.group.CyGroup) CyTable(org.cytoscape.model.CyTable) CyNode(org.cytoscape.model.CyNode) ArrayList(java.util.ArrayList) List(java.util.List) CyGroupFactory(org.cytoscape.group.CyGroupFactory) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Aggregations

CyGroup (org.cytoscape.group.CyGroup)60 CyNode (org.cytoscape.model.CyNode)33 CyNetwork (org.cytoscape.model.CyNetwork)26 ArrayList (java.util.ArrayList)22 CyEdge (org.cytoscape.model.CyEdge)12 CyNetworkView (org.cytoscape.view.model.CyNetworkView)10 HashSet (java.util.HashSet)8 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)7 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)7 List (java.util.List)6 GroupViewType (org.cytoscape.group.CyGroupSettingsManager.GroupViewType)6 CyGroupManager (org.cytoscape.group.CyGroupManager)5 CyRow (org.cytoscape.model.CyRow)5 TaskIterator (org.cytoscape.work.TaskIterator)5 CyGroupImpl (org.cytoscape.group.internal.CyGroupImpl)4 Dimension (java.awt.Dimension)3 LinkedHashSet (java.util.LinkedHashSet)3 CyEventHelper (org.cytoscape.event.CyEventHelper)3 GroupCollapsedEvent (org.cytoscape.group.events.GroupCollapsedEvent)3 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)2