Search in sources :

Example 36 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class CyActivator method start.

public void start(BundleContext bc) {
    UndoSupport undo = getService(bc, UndoSupport.class);
    ForceDirectedLayout forceDirectedLayout = new ForceDirectedLayout(undo);
    Properties forceDirectedLayoutProps = new Properties();
    forceDirectedLayoutProps.setProperty(PREFERRED_MENU, "Layout.Cytoscape Layouts");
    forceDirectedLayoutProps.setProperty("preferredTaskManager", "menu");
    forceDirectedLayoutProps.setProperty(TITLE, forceDirectedLayout.toString());
    forceDirectedLayoutProps.setProperty(MENU_GRAVITY, "10.5");
    registerService(bc, forceDirectedLayout, CyLayoutAlgorithm.class, forceDirectedLayoutProps);
}
Also used : Properties(java.util.Properties) ServiceProperties(org.cytoscape.work.ServiceProperties) UndoSupport(org.cytoscape.work.undo.UndoSupport)

Example 37 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class CyActivator method start.

@Override
public void start(BundleContext bc) {
    final CyServiceRegistrar serviceRegistrar = getService(bc, CyServiceRegistrar.class);
    final UndoSupport undoSupport = getService(bc, UndoSupport.class);
    GridNodeLayout gridNodeLayout = new GridNodeLayout(undoSupport);
    CyLayoutAlgorithmManagerImpl layoutManager = new CyLayoutAlgorithmManagerImpl(gridNodeLayout, serviceRegistrar);
    registerService(bc, layoutManager, CyLayoutAlgorithmManager.class, new Properties());
    {
        Properties props = new Properties();
        // gridNodeLayoutProps.setProperty(PREFERRED_MENU, "Layout.Cytoscape Layouts");
        props.setProperty("preferredTaskManager", "menu");
        props.setProperty(TITLE, gridNodeLayout.toString());
        props.setProperty(MENU_GRAVITY, "10.0");
        registerService(bc, gridNodeLayout, CyLayoutAlgorithm.class, props);
    }
    registerServiceListener(bc, layoutManager::addLayout, layoutManager::removeLayout, CyLayoutAlgorithm.class);
}
Also used : GridNodeLayout(org.cytoscape.view.layout.internal.algorithms.GridNodeLayout) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) Properties(java.util.Properties) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar)

Example 38 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class DeleteSelectedNodesAndEdgesTask method run.

@Override
public void run(final TaskMonitor taskMonitor) {
    taskMonitor.setProgress(0.0);
    List<CyNode> nodeList = tunables.getNodeList(false);
    List<CyEdge> edgeList = tunables.getEdgeList(false);
    if (tunables.getNetwork() != null)
        network = tunables.getNetwork();
    // Delete from the base network so that our changes can be undone:
    if (nodeList == null && edgeList == null) {
        selectedNodes = CyTableUtil.getNodesInState(network, "selected", true);
        taskMonitor.setProgress(0.1);
        selectedEdges = new HashSet<CyEdge>(CyTableUtil.getEdgesInState(network, "selected", true));
    } else {
        if (nodeList != null && nodeList.size() > 0)
            selectedNodes = nodeList;
        else
            selectedNodes = new ArrayList<CyNode>();
        if (edgeList != null && edgeList.size() > 0)
            selectedEdges = new HashSet<CyEdge>(edgeList);
        else
            selectedEdges = new HashSet<CyEdge>();
    }
    taskMonitor.setProgress(0.2);
    // Make sure we're not loosing any edges for a possible undo!
    for (CyNode selectedNode : selectedNodes) selectedEdges.addAll(network.getAdjacentEdgeList(selectedNode, CyEdge.Type.ANY));
    taskMonitor.setProgress(0.3);
    final UndoSupport undoSupport = serviceRegistrar.getService(UndoSupport.class);
    final CyNetworkViewManager netViewMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    undoSupport.postEdit(new DeleteEdit((CySubNetwork) network, selectedNodes, selectedEdges, netViewMgr, vmMgr, eventHelper));
    // Delete the actual nodes and edges:
    network.removeEdges(selectedEdges);
    taskMonitor.setProgress(0.7);
    network.removeNodes(selectedNodes);
    taskMonitor.setProgress(0.9);
    // Update network views
    final Collection<CyNetworkView> views = netViewMgr.getNetworkViews(network);
    for (final CyNetworkView netView : views) netView.updateView();
    taskMonitor.setProgress(1.0);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ArrayList(java.util.ArrayList) CyEdge(org.cytoscape.model.CyEdge) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) HashSet(java.util.HashSet)

Example 39 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class NewNetworkSelectedNodesOnlyTaskFactoryTest method testObserver.

@Test
public void testObserver() throws Exception {
    NetworkViewTestSupport viewSupport = new NetworkViewTestSupport();
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetworkFactory networkFactory = networkSupport.getNetworkFactory();
    UndoSupport undoSupport = mock(UndoSupport.class);
    CyRootNetworkManager crnf = new CyRootNetworkManagerImpl();
    CyNetworkViewFactory cnvf = viewSupport.getNetworkViewFactory();
    CyNetworkManager netmgr = mock(CyNetworkManager.class);
    CyNetworkViewManager networkViewManager = mock(CyNetworkViewManager.class);
    CyNetworkNaming naming = mock(CyNetworkNaming.class);
    VisualMappingManager vmm = mock(VisualMappingManager.class);
    CyApplicationManager appManager = mock(CyApplicationManager.class);
    CyEventHelper eventHelper = mock(CyEventHelper.class);
    CyGroupManager groupMgr = mock(CyGroupManager.class);
    RenderingEngineManager renderingEngineMgr = mock(RenderingEngineManager.class);
    CyLayoutAlgorithm defLayout = mock(CyLayoutAlgorithm.class);
    CyLayoutAlgorithmManager layoutMgr = mock(CyLayoutAlgorithmManager.class);
    when(layoutMgr.getDefaultLayout()).thenReturn(defLayout);
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyLayoutAlgorithmManager.class)).thenReturn(layoutMgr);
    NewNetworkSelectedNodesOnlyTaskFactoryImpl factory = new NewNetworkSelectedNodesOnlyTaskFactoryImpl(undoSupport, crnf, cnvf, netmgr, networkViewManager, naming, vmm, appManager, eventHelper, groupMgr, renderingEngineMgr, serviceRegistrar);
    CyNetwork network = networkFactory.createNetwork();
    CyNode node = network.addNode();
    network.getRow(node).set(CyNetwork.SELECTED, true);
    TaskObserver observer = mock(TaskObserver.class);
    TaskMonitor taskMonitor = mock(TaskMonitor.class);
    TaskIterator iterator = factory.createTaskIterator(network);
    while (iterator.hasNext()) {
        Task t = iterator.next();
        t.run(taskMonitor);
        if (t instanceof ObservableTask)
            observer.taskFinished((ObservableTask) t);
    }
    verify(observer, times(1)).taskFinished(any(ObservableTask.class));
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) CyNetwork(org.cytoscape.model.CyNetwork) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) CyNode(org.cytoscape.model.CyNode) CyGroupManager(org.cytoscape.group.CyGroupManager) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) CyRootNetworkManagerImpl(org.cytoscape.model.internal.CyRootNetworkManagerImpl) NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyApplicationManager(org.cytoscape.application.CyApplicationManager) TaskObserver(org.cytoscape.work.TaskObserver) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyLayoutAlgorithmManager(org.cytoscape.view.layout.CyLayoutAlgorithmManager) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) Test(org.junit.Test)

Example 40 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class HideSelectedNodesTaskFactoryTest 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);
    HideSelectedNodesTaskFactoryImpl factory = new HideSelectedNodesTaskFactoryImpl(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)

Aggregations

UndoSupport (org.cytoscape.work.undo.UndoSupport)50 Test (org.junit.Test)21 Task (org.cytoscape.work.Task)19 CyEventHelper (org.cytoscape.event.CyEventHelper)15 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)15 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)12 HashSet (java.util.HashSet)10 TaskIterator (org.cytoscape.work.TaskIterator)10 CyNode (org.cytoscape.model.CyNode)9 ArrayList (java.util.ArrayList)8 CyEdge (org.cytoscape.model.CyEdge)7 CyNetwork (org.cytoscape.model.CyNetwork)7 CyNetworkView (org.cytoscape.view.model.CyNetworkView)7 CyRow (org.cytoscape.model.CyRow)6 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)6 Properties (java.util.Properties)5 CyNetworkManager (org.cytoscape.model.CyNetworkManager)5 CyApplicationManager (org.cytoscape.application.CyApplicationManager)4 CyGroupManager (org.cytoscape.group.CyGroupManager)4 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)4