Search in sources :

Example 1 with CyPropertyReader

use of org.cytoscape.io.read.CyPropertyReader in project cytoscape-impl by cytoscape.

the class Cy2SessionReaderImpl method extractSessionState.

private void extractSessionState(InputStream is, String entryName) throws Exception {
    CyPropertyReader reader = propertyReaderMgr.getReader(is, entryName);
    reader.run(taskMonitor);
    cysession = (Cysession) reader.getProperty();
    if (cysession != null) {
        // Network attributes and visual styles
        if (cysession.getNetworkTree() != null) {
            for (final Network net : cysession.getNetworkTree().getNetwork()) {
                // so let's ignore a network with that name.
                if (net.getId().equals(NETWORK_ROOT))
                    continue;
                final String netName = net.getId();
                List<Node> selNodes = null;
                List<Edge> selEdges = null;
                if (net.getSelectedNodes() != null)
                    selNodes = net.getSelectedNodes().getNode();
                if (net.getSelectedEdges() != null)
                    selEdges = net.getSelectedEdges().getEdge();
                nodeSelectionLookup.put(netName, selNodes);
                edgeSelectionLookup.put(netName, selEdges);
            }
        }
        // Convert the old cysession to core the required 3.0 core plugin files:
        // Actually we just need to extract the "networkFrames" and "cytopanels" data from the Cysession object
        // and write an XML file that will be parsed by swing-application.
        StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
        sb.append("<sessionState documentVersion=\"1.0\">\n");
        sb.append("    <networkFrames>\n");
        if (cysession.getSessionState() != null && cysession.getSessionState().getDesktop() != null) {
            NetworkFrames netFrames = cysession.getSessionState().getDesktop().getNetworkFrames();
            if (netFrames != null) {
                for (NetworkFrame nf : netFrames.getNetworkFrame()) {
                    String id = nf.getFrameID();
                    String x = nf.getX() != null ? nf.getX().toString() : "0";
                    String y = nf.getY() != null ? nf.getY().toString() : "0";
                    sb.append("        <networkFrame networkViewID=\"" + id + "\" x=\"" + x + "\" y=\"" + y + "\"/>\n");
                }
            }
        }
        sb.append("    </networkFrames>\n");
        sb.append("    <cytopanels>\n");
        SessionState sessionState = cysession.getSessionState();
        if (sessionState != null) {
            Cytopanels cytopanels = sessionState.getCytopanels();
            if (cytopanels != null) {
                List<Cytopanel> cytopanelsList = cytopanels.getCytopanel();
                for (Cytopanel cytopanel : cytopanelsList) {
                    String id = cytopanel.getId();
                    String state = cytopanel.getPanelState();
                    String selection = cytopanel.getSelectedPanel();
                    sb.append("        <cytopanel id=\"" + id + "\">\n");
                    sb.append("            <panelState>" + state + "</panelState>\n");
                    sb.append("            <selectedPanel>" + selection + "</selectedPanel>\n");
                    sb.append("        </cytopanel>\n");
                }
            }
        }
        sb.append("    </cytopanels>\n");
        sb.append("</sessionState>");
        // Extract it as an app file now:
        ByteArrayInputStream bais = new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
        extractPluginEntry(bais, cysession.getId() + "/" + PLUGINS_FOLDER + "org.cytoscape.swing-application/session_state.xml");
    }
}
Also used : SessionState(org.cytoscape.io.internal.util.session.model.SessionState) CyNode(org.cytoscape.model.CyNode) Node(org.cytoscape.io.internal.util.session.model.Node) NetworkFrames(org.cytoscape.io.internal.util.session.model.NetworkFrames) ByteArrayInputStream(java.io.ByteArrayInputStream) Cytopanels(org.cytoscape.io.internal.util.session.model.Cytopanels) CyNetwork(org.cytoscape.model.CyNetwork) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) Network(org.cytoscape.io.internal.util.session.model.Network) CyPropertyReader(org.cytoscape.io.read.CyPropertyReader) Edge(org.cytoscape.io.internal.util.session.model.Edge) CyEdge(org.cytoscape.model.CyEdge) NetworkFrame(org.cytoscape.io.internal.util.session.model.NetworkFrame) Cytopanel(org.cytoscape.io.internal.util.session.model.Cytopanel)

Example 2 with CyPropertyReader

use of org.cytoscape.io.read.CyPropertyReader in project cytoscape-impl by cytoscape.

the class Cy2SessionReaderImpl method extractProperties.

private void extractProperties(InputStream is, String entryName) throws Exception {
    CyPropertyReader reader = propertyReaderMgr.getReader(is, entryName);
    if (reader == null)
        return;
    reader.run(taskMonitor);
    final Properties props = (Properties) reader.getProperty();
    final Properties newProps = new Properties();
    if (props != null) {
        // Only add properties that should have the SESSION_FILE save policy
        for (String key : props.stringPropertyNames()) {
            if (isSessionProperty(key)) {
                String value = props.getProperty(key);
                newProps.put(key, value);
            }
        }
        final CyProperty<Properties> cyProps = new SimpleCyProperty<Properties>("session", newProps, Properties.class, CyProperty.SavePolicy.SESSION_FILE);
        properties.add(cyProps);
    }
}
Also used : CyPropertyReader(org.cytoscape.io.read.CyPropertyReader) Properties(java.util.Properties) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty)

Example 3 with CyPropertyReader

use of org.cytoscape.io.read.CyPropertyReader in project cytoscape-impl by cytoscape.

the class Cy2SessionReaderImpl method extractBookmarks.

private void extractBookmarks(InputStream is, String entryName) throws Exception {
    CyPropertyReader reader = propertyReaderMgr.getReader(is, entryName);
    reader.run(taskMonitor);
    final Bookmarks bookmarks = (Bookmarks) reader.getProperty();
    final CyProperty<Bookmarks> cyProps = new SimpleCyProperty<Bookmarks>("bookmarks", bookmarks, Bookmarks.class, CyProperty.SavePolicy.SESSION_FILE);
    properties.add(cyProps);
}
Also used : Bookmarks(org.cytoscape.property.bookmark.Bookmarks) CyPropertyReader(org.cytoscape.io.read.CyPropertyReader) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty)

Example 4 with CyPropertyReader

use of org.cytoscape.io.read.CyPropertyReader in project cytoscape-impl by cytoscape.

the class Cy3SessionReaderImpl method extractProperties.

private void extractProperties(InputStream is, String entryName) throws Exception {
    CyPropertyReader reader = propertyReaderMgr.getReader(is, entryName);
    if (reader == null)
        return;
    reader.run(taskMonitor);
    CyProperty<?> cyProps = null;
    Object obj = reader.getProperty();
    if (obj instanceof Properties) {
        Properties props = (Properties) obj;
        Matcher matcher = PROPERTIES_PATTERN.matcher(entryName);
        if (matcher.matches()) {
            String propsName = matcher.group(2);
            if (propsName != null) {
                cyProps = new SimpleCyProperty<>(propsName, props, Properties.class, CyProperty.SavePolicy.SESSION_FILE);
            }
        }
    } else if (obj instanceof Bookmarks) {
        cyProps = new SimpleCyProperty<>("bookmarks", (Bookmarks) obj, Bookmarks.class, CyProperty.SavePolicy.SESSION_FILE);
    } else {
        // TODO: get name and create the CyProperty for unknown types
        logger.error("Cannot extract CyProperty name from: " + entryName);
    }
    if (cyProps != null)
        properties.add(cyProps);
}
Also used : Bookmarks(org.cytoscape.property.bookmark.Bookmarks) Matcher(java.util.regex.Matcher) CyPropertyReader(org.cytoscape.io.read.CyPropertyReader) Properties(java.util.Properties) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty)

Aggregations

CyPropertyReader (org.cytoscape.io.read.CyPropertyReader)4 SimpleCyProperty (org.cytoscape.property.SimpleCyProperty)3 Properties (java.util.Properties)2 Bookmarks (org.cytoscape.property.bookmark.Bookmarks)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Matcher (java.util.regex.Matcher)1 Cytopanel (org.cytoscape.io.internal.util.session.model.Cytopanel)1 Cytopanels (org.cytoscape.io.internal.util.session.model.Cytopanels)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 NetworkFrames (org.cytoscape.io.internal.util.session.model.NetworkFrames)1 Node (org.cytoscape.io.internal.util.session.model.Node)1 SessionState (org.cytoscape.io.internal.util.session.model.SessionState)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNode (org.cytoscape.model.CyNode)1 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)1