Search in sources :

Example 71 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class NewEmptyNetworkTask method run.

@Override
public void run(final TaskMonitor tm) {
    tm.setProgress(0.0);
    final String networkCollectionName = rootNetworkList.getSelectedValue();
    if (networkCollectionName == null || networkCollectionName.equalsIgnoreCase(CRERATE_NEW_COLLECTION_STRING)) {
        // This is a new network collection, create a root network and a subnetwork, which is a base subnetwork
        subNetwork = (CySubNetwork) netFactory.createNetwork();
    } else {
        // Add a new subNetwork to the given collection
        subNetwork = this.name2RootMap.get(networkCollectionName).addSubNetwork();
    }
    tm.setProgress(0.2);
    final String networkName = namingUtil.getSuggestedNetworkTitle(name);
    subNetwork.getRow(subNetwork).set(CyNetwork.NAME, networkName);
    if (networkCollectionName == null || networkCollectionName.equalsIgnoreCase(CRERATE_NEW_COLLECTION_STRING)) {
        // Set the name of new root network
        final CyNetwork rootNetwork = subNetwork.getRootNetwork();
        rootNetwork.getRow(rootNetwork).set(CyNetwork.NAME, networkName);
    }
    NetworkViewRenderer nvRenderer = null;
    try {
        nvRenderer = renderers.getSelectedValue();
    } catch (ClassCastException cce) {
        tm.showMessage(TaskMonitor.Level.WARN, "Unknown renderer: " + renderers.getSelectedValue() + " using default renderer.");
    }
    if (nvRenderer == null)
        nvRenderer = appMgr.getDefaultNetworkViewRenderer();
    final CyNetworkViewFactory netViewFactory = nvRenderer.getNetworkViewFactory();
    tm.setProgress(0.4);
    view = netViewFactory.createNetworkView(subNetwork);
    tm.setProgress(0.6);
    netMgr.addNetwork(subNetwork, false);
    appMgr.setCurrentNetwork(subNetwork);
    tm.setProgress(0.8);
    // get the current style before registering the view!
    final VisualStyle style = vmMgr.getCurrentVisualStyle();
    netViewMgr.addNetworkView(view);
    tm.setProgress(0.9);
    applyVisualStyle(style);
    tm.setProgress(1.0);
}
Also used : CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyNetwork(org.cytoscape.model.CyNetwork) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 72 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class RegisterNetworkTask method run.

@Override
public void run(TaskMonitor tm) throws Exception {
    tm.setProgress(0.0);
    for (CyNetwork network : networks) {
        if (!networkManager.networkExists(network.getSUID()))
            networkManager.addNetwork(network, false);
    }
    tm.setProgress(0.1);
    if (views != null) {
        for (CyNetworkView view : views) {
            if (view != null) {
                networkViewManager.addNetworkView(view, false);
                tm.setProgress(0.2);
                if (style != null) {
                    vmm.setVisualStyle(style, view);
                    tm.setProgress(0.8);
                }
                view.updateView();
            }
        }
    }
    if (views != null) {
        appMgr.setCurrentNetworkView(views.get(0));
        appMgr.setSelectedNetworkViews(views);
        tm.setProgress(0.9);
    } else {
        appMgr.setCurrentNetwork(networks.get(0));
    }
    tm.setProgress(1.0);
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 73 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class ExportSelectedNetworkTaskFactoryImpl method createTaskIterator.

@Override
public TaskIterator createTaskIterator() {
    final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
    CyNetworkView view = applicationManager.getCurrentNetworkView();
    if (view != null)
        return getExportNetworkViewTaskFactory().createTaskIterator(view);
    CyNetwork network = applicationManager.getCurrentNetwork();
    if (network != null)
        return getExportNetworkTaskFactory().createTaskIterator(network);
    return null;
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 74 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class ExportAsWebArchiveTaskFactory method createTaskIterator.

@Override
public TaskIterator createTaskIterator() {
    final Set<CyNetwork> networks = networkManager.getNetworkSet();
    boolean showWarning = false;
    for (final CyNetwork network : networks) {
        final int nodeCount = network.getNodeCount();
        final int edgeCount = network.getEdgeCount();
        if (nodeCount > TH || edgeCount > TH) {
            showWarning = true;
            break;
        }
    }
    final ExportAsWebArchiveTask exportTask = new ExportAsWebArchiveTask(fullWriterFactory, simpleWriterFactory, zippedWriterFactory, applicationManager, sessionManager);
    if (showWarning) {
        return new TaskIterator(new ShowWarningTask(exportTask));
    } else {
        return new TaskIterator(exportTask);
    }
}
Also used : TaskIterator(org.cytoscape.work.TaskIterator) CyNetwork(org.cytoscape.model.CyNetwork)

Example 75 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class AbstractPropertyTask method getPropertyValue.

public Object getPropertyValue(CyNetwork network, CyIdentifiable target, VisualProperty vp) {
    CyNetworkView networkView = getViewForNetwork(network);
    Class<? extends CyIdentifiable> vpTargetType = vp.getTargetDataType();
    if (target instanceof CyNetwork) {
        if (vpTargetType != CyNetwork.class)
            throw new RuntimeException("Property '" + vp.getDisplayName() + "' not available for networks");
        return networkView.getVisualProperty(vp);
    } else if (target instanceof CyNode) {
        if (vpTargetType != CyNode.class)
            throw new RuntimeException("Property '" + vp.getDisplayName() + "' not available for nodes");
        View<CyNode> nodeView = networkView.getNodeView((CyNode) target);
        return nodeView.getVisualProperty(vp);
    } else if (target instanceof CyEdge) {
        if (vpTargetType != CyEdge.class)
            throw new RuntimeException("Property '" + vp.getDisplayName() + "' not available for edges");
        View<CyEdge> edgeView = networkView.getEdgeView((CyEdge) target);
        return edgeView.getVisualProperty(vp);
    }
    return null;
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge)

Aggregations

CyNetwork (org.cytoscape.model.CyNetwork)517 CyNode (org.cytoscape.model.CyNode)183 CyNetworkView (org.cytoscape.view.model.CyNetworkView)129 CyEdge (org.cytoscape.model.CyEdge)108 Test (org.junit.Test)107 ArrayList (java.util.ArrayList)87 CyTable (org.cytoscape.model.CyTable)75 CyApplicationManager (org.cytoscape.application.CyApplicationManager)70 CyIdentifiable (org.cytoscape.model.CyIdentifiable)57 CyRow (org.cytoscape.model.CyRow)48 HashSet (java.util.HashSet)45 CyNetworkManager (org.cytoscape.model.CyNetworkManager)40 HashMap (java.util.HashMap)35 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)35 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)32 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)31 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)30 AbstractNetworkReaderTest (org.cytoscape.io.internal.read.AbstractNetworkReaderTest)27 TaskIterator (org.cytoscape.work.TaskIterator)27 List (java.util.List)26