Search in sources :

Example 1 with CyGroupImpl

use of org.cytoscape.group.internal.CyGroupImpl in project cytoscape-impl by cytoscape.

the class GroupViewCollapseHandler method handleEvent.

/**
 * We need to do some fixup after we load the session for compound nodes.
 * When the session gets loaded, we don't (yet) have a view.  We need to
 * go through and kick update things to work properly if we have a view
 * after the session gets loaded.
 */
@Override
public void handleEvent(SessionLoadedEvent e) {
    getServices();
    // System.out.println("SessionLoadedEvent");
    try {
        // For each network
        for (CyNetworkView networkView : e.getLoadedSession().getNetworkViews()) {
            CyNetwork network = networkView.getModel();
            // For each group
            for (CyGroup group : cyGroupManager.getGroupSet(network)) {
                GroupViewType groupViewType = cyGroupSettings.getGroupViewType(group);
                // If the group is a compound node and if it is expanded,
                if (groupViewType.equals(GroupViewType.COMPOUND) || groupViewType.equals(GroupViewType.SINGLENODE)) {
                    // If it's really collapsed, all of our children will
                    // be absent from the network.  Check that first
                    boolean haveChildren = true;
                    for (CyNode node : group.getNodeList()) {
                        if (!network.containsNode(node)) {
                            haveChildren = false;
                            break;
                        }
                    }
                    if (haveChildren && network.containsNode(group.getGroupNode())) {
                        // At this point, because of the way we create the
                        // group, it will think it's collapsed.  Change
                        // that.
                        ((CyGroupImpl) group).setCollapsed(network, false);
                        ((CyGroupImpl) group).setGroupNodeShown(network, true);
                        try {
                            // OK, now activate the group
                            activateCompoundNode(group, networkView);
                        } catch (Exception rtree) {
                            // We may get an RTree exception under rare
                            // circumstances.
                            rtree.printStackTrace();
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : CyGroup(org.cytoscape.group.CyGroup) GroupViewType(org.cytoscape.group.CyGroupSettingsManager.GroupViewType) CyGroupImpl(org.cytoscape.group.internal.CyGroupImpl) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 2 with CyGroupImpl

use of org.cytoscape.group.internal.CyGroupImpl in project cytoscape-impl by cytoscape.

the class CyGroupSettingsImpl method setGroupViewType.

@Override
public void setGroupViewType(CyGroup group, GroupViewType groupViewType) {
    // System.out.println("setGroupViewType("+group+") to "+groupViewType);
    if (group != null) {
        GroupViewType oldType = getGroupViewType(group);
        groupViewTypeMap.put(group, groupViewType);
        updateSettingsInTable(group);
        if (!loadingNewGroup) {
            eventHelper.fireEvent(new GroupViewTypeChangedEvent(group, oldType, groupViewType));
        } else {
            // group node shown flag.  Fix that now...
            if (!oldType.equals(GroupViewType.NONE) && groupViewType.equals(GroupViewType.NONE)) {
                for (CyNetwork net : group.getNetworkSet()) {
                    // Careful -- the network set includes the root
                    if (net.equals(group.getRootNetwork()))
                        continue;
                    ((CyGroupImpl) group).setGroupNodeShown(net, false);
                }
            }
        }
    } else {
        this.groupViewType = groupViewType;
        updateProperties();
    }
}
Also used : CyGroupImpl(org.cytoscape.group.internal.CyGroupImpl) CyNetwork(org.cytoscape.model.CyNetwork)

Example 3 with CyGroupImpl

use of org.cytoscape.group.internal.CyGroupImpl 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 4 with CyGroupImpl

use of org.cytoscape.group.internal.CyGroupImpl 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 5 with CyGroupImpl

use of org.cytoscape.group.internal.CyGroupImpl 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

CyGroupImpl (org.cytoscape.group.internal.CyGroupImpl)5 CyNetwork (org.cytoscape.model.CyNetwork)5 CyGroup (org.cytoscape.group.CyGroup)4 GroupViewType (org.cytoscape.group.CyGroupSettingsManager.GroupViewType)4 GroupCollapsedEvent (org.cytoscape.group.events.GroupCollapsedEvent)2 CyNode (org.cytoscape.model.CyNode)2 CyNetworkView (org.cytoscape.view.model.CyNetworkView)2 Dimension (java.awt.Dimension)1 CyEventHelper (org.cytoscape.event.CyEventHelper)1 CyEdge (org.cytoscape.model.CyEdge)1 CyRow (org.cytoscape.model.CyRow)1 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)1 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)1 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)1