Search in sources :

Example 46 with CyGroup

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

the class CyGroupManagerImpl method addGroups.

@Override
public void addGroups(final List<CyGroup> groups) {
    synchronized (lock) {
        for (CyGroup group : groups) {
            if (!groupSet.contains(group)) {
                groupSet.add(group);
                addGroupToRootMap(group);
            // updateGroupAttribute(group);
            }
        }
    }
// Fire GroupsAddedEvent?
// cyEventHelper.fireEvent(new GroupAddedEvent(CyGroupManagerImpl.this, group));
}
Also used : CyGroup(org.cytoscape.group.CyGroup)

Example 47 with CyGroup

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

the class CyGroupManagerImpl method handleEvent.

public void handleEvent(AddedEdgesEvent addedEdgesEvent) {
    CyNetwork net = addedEdgesEvent.getSource();
    Collection<CyEdge> edges = addedEdgesEvent.getPayloadCollection();
    Set<CyGroup> groups = getGroupSet(net);
    if (groups == null || groups.size() == 0)
        return;
    // that this event came from one of the groups
    for (CyGroup group : groups) {
        CyGroupImpl gImpl = (CyGroupImpl) group;
        if (gImpl.isCollapsing() || gImpl.isExpanding())
            return;
    }
    List<CyEdge> edgesToAdd = new ArrayList<>();
    for (CyGroup group : groups) {
        CyGroupImpl gImpl = (CyGroupImpl) group;
        for (CyEdge edge : edges) {
            if (!gImpl.isMeta(edge) && gImpl.isConnectingEdge(edge))
                edgesToAdd.add(edge);
        }
        group.addEdges(edgesToAdd);
    }
}
Also used : CyGroup(org.cytoscape.group.CyGroup) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge)

Example 48 with CyGroup

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

the class GroupViewCollapseHandler method handleEvent.

@Override
public void handleEvent(GroupAddedEvent e) {
    getServices();
    CyGroup group = e.getGroup();
    GroupViewType groupViewType = cyGroupSettings.getGroupViewType(group);
    try {
        // of the group visually immediately
        if (groupViewType.equals(GroupViewType.COMPOUND) || groupViewType.equals(GroupViewType.SINGLENODE)) {
            Set<CyNetwork> networkSet = group.getNetworkSet();
            if (networkSet == null || networkSet.size() == 0)
                return;
            for (CyNetwork network : networkSet) {
                ((CyGroupImpl) group).setGroupNodeShown(network, true);
                GroupCollapsedEvent ev = new GroupCollapsedEvent(group, network, false);
                handleEvent(ev);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return;
}
Also used : CyGroup(org.cytoscape.group.CyGroup) GroupViewType(org.cytoscape.group.CyGroupSettingsManager.GroupViewType) CyGroupImpl(org.cytoscape.group.internal.CyGroupImpl) CyNetwork(org.cytoscape.model.CyNetwork) GroupCollapsedEvent(org.cytoscape.group.events.GroupCollapsedEvent)

Example 49 with CyGroup

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

the class GroupViewCollapseHandler method handleEvent.

@Override
public void handleEvent(GroupCollapsedEvent e) {
    getServices();
    CyNetwork network = e.getNetwork();
    CyGroup group = e.getSource();
    final Collection<CyNetworkView> views = cyNetworkViewManager.getNetworkViews(network);
    CyNetworkView view = null;
    if (views.size() == 0) {
        return;
    }
    for (CyNetworkView v : views) {
        if (v.getRendererId().equals("org.cytoscape.ding")) {
            view = v;
        }
    }
    if (view == null)
        return;
    CyRootNetwork rootNetwork = group.getRootNetwork();
    GroupViewType groupViewType = cyGroupSettings.getGroupViewType(group);
    if (e.collapsed()) {
        // System.out.println("Got collapse event for "+group);
        // Get the location to move the group node to
        Dimension d = ViewUtils.getLocation(network, group);
        if (d != null) {
            // Move it.
            ViewUtils.moveNode(view, group.getGroupNode(), d);
        }
        View<CyNode> nView = view.getNodeView(group.getGroupNode());
        if (cyGroupSettings.getUseNestedNetworks(group)) {
            // Now, if we're displaying the nested network, create it....
            CyNetwork nn = group.getGroupNetwork();
            CyNetworkView nnView = null;
            // If we've already registered the network, don't do it again
            if (!cyNetworkManager.networkExists(nn.getSUID())) {
                cyNetworkManager.addNetwork(nn, false);
                nnView = cyNetworkViewFactory.createNetworkView(nn);
                cyNetworkViewManager.addNetworkView(nnView, false);
                // Apply our current style to the nested network
                VisualStyle style = cyStyleManager.getVisualStyle(view);
                cyStyleManager.setVisualStyle(style, nnView);
                style.apply(nnView);
            } else if (cyNetworkViewManager.viewExists(nn)) {
                nnView = cyNetworkViewManager.getNetworkViews(nn).iterator().next();
            }
            if (nnView != null) {
                ViewUtils.moveNodes(group, nnView, d);
                nnView.updateView();
                // Allow the nested network image to be displayed
                nView.clearValueLock(BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE);
            }
        } else {
            // Make sure the nested network image is not displayed
            nView.setLockedValue(BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE, Boolean.FALSE);
        }
        // If we were showing this as a compound node, we need to restyle
        if (groupViewType.equals(GroupViewType.COMPOUND)) {
            deActivateCompoundNode(group, view);
        }
        styleGroupNode(group, view, views);
    } else {
        // System.out.println("Got expand event for "+group);
        CyNode groupNode = group.getGroupNode();
        // Get the location of the group node before it went away
        Dimension center = ViewUtils.getLocation(network, group);
        if (center != null)
            ViewUtils.moveNodes(group, view, center);
        // If we're asked to, show the group node
        if (!groupViewType.equals(GroupViewType.NONE)) {
            CySubNetwork subnet = (CySubNetwork) network;
            // Add the node back
            subnet.addNode(group.getGroupNode());
            // Add the group nodes's edges back
            List<CyEdge> groupNodeEdges = rootNetwork.getAdjacentEdgeList(groupNode, CyEdge.Type.ANY);
            for (CyEdge edge : groupNodeEdges) {
                CyRow row = rootNetwork.getRow(edge, CyNetwork.HIDDEN_ATTRS);
                // Only add non-meta edges
                if (row != null && (!row.isSet(CyGroupImpl.ISMETA_EDGE_ATTR) || !row.get(CyGroupImpl.ISMETA_EDGE_ATTR, Boolean.class))) {
                    subnet.addEdge(edge);
                } else if (subnet.containsEdge(edge) && row != null && row.isSet(CyGroupImpl.ISMETA_EDGE_ATTR) && row.get(CyGroupImpl.ISMETA_EDGE_ATTR, Boolean.class)) {
                    // Edge is a meta edge, but is still in the network.  Remove it
                    subnet.removeEdges(Collections.singletonList(edge));
                }
            }
            if (groupViewType.equals(GroupViewType.SHOWGROUPNODE)) {
                // If this is the first time, we need to add our member
                // edges in.
                addMemberEdges(group, network);
                // Style our member edges
                styleGroupNode(group, view, views);
            }
            // Flush events so that the view hears about it
            final CyEventHelper cyEventHelper = cyGroupManager.getService(CyEventHelper.class);
            cyEventHelper.flushPayloadEvents();
            // Now, call ourselves as if we had been collapsed
            handleEvent(new GroupCollapsedEvent(group, network, true));
            if (groupViewType.equals(GroupViewType.COMPOUND) || groupViewType.equals(GroupViewType.SINGLENODE)) {
                // May be redundant, but just to make sure
                ((CyGroupImpl) group).setGroupNodeShown(network, true);
                activateCompoundNode(group, view);
            }
            cyEventHelper.flushPayloadEvents();
            view.updateView();
            return;
        }
        final List<CyNode> nodeList = group.getNodeList();
        // TODO: turn off stupid nested network thing
        for (CyNode node : nodeList) {
            if (!network.containsNode(node))
                continue;
            View<CyNode> nView = view.getNodeView(node);
            if (node.getNetworkPointer() != null && cyGroupManager.isGroup(node, network)) {
                if (!cyGroupSettings.getUseNestedNetworks(cyGroupManager.getGroup(node, network))) {
                    nView.setLockedValue(BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE, Boolean.FALSE);
                }
            }
        }
        // Apply visual property to added graph elements
        ViewUtils.applyStyle(nodeList, views, cyStyleManager);
        ViewUtils.applyStyle(group.getInternalEdgeList(), views, cyStyleManager);
        ViewUtils.applyStyle(group.getExternalEdgeList(), views, cyStyleManager);
    }
    view.updateView();
}
Also used : GroupViewType(org.cytoscape.group.CyGroupSettingsManager.GroupViewType) CyEventHelper(org.cytoscape.event.CyEventHelper) CyNetwork(org.cytoscape.model.CyNetwork) Dimension(java.awt.Dimension) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) CyGroup(org.cytoscape.group.CyGroup) CyGroupImpl(org.cytoscape.group.internal.CyGroupImpl) CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) GroupCollapsedEvent(org.cytoscape.group.events.GroupCollapsedEvent) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 50 with CyGroup

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

the class GroupViewCollapseHandler method handleEvent.

/**
 * This is called when the user changes the view type for a particular
 * group.  We want to respond and change the visualization right away,
 * from the old visual type to the new visual type.
 */
@Override
public void handleEvent(GroupViewTypeChangedEvent e) {
    getServices();
    GroupViewType oldType = e.getOldType();
    GroupViewType newType = e.getNewType();
    CyGroup group = e.getGroup();
    if (group == null || oldType.equals(newType))
        return;
    if (oldType == GroupViewType.COMPOUND || oldType == GroupViewType.SINGLENODE)
        removeCompoundNode(group);
    else if (oldType == GroupViewType.SHOWGROUPNODE)
        ((CyGroupImpl) group).removeMemberEdges();
    for (CyNetwork net : group.getNetworkSet()) {
        // Careful -- the network set includes the root
        if (net.equals(group.getRootNetwork()))
            continue;
        // necessary to make sure we can update other settings.
        if (newType == GroupViewType.NONE) {
            ((CyGroupImpl) group).setGroupNodeShown(net, false);
            // If we're expanded and the group node is shown, remove it
            if (!group.isCollapsed(net) && net.containsNode(group.getGroupNode())) {
                group.collapse(net);
                // We need to do this again because our group node was "noticed" when we
                // collapsed.  If we remove the group node ourselves, it messes up the
                // restyling
                ((CyGroupImpl) group).setGroupNodeShown(net, false);
            }
        } else {
            // the group is appropriately restyled
            if (!group.isCollapsed(net))
                group.collapse(net);
            group.expand(net);
        }
    }
}
Also used : GroupViewType(org.cytoscape.group.CyGroupSettingsManager.GroupViewType) CyGroup(org.cytoscape.group.CyGroup) CyGroupImpl(org.cytoscape.group.internal.CyGroupImpl) CyNetwork(org.cytoscape.model.CyNetwork)

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