Search in sources :

Example 26 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.

the class AddNodeTask method run.

@Override
public void run(TaskMonitor tm) throws Exception {
    final CyNetwork net = view.getModel();
    final CyNode n = net.addNode();
    // set the name attribute for the new node
    final String nodeName = "Node " + new_node_index;
    new_node_index++;
    final CyRow nodeRow = net.getRow(n);
    nodeRow.set(CyNetwork.NAME, nodeName);
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.flushPayloadEvents();
    View<CyNode> nv = view.getNodeView(n);
    nv.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION, xformPt.getX());
    nv.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION, xformPt.getY());
    // Apply visual style
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    VisualStyle vs = vmMgr.getVisualStyle(view);
    vs.apply(net.getRow(n), nv);
    view.updateView();
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyRow(org.cytoscape.model.CyRow)

Example 27 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project clusterMaker2 by RBVI.

the class ClusterManagerImpl method linkNetworkSelection.

public void linkNetworkSelection(CyNetwork network) {
    if (isLinked(network))
        return;
    CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
    CyEventHelper helper = serviceRegistrar.getService(CyEventHelper.class);
    NetworkSelectionLinker linker = new NetworkSelectionLinker(rootNetwork, helper, this);
    registerService(linker, RowsSetListener.class, new Properties());
    linkedNetworks.put(rootNetwork, linker);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) NetworkSelectionLinker(edu.ucsf.rbvi.clusterMaker2.internal.ui.NetworkSelectionLinker) Properties(java.util.Properties) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 28 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project clusterMaker2 by RBVI.

the class ViewUtils method createView.

public static CyNetworkView createView(ClusterManager manager, CyNetwork newNetwork, boolean register) {
    // Create the view
    CyNetworkView view = manager.getService(CyNetworkViewFactory.class).createNetworkView(newNetwork);
    if (register)
        registerView(manager, view);
    // Make sure we flush our events before we try to do anything else
    CyEventHelper eventHelper = manager.getService(CyEventHelper.class);
    eventHelper.flushPayloadEvents();
    return view;
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 29 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.

the class CySessionManagerImpl method setCurrentSession.

@Override
public void setCurrentSession(CySession sess, final String fileName) {
    // Always remove the current session first
    if (!disposed)
        disposeCurrentSession();
    if (sess == null) {
        logger.debug("Creating empty session...");
        final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
        final Set<VisualStyle> styles = vmMgr.getAllVisualStyles();
        final Set<CyProperty<?>> props = getAllProperties();
        sess = new CySession.Builder().properties(props).visualStyles(styles).build();
    } else {
        logger.debug("Restoring the session...");
        // Save the selected networks first, so the selection state can be restored later.
        final List<CyNetwork> selectedNetworks = new ArrayList<>();
        final Set<CyNetwork> networks = sess.getNetworks();
        for (CyNetwork n : networks) {
            final Boolean selected = n.getDefaultNetworkTable().getRow(n.getSUID()).get(CyNetwork.SELECTED, Boolean.class);
            if (Boolean.TRUE.equals(selected))
                selectedNetworks.add(n);
        }
        restoreProperties(sess);
        restoreNetworks(sess);
        restoreTables(sess);
        restoreNetworkViews(sess, selectedNetworks);
        restoreNetworkSelection(sess, selectedNetworks);
        restoreVisualStyles(sess);
        restoreCurrentVisualStyle();
    }
    currentFileName = fileName;
    disposed = false;
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.fireEvent(new SessionLoadedEvent(this, sess, getCurrentSessionFileName()));
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) CyProperty(org.cytoscape.property.CyProperty) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) SessionLoadedEvent(org.cytoscape.session.events.SessionLoadedEvent)

Example 30 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.

the class CySessionManagerImpl method restoreNetworkViews.

private void restoreNetworkViews(final CySession sess, List<CyNetwork> selectedNetworks) {
    logger.debug("Restoring network views...");
    Set<CyNetworkView> netViews = sess.getNetworkViews();
    List<CyNetworkView> selectedViews = new ArrayList<>();
    for (CyNetworkView nv : netViews) {
        CyNetwork network = nv.getModel();
        if (selectedNetworks.contains(network)) {
            selectedViews.add(nv);
        }
    }
    Map<CyNetworkView, Map<VisualProperty<?>, Object>> viewVPMap = new HashMap<>();
    if (netViews != null) {
        final CyNetworkViewManager nvMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
        for (CyNetworkView nv : netViews) {
            if (nv != null) {
                // Save the original values of these visual properties,
                // because we will have to set them again after the views are rendered
                Map<VisualProperty<?>, Object> vpMap = new HashMap<>();
                viewVPMap.put(nv, vpMap);
                vpMap.put(BasicVisualLexicon.NETWORK_HEIGHT, nv.getVisualProperty(BasicVisualLexicon.NETWORK_HEIGHT));
                vpMap.put(BasicVisualLexicon.NETWORK_WIDTH, nv.getVisualProperty(BasicVisualLexicon.NETWORK_WIDTH));
                nvMgr.addNetworkView(nv, false);
            }
        }
    }
    // Let's guarantee the network views are rendered
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.flushPayloadEvents();
    // Set the saved visual properties again, because the renderer may have overwritten the original values
    for (Entry<CyNetworkView, Map<VisualProperty<?>, Object>> entry1 : viewVPMap.entrySet()) {
        CyNetworkView nv = entry1.getKey();
        for (Entry<VisualProperty<?>, Object> entry2 : entry1.getValue().entrySet()) nv.setVisualProperty(entry2.getKey(), entry2.getValue());
    }
    final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
    if (!selectedViews.isEmpty())
        appMgr.setCurrentNetworkView(selectedViews.get(0));
    appMgr.setSelectedNetworkViews(selectedViews);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) HashMap(java.util.HashMap) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyApplicationManager(org.cytoscape.application.CyApplicationManager) VisualProperty(org.cytoscape.view.model.VisualProperty) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

CyEventHelper (org.cytoscape.event.CyEventHelper)63 CyNetworkView (org.cytoscape.view.model.CyNetworkView)19 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)19 CyNode (org.cytoscape.model.CyNode)15 UndoSupport (org.cytoscape.work.undo.UndoSupport)14 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)13 ArrayList (java.util.ArrayList)11 CyApplicationManager (org.cytoscape.application.CyApplicationManager)11 CyNetwork (org.cytoscape.model.CyNetwork)10 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)10 Test (org.junit.Test)10 Task (org.cytoscape.work.Task)9 CyTable (org.cytoscape.model.CyTable)8 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)8 TaskIterator (org.cytoscape.work.TaskIterator)8 CyEdge (org.cytoscape.model.CyEdge)7 CyRow (org.cytoscape.model.CyRow)7 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)5 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)5