Search in sources :

Example 1 with Desktop

use of org.cytoscape.io.internal.util.session.model.Desktop in project cytoscape-impl by cytoscape.

the class Cy2SessionReaderImpl method processNetworks.

private void processNetworks() throws Exception {
    if (cysession == null)
        return;
    // Network attributes and visual styles
    if (cysession.getNetworkTree() != null) {
        for (final Network net : cysession.getNetworkTree().getNetwork()) {
            if (cancelled)
                return;
            // so let's ignore a network with that name.
            if (net.getId().equals(NETWORK_ROOT))
                continue;
            final String netName = net.getId();
            final CyNetworkView view = getNetworkView(netName);
            if (view != null) {
                // Populate the visual style map
                String vsName = net.getVisualStyle();
                if (vsName != null)
                    visualStyleMap.put(view, vsName);
                // Convert 2.x hidden state (cysession.xml) to 3.x visual properties
                if (net.getHiddenEdges() != null) {
                    for (final Edge edgeObject : net.getHiddenEdges().getEdge()) {
                        if (cancelled)
                            return;
                        final String name = edgeObject.getId();
                        final CyEdge e = cache.getEdge(name);
                        if (e != null) {
                            final View<CyEdge> ev = view.getEdgeView(e);
                            if (ev != null)
                                ev.setLockedValue(BasicVisualLexicon.EDGE_VISIBLE, false);
                            else
                                logger.error("Cannot restore hidden state of edge \"" + name + "\": Edge view not found.");
                        } else {
                            logger.error("Cannot restore hidden state of edge \"" + name + "\": Edge not found.");
                        }
                    }
                }
                if (net.getHiddenNodes() != null) {
                    for (final Node nodeObject : net.getHiddenNodes().getNode()) {
                        if (cancelled)
                            return;
                        final String name = nodeObject.getId();
                        final CyNode n = cache.getNodeByName(name);
                        if (n != null) {
                            final View<CyNode> nv = view.getNodeView(n);
                            if (nv != null)
                                nv.setLockedValue(BasicVisualLexicon.NODE_VISIBLE, false);
                            else
                                logger.error("Cannot restore hidden state of node \"" + name + "\": Node view not found.");
                        } else {
                            logger.error("Cannot restore hidden state of node \"" + name + "\": Node not found.");
                        }
                    }
                }
            }
        }
    }
    // Network view sizes
    if (cysession.getSessionState() != null) {
        Desktop desktop = cysession.getSessionState().getDesktop();
        if (desktop != null && desktop.getNetworkFrames() != null) {
            List<NetworkFrame> frames = desktop.getNetworkFrames().getNetworkFrame();
            for (final NetworkFrame nf : frames) {
                if (cancelled)
                    return;
                // Set sizes
                final CyNetworkView view = getNetworkView(nf.getFrameID());
                if (view != null) {
                    BigInteger w = nf.getWidth();
                    BigInteger h = nf.getHeight();
                    if (w != null)
                        view.setVisualProperty(BasicVisualLexicon.NETWORK_WIDTH, w.doubleValue());
                    if (h != null)
                        view.setVisualProperty(BasicVisualLexicon.NETWORK_HEIGHT, h.doubleValue());
                }
            }
        }
    }
    if (!networks.isEmpty()) {
        // Select the last network that has a view, since Cy2 files do not contain the network selection info
        final CyNetwork[] array = networks.toArray(new CyNetwork[networks.size()]);
        for (int i = array.length - 1; i >= 0; i--) {
            final CyNetwork net = array[i];
            final CyRow row = net.getRow(net);
            final String netName = row.get(CyNetwork.NAME, String.class);
            final CyNetworkView view = networkViewLookup.get(netName);
            if (view != null) {
                row.set(CyNetwork.SELECTED, true);
                break;
            }
        }
    }
}
Also used : CyNode(org.cytoscape.model.CyNode) Node(org.cytoscape.io.internal.util.session.model.Node) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) Desktop(org.cytoscape.io.internal.util.session.model.Desktop) CyNetwork(org.cytoscape.model.CyNetwork) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) Network(org.cytoscape.io.internal.util.session.model.Network) BigInteger(java.math.BigInteger) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) Edge(org.cytoscape.io.internal.util.session.model.Edge) CyEdge(org.cytoscape.model.CyEdge) NetworkFrame(org.cytoscape.io.internal.util.session.model.NetworkFrame)

Aggregations

BigInteger (java.math.BigInteger)1 Desktop (org.cytoscape.io.internal.util.session.model.Desktop)1 Edge (org.cytoscape.io.internal.util.session.model.Edge)1 Network (org.cytoscape.io.internal.util.session.model.Network)1 NetworkFrame (org.cytoscape.io.internal.util.session.model.NetworkFrame)1 Node (org.cytoscape.io.internal.util.session.model.Node)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNode (org.cytoscape.model.CyNode)1 CyRow (org.cytoscape.model.CyRow)1 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1