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);
}
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);
}
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);
}
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));
}
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);
}
Aggregations