use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class CySessionManagerImpl method getCurrentSession.
@Override
public CySession getCurrentSession() {
// Apps who want to save anything to a session will have to listen for this event
// and will then be responsible for adding files through SessionAboutToBeSavedEvent.addAppFiles(..)
final SessionAboutToBeSavedEvent savingEvent = new SessionAboutToBeSavedEvent(this);
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.fireEvent(savingEvent);
final Set<CyNetwork> networks = getSerializableNetworks();
final CyNetworkViewManager nvMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
final Set<CyNetworkView> netViews = nvMgr.getNetworkViewSet();
// Visual Styles Map
final Map<CyNetworkView, String> stylesMap = new HashMap<>();
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
if (netViews != null) {
for (final CyNetworkView nv : netViews) {
final VisualStyle style = vmMgr.getVisualStyle(nv);
if (style != null)
stylesMap.put(nv, style.getTitle());
}
}
final Map<String, List<File>> appMap = savingEvent.getAppFileListMap();
final Set<CyTableMetadata> metadata = createTablesMetadata(networks);
final Set<VisualStyle> styles = vmMgr.getAllVisualStyles();
final Set<CyProperty<?>> props = getAllProperties();
// Build the session
final CySession sess = new CySession.Builder().properties(props).appFileListMap(appMap).tables(metadata).networks(networks).networkViews(netViews).visualStyles(styles).viewVisualStyleMap(stylesMap).build();
return sess;
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class CySessionManagerImpl method restoreCurrentVisualStyle.
private void restoreCurrentVisualStyle() {
// Make sure the current visual style is the one applied to the current network view
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.flushPayloadEvents();
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
final CyNetworkView cv = appMgr.getCurrentNetworkView();
if (cv != null) {
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
final VisualStyle style = vmMgr.getVisualStyle(cv);
if (style != null && !style.equals(vmMgr.getCurrentVisualStyle()))
vmMgr.setCurrentVisualStyle(style);
}
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class CySubNetworkCyTableManagerTest method setUp.
@Before
public void setUp() {
final CyEventHelper eh = new DummyCyEventHelper();
final CyNetworkNaming namingUtil = mock(CyNetworkNaming.class);
final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
final EquationCompiler compiler = new EquationCompilerImpl(new EquationParserImpl(serviceRegistrar));
final Interpreter interpreter = new InterpreterImpl();
when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eh);
when(serviceRegistrar.getService(CyNetworkNaming.class)).thenReturn(namingUtil);
when(serviceRegistrar.getService(EquationCompiler.class)).thenReturn(compiler);
when(serviceRegistrar.getService(Interpreter.class)).thenReturn(interpreter);
networkTableMgr = new CyNetworkTableManagerImpl();
networkManager = new CyNetworkManagerImpl(serviceRegistrar);
mgr = new CyTableManagerImpl(networkTableMgr, networkManager, serviceRegistrar);
CyTableFactoryImpl tableFactory = new CyTableFactoryImpl(eh, serviceRegistrar);
CyRootNetworkImpl baseNet = new CyRootNetworkImpl(eh, (CyTableManagerImpl) mgr, networkTableMgr, tableFactory, serviceRegistrar, true, SavePolicy.DO_NOT_SAVE);
// This is a different subnetwork and not "baseNetwork" in ArrayGraph.
goodNetwork = baseNet.addSubNetwork();
globalTable = tableFactory.createTable("test table", CyIdentifiable.SUID, Long.class, true, true);
networkManager.addNetwork(goodNetwork);
assertNotNull(globalTable);
assertNotNull(goodNetwork);
assertEquals(1, networkManager.getNetworkSet().size());
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class NewSessionTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
if (confirm && destroyCurrentSession) {
// Also checks destroyCurrentSession for backwards compatibility
tm.setTitle("Create New Session");
tm.setProgress(0.0);
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
final CySessionManager sessionManager = serviceRegistrar.getService(CySessionManager.class);
// Let everybody know the current session will be destroyed
eventHelper.fireEvent(new SessionAboutToBeLoadedEvent(this));
tm.setProgress(0.1);
// Dispose the current session before loading the new one
sessionManager.disposeCurrentSession();
tm.setProgress(0.2);
sessionManager.setCurrentSession(null, null);
tm.setProgress(1.0);
}
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class ApplyFilterTask method applyFilter.
public static void applyFilter(CyServiceRegistrar serviceRegistrar, CyNetwork network, NamedTransformer<CyNetwork, CyIdentifiable> transformer) {
CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
TransformerManager transformerManager = serviceRegistrar.getService(TransformerManager.class);
SelectUtils selectUtils = new SelectUtils(eventHelper);
// De-select all nodes and edges.
// Do this before running the filter because selection handlers can run in parallel with the filter.
selectUtils.setSelectedNodes(network, network.getNodeList(), false);
selectUtils.setSelectedEdges(network, network.getEdgeList(), false);
Sink sink = new Sink();
transformerManager.execute(network, transformer.getTransformers(), sink);
selectUtils.setSelectedNodes(network, sink.getNodes(), true);
}
Aggregations