Search in sources :

Example 1 with CyJSONUtil

use of org.cytoscape.util.json.CyJSONUtil in project cytoscape-impl by cytoscape.

the class UnHideCommandTask method getResults.

public Object getResults(Class type) {
    List<CyIdentifiable> identifiables = new ArrayList<>();
    if (nodes != null)
        identifiables.addAll(nodes);
    if (edges != null)
        identifiables.addAll(edges);
    if (type.equals(List.class)) {
        return identifiables;
    } else if (type.equals(String.class)) {
        if (identifiables.size() == 0)
            return "<none>";
        String ret = "";
        if (nodes != null && nodes.size() > 0) {
            ret += "Nodes unhidden: \n";
            for (CyNode node : nodes) {
                ret += "   " + network.getRow(node).get(CyNetwork.NAME, String.class) + "\n";
            }
        }
        if (edges != null && edges.size() > 0) {
            ret += "Edges unhidden: \n";
            for (CyEdge edge : edges) {
                ret += "   " + network.getRow(edge).get(CyNetwork.NAME, String.class) + "\n";
            }
        }
        return ret;
    } else if (type.equals(JSONResult.class)) {
        JSONResult res = () -> {
            if (identifiables == null || identifiables.size() == 0)
                return "{}";
            else {
                CyJSONUtil cyJSONUtil = serviceRegistrar.getService(CyJSONUtil.class);
                String result = "{\"nodes\":";
                if (nodes == null || nodes.size() == 0)
                    result += "[]";
                else
                    result += cyJSONUtil.cyIdentifiablesToJson(nodes);
                result += ", \"edges\":";
                if (edges == null || edges.size() == 0)
                    result += "[]";
                else
                    result += cyJSONUtil.cyIdentifiablesToJson(edges);
                result += "}";
                return result;
            }
        };
        return res;
    }
    return identifiables;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CyIdentifiable(org.cytoscape.model.CyIdentifiable) CyJSONUtil(org.cytoscape.util.json.CyJSONUtil)

Example 2 with CyJSONUtil

use of org.cytoscape.util.json.CyJSONUtil in project cytoscape-impl by cytoscape.

the class SelectTask method getResults.

public Object getResults(Class type) {
    List<CyIdentifiable> identifiables = new ArrayList();
    if (selectedNodes != null)
        identifiables.addAll(selectedNodes);
    if (selectedEdges != null)
        identifiables.addAll(selectedEdges);
    if (type.equals(List.class)) {
        return identifiables;
    } else if (type.equals(String.class)) {
        if (identifiables.size() == 0)
            return "<none>";
        String ret = "";
        if (selectedNodes != null && selectedNodes.size() > 0) {
            ret += "Nodes selected: \n";
            for (CyNode node : selectedNodes) {
                ret += "   " + network.getRow(node).get(CyNetwork.NAME, String.class) + "\n";
            }
        }
        if (selectedEdges != null && selectedEdges.size() > 0) {
            ret += "Edges selected: \n";
            for (CyEdge edge : selectedEdges) {
                ret += "   " + network.getRow(edge).get(CyNetwork.NAME, String.class) + "\n";
            }
        }
        return ret;
    } else if (type.equals(JSONResult.class)) {
        JSONResult res = () -> {
            if (identifiables == null || identifiables.size() == 0)
                return "{}";
            else {
                CyJSONUtil cyJSONUtil = registrar.getService(CyJSONUtil.class);
                String result = "{\"nodes\":";
                if (selectedNodes == null || selectedNodes.size() == 0)
                    result += "[]";
                else
                    result += cyJSONUtil.cyIdentifiablesToJson(selectedNodes);
                result += ", \"edges\":";
                if (selectedEdges == null || selectedEdges.size() == 0)
                    result += "[]";
                else
                    result += cyJSONUtil.cyIdentifiablesToJson(selectedEdges);
                return result + "}";
            }
        };
        return res;
    }
    return identifiables;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CyIdentifiable(org.cytoscape.model.CyIdentifiable) CyJSONUtil(org.cytoscape.util.json.CyJSONUtil)

Example 3 with CyJSONUtil

use of org.cytoscape.util.json.CyJSONUtil in project cytoscape-impl by cytoscape.

the class GenerateNetworkViewsTask method getResults.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object getResults(Class expectedType) {
    if (expectedType.equals(String.class))
        return getStringResults();
    else if (expectedType.equals(JSONResult.class)) {
        JSONResult res = () -> {
            if (results == null && largeNetworks.isEmpty())
                return "{}";
            else {
                CyJSONUtil cyJSONUtil = serviceRegistrar.getService(CyJSONUtil.class);
                List<CyNetwork> networks = new ArrayList<>();
                for (CyNetworkView view : results) networks.add(view.getModel());
                networks.addAll(largeNetworks);
                String jsonRes = "{ \"networks\":";
                jsonRes += cyJSONUtil.cyIdentifiablesToJson(networks);
                jsonRes += ", \"views\":";
                jsonRes += cyJSONUtil.cyIdentifiablesToJson(results) + "}";
                return jsonRes;
            }
        };
        return res;
    }
    return results;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyJSONUtil(org.cytoscape.util.json.CyJSONUtil)

Example 4 with CyJSONUtil

use of org.cytoscape.util.json.CyJSONUtil in project cytoscape-impl by cytoscape.

the class GroupNodesTask method getResults.

@Override
public Object getResults(Class requestedType) {
    if (newGroup == null)
        return null;
    if (requestedType.equals(CyGroup.class))
        return newGroup;
    if (requestedType.equals(String.class))
        return newGroup.toString();
    if (requestedType.equals(JSONResult.class)) {
        CyJSONUtil jsonUtil = serviceRegistrar.getService(CyJSONUtil.class);
        JSONResult res = () -> {
            if (newGroup == null)
                return "{}";
            return "{\"group\":" + newGroup.getGroupNode().getSUID() + "}";
        /*
				String val = "{\"group\":"+newGroup.getGroupNode().getSUID();
				List<CyNode> nodes = newGroup.getNodeList();
				if (nodes != null && nodes.size() > 0)
					val += "\"nodes\":"+jsonUtil.cyIdentifiablesToJson(nodes);
				return val+"}";
				*/
        };
        return res;
    }
    return null;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) CyJSONUtil(org.cytoscape.util.json.CyJSONUtil)

Example 5 with CyJSONUtil

use of org.cytoscape.util.json.CyJSONUtil in project cytoscape-impl by cytoscape.

the class HideCommandTask method getResults.

public Object getResults(Class type) {
    List<CyIdentifiable> identifiables = new ArrayList<>();
    if (nodes != null)
        identifiables.addAll(nodes);
    if (edges != null)
        identifiables.addAll(edges);
    if (type.equals(List.class)) {
        return identifiables;
    } else if (type.equals(String.class)) {
        if (identifiables.size() == 0)
            return "<none>";
        String ret = "";
        if (nodes != null && nodes.size() > 0) {
            ret += "Nodes hidden: \n";
            for (CyNode node : nodes) {
                ret += "   " + network.getRow(node).get(CyNetwork.NAME, String.class) + "\n";
            }
        }
        if (edges != null && edges.size() > 0) {
            ret += "Edges hidden: \n";
            for (CyEdge edge : edges) {
                ret += "   " + network.getRow(edge).get(CyNetwork.NAME, String.class) + "\n";
            }
        }
        return ret;
    } else if (type.equals(JSONResult.class)) {
        JSONResult res = () -> {
            if (identifiables == null || identifiables.size() == 0)
                return "{}";
            else {
                CyJSONUtil cyJSONUtil = serviceRegistrar.getService(CyJSONUtil.class);
                String result = "{\"nodes\":";
                if (nodes == null || nodes.size() == 0)
                    result += "[]";
                else
                    result += cyJSONUtil.cyIdentifiablesToJson(nodes);
                result += ", \"edges\":";
                if (edges == null || edges.size() == 0)
                    result += "[]";
                else
                    result += cyJSONUtil.cyIdentifiablesToJson(edges);
                result += "}";
                return result;
            }
        };
        return res;
    }
    return identifiables;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CyIdentifiable(org.cytoscape.model.CyIdentifiable) CyJSONUtil(org.cytoscape.util.json.CyJSONUtil)

Aggregations

CyJSONUtil (org.cytoscape.util.json.CyJSONUtil)10 JSONResult (org.cytoscape.work.json.JSONResult)10 CyIdentifiable (org.cytoscape.model.CyIdentifiable)6 ArrayList (java.util.ArrayList)5 CyEdge (org.cytoscape.model.CyEdge)4 CyNode (org.cytoscape.model.CyNode)4 CyColumn (org.cytoscape.model.CyColumn)3 CyRow (org.cytoscape.model.CyRow)3 CyNetwork (org.cytoscape.model.CyNetwork)1 CyTable (org.cytoscape.model.CyTable)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1