Search in sources :

Example 51 with CyEventHelper

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

the class UnHideAllNodesTaskFactoryTest method testRun.

@Test
public void testRun() throws Exception {
    UndoSupport undoSupport = mock(UndoSupport.class);
    CyEventHelper eventHelper = mock(CyEventHelper.class);
    VisualMappingManager vmMgr = mock(VisualMappingManager.class);
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(UndoSupport.class)).thenReturn(undoSupport);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
    when(serviceRegistrar.getService(VisualMappingManager.class)).thenReturn(vmMgr);
    UnHideAllNodesTaskFactoryImpl factory = new UnHideAllNodesTaskFactoryImpl(serviceRegistrar);
    CyNetworkView view = mock(CyNetworkView.class);
    TaskIterator ti = factory.createTaskIterator(view);
    assertNotNull(ti);
    assertTrue(ti.hasNext());
    Task t = ti.next();
    assertNotNull(t);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) TaskIterator(org.cytoscape.work.TaskIterator) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) Test(org.junit.Test)

Example 52 with CyEventHelper

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

the class HideSelectedEdgesTaskFactoryTest method testRun.

@Test
public void testRun() throws Exception {
    UndoSupport undoSupport = mock(UndoSupport.class);
    CyEventHelper eventHelper = mock(CyEventHelper.class);
    VisualMappingManager vmMgr = mock(VisualMappingManager.class);
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(UndoSupport.class)).thenReturn(undoSupport);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
    when(serviceRegistrar.getService(VisualMappingManager.class)).thenReturn(vmMgr);
    HideSelectedEdgesTaskFactoryImpl factory = new HideSelectedEdgesTaskFactoryImpl(serviceRegistrar);
    CyNetworkView view = mock(CyNetworkView.class);
    TaskIterator ti = factory.createTaskIterator(view);
    assertNotNull(ti);
    assertTrue(ti.hasNext());
    Task t = ti.next();
    assertNotNull(t);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) TaskIterator(org.cytoscape.work.TaskIterator) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) Test(org.junit.Test)

Example 53 with CyEventHelper

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

the class HideSelectedTaskFactoryTest method testRun.

@Test
public void testRun() throws Exception {
    UndoSupport undoSupport = mock(UndoSupport.class);
    CyEventHelper eventHelper = mock(CyEventHelper.class);
    VisualMappingManager vmMgr = mock(VisualMappingManager.class);
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(UndoSupport.class)).thenReturn(undoSupport);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
    when(serviceRegistrar.getService(VisualMappingManager.class)).thenReturn(vmMgr);
    HideSelectedTaskFactoryImpl factory = new HideSelectedTaskFactoryImpl(serviceRegistrar);
    CyNetworkView view = mock(CyNetworkView.class);
    TaskIterator ti = factory.createTaskIterator(view);
    assertNotNull(ti);
    assertTrue(ti.hasNext());
    Task t = ti.next();
    assertNotNull(t);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) TaskIterator(org.cytoscape.work.TaskIterator) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) Test(org.junit.Test)

Example 54 with CyEventHelper

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

the class UnHideAllTaskFactoryTest method testRun.

@Test
public void testRun() throws Exception {
    UndoSupport undoSupport = mock(UndoSupport.class);
    CyEventHelper eventHelper = mock(CyEventHelper.class);
    VisualMappingManager vmMgr = mock(VisualMappingManager.class);
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(UndoSupport.class)).thenReturn(undoSupport);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
    when(serviceRegistrar.getService(VisualMappingManager.class)).thenReturn(vmMgr);
    UnHideAllTaskFactoryImpl factory = new UnHideAllTaskFactoryImpl(serviceRegistrar);
    CyNetworkView view = mock(CyNetworkView.class);
    TaskIterator ti = factory.createTaskIterator(view);
    assertNotNull(ti);
    assertTrue(ti.hasNext());
    Task t = ti.next();
    assertNotNull(t);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) TaskIterator(org.cytoscape.work.TaskIterator) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) Test(org.junit.Test)

Example 55 with CyEventHelper

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

the class ClipboardImpl method paste.

public List<CyIdentifiable> paste(CyNetworkView targetView, double x, double y) {
    final List<CyIdentifiable> pastedObjects = new ArrayList<>();
    final Map<CyRow, CyRow> rowMap = new HashMap<>();
    // We need to do this in 4 passes.
    // In pass 1, we'll add all of the nodes and store their (possibly new) SUID.
    // In pass 2, we'll add the edges.
    // In pass 3, we'll reposition the nodes and paste any locked visual properties node views.
    // In pass 4, we'll paste any locked visual properties to edge views
    // Note that if we add any nodes, we'll only add edges to nodes that exist.
    // Pass 1: add the nodes
    final Map<CyNode, CyNode> newNodeMap = new HashMap<>();
    for (CyNode node : nodes) {
        CyNode newNode = pasteNode(sourceView, targetView, node, rowMap);
        newNodeMap.put(node, newNode);
        pastedObjects.add(newNode);
    }
    // Pass 2: add the edges
    final Map<CyEdge, CyEdge> newEdgeMap = new HashMap<>();
    for (CyEdge edge : edges) {
        CyEdge newEdge = pasteEdge(sourceView, targetView, edge, rowMap, newNodeMap, pastedObjects);
        if (newEdge != null) {
            newEdgeMap.put(edge, newEdge);
            pastedObjects.add(newEdge);
        }
    }
    copyRows(rowMap);
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    // Make sure node/edge views were created
    eventHelper.flushPayloadEvents();
    targetView.updateView();
    // Pass 3: paste locked visual properties and reposition the new node views
    double xOffset = xCenter - x;
    double yOffset = yCenter - y;
    for (CyNode node : nodePositions.keySet()) {
        final CyNode newNode = newNodeMap.get(node);
        if (newNode == null || !pastedObjects.contains(newNode))
            continue;
        final double[] position = nodePositions.get(node);
        double nodeX = (position == null ? 0 : position[0]) - xOffset;
        double nodeY = (position == null ? 0 : position[1]) - yOffset;
        // Now, get the new node view
        View<CyNode> newNodeView = targetView.getNodeView(newNode);
        if (newNodeView != null) {
            newNodeView.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION, nodeX);
            newNodeView.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION, nodeY);
            setLockedValues(newNodeView, node, nodeBypass);
        }
    }
    // Pass 4: paste locked visual properties to new edge views
    if (!edgeBypassMap.isEmpty()) {
        for (CyEdge edge : edgeBypassMap.keySet()) {
            // Now, get the new edge view
            CyEdge newEdge = newEdgeMap.get(edge);
            View<CyEdge> newEdgeView = newEdge != null ? targetView.getEdgeView(newEdge) : null;
            if (newEdgeView != null)
                setLockedValues(newEdgeView, edge, edgeBypassMap);
        }
    }
    // the nodes and edges don't show as selected.  We need to fix that now
    for (CyIdentifiable object : pastedObjects) {
        // Special-case selected!!!
        if (isSelected(targetView, object))
            reselect(targetView, object);
    }
    return pastedObjects;
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) ArrayList(java.util.ArrayList) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) CyNode(org.cytoscape.model.CyNode) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

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