use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class GenerateNetworkViewsTask method setCurrentNetworkAndViewTask.
public void setCurrentNetworkAndViewTask(final CyNetwork network) {
final CyNetworkViewManager netViewManager = serviceRegistrar.getService(CyNetworkViewManager.class);
final List<CyNetworkView> views = new ArrayList<>(netViewManager.getNetworkViews(network));
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
boolean currentViewSet = false;
for (CyNetworkView v : views) {
if (v.getModel().equals(network)) {
applicationManager.setCurrentNetworkView(v);
currentViewSet = true;
break;
}
}
if (!currentViewSet)
applicationManager.setCurrentNetwork(network);
}
use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class LoadMultipleNetworksTask method init.
private void init() {
// otherwise let the reader's tunables handle it.
if (readers != null && readers.size() > 1) {
// Initialize column list
if (rootNetwork != null)
setTargetColumnList(getTargetColumns(rootNetwork));
else
setTargetColumnList(new ListSingleSelection<>());
// Initialize renderer list
final List<NetworkViewRenderer> renderers = new ArrayList<>();
NetworkViewRenderer defViewRenderer = null;
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
final Set<NetworkViewRenderer> rendererSet = applicationManager.getNetworkViewRendererSet();
// so the combo-box does not appear to the user, since there is nothing to select anyway.
if (rendererSet.size() > 1) {
renderers.addAll(rendererSet);
Collections.sort(renderers, new Comparator<NetworkViewRenderer>() {
@Override
public int compare(NetworkViewRenderer r1, NetworkViewRenderer r2) {
return r1.toString().compareToIgnoreCase(r2.toString());
}
});
}
defViewRenderer = applicationManager.getDefaultNetworkViewRenderer();
rendererList = new ListSingleSelection<>(renderers);
if (defViewRenderer != null && renderers.contains(defViewRenderer))
rendererList.setSelectedValue(defViewRenderer);
}
}
use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class ExportSelectedNetworkTaskFactoryImpl method createTaskIterator.
@Override
public TaskIterator createTaskIterator(File file) {
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
CyNetworkView view = applicationManager.getCurrentNetworkView();
if (view != null)
return getExportNetworkViewTaskFactory().createTaskIterator(view, file);
CyNetwork network = applicationManager.getCurrentNetwork();
if (network != null)
return getExportNetworkTaskFactory().createTaskIterator(network, file);
return null;
}
use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class OpenSessionCommandTask method changeCurrentSession.
private void changeCurrentSession(CySessionManager sessionManager, TaskMonitor tm) throws Exception {
final CySession newSession = reader.getSession();
if (newSession == null)
throw new NullPointerException("Session could not be read for file: " + file);
String fileName = file != null ? file.getAbsolutePath() : new URI(url).getPath().replace("/", "");
sessionManager.setCurrentSession(newSession, fileName);
// Set Current network: this is necessary to update GUI
final CyApplicationManager appManager = serviceRegistrar.getService(CyApplicationManager.class);
final RenderingEngine<CyNetwork> currentEngine = appManager.getCurrentRenderingEngine();
if (currentEngine != null)
appManager.setCurrentRenderingEngine(currentEngine);
tm.setProgress(1.0);
tm.setStatusMessage("Session file " + fileName + " successfully loaded.");
// Add this session file URL as the most recent file
if (file != null)
serviceRegistrar.getService(RecentlyOpenedTracker.class).add(file.toURI().toURL());
}
use of org.cytoscape.application.CyApplicationManager 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));
}
Aggregations