use of org.cytoscape.property.CyProperty in project cytoscape-api by cytoscape.
the class CySessionTest method getFakeProps.
private Set<CyProperty<?>> getFakeProps() {
Set<CyProperty<?>> set = new HashSet<CyProperty<?>>();
Properties p = new Properties();
p.setProperty("key1", "value1");
p.setProperty("key2", "value2");
CyProperty<Properties> cyProps = new SimpleCyProperty<Properties>("test", p, Properties.class, CyProperty.SavePolicy.SESSION_FILE);
set.add(cyProps);
return set;
}
use of org.cytoscape.property.CyProperty 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.property.CyProperty in project cytoscape-impl by cytoscape.
the class CySessionManagerImpl method disposeCurrentSession.
@Override
public void disposeCurrentSession() {
logger.debug("Disposing current session...");
// Destroy network views
final CyNetworkViewManager nvMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
final Set<CyNetworkView> netViews = nvMgr.getNetworkViewSet();
for (final CyNetworkView nv : netViews) nvMgr.destroyNetworkView(nv);
nvMgr.reset();
// Destroy networks
final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
final Set<CyNetwork> networks = netMgr.getNetworkSet();
for (final CyNetwork n : networks) netMgr.destroyNetwork(n);
netMgr.reset();
// Destroy styles
logger.debug("Removing current visual styles...");
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
final VisualStyle defaultStyle = vmMgr.getDefaultVisualStyle();
final List<VisualStyle> allStyles = new ArrayList<>(vmMgr.getAllVisualStyles());
for (final VisualStyle vs : allStyles) {
if (!vs.equals(defaultStyle))
vmMgr.removeVisualStyle(vs);
}
// Destroy tables
final CyTableManager tblMgr = serviceRegistrar.getService(CyTableManager.class);
tblMgr.reset();
// Reset groups
serviceRegistrar.getService(CyGroupManager.class).reset();
// Unregister session properties
final Set<CyProperty<?>> cyPropsClone = getAllProperties();
for (CyProperty<?> cyProps : cyPropsClone) {
if (cyProps.getSavePolicy().equals(CyProperty.SavePolicy.SESSION_FILE)) {
serviceRegistrar.unregisterAllServices(cyProps);
sessionProperties.remove(cyProps.getName());
}
}
// Clear undo stack
serviceRegistrar.getService(UndoSupport.class).reset();
// Reset current table and rendering engine
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
appMgr.reset();
currentFileName = null;
disposed = true;
}
use of org.cytoscape.property.CyProperty in project cytoscape-impl by cytoscape.
the class ConfigDirPropertyWriter method handleEvent.
@Override
public void handleEvent(final CyShutdownEvent event) {
for (final Map.Entry<CyProperty<?>, Map<?, ?>> keyAndValue : configDirProperties.entrySet()) {
final String propertyName = (String) keyAndValue.getValue().get("cyPropertyName");
if (propertyName == null || propertyName.isEmpty())
continue;
final String propertyFileName;
if (propertyName.endsWith(".props"))
propertyFileName = propertyName;
else
propertyFileName = propertyName + ".props";
final CyApplicationConfiguration config = serviceRegistrar.getService(CyApplicationConfiguration.class);
final File outputFile = new File(config.getConfigurationDirectoryLocation(), propertyFileName);
final Properties props = (Properties) keyAndValue.getKey().getProperties();
try {
FileOutputStream out = new FileOutputStream(outputFile);
props.store(out, null);
out.close();
} catch (Exception e) {
logger.error("Error in wring properties file.");
}
}
}
use of org.cytoscape.property.CyProperty in project cytoscape-impl by cytoscape.
the class CyActivator method start.
public void start(BundleContext bc) {
CommandLineArgs args = getService(bc, CommandLineArgs.class);
CyVersion cyVersion = getService(bc, CyVersion.class);
CyShutdown cyShutdown = getService(bc, CyShutdown.class);
StreamUtil streamUtil = getService(bc, StreamUtil.class);
OpenSessionTaskFactory loadSession = getService(bc, OpenSessionTaskFactory.class);
LoadNetworkFileTaskFactory networkFileLoader = getService(bc, LoadNetworkFileTaskFactory.class);
LoadNetworkURLTaskFactory networkURLLoader = getService(bc, LoadNetworkURLTaskFactory.class);
LoadVizmapFileTaskFactory visualStylesLoader = getService(bc, LoadVizmapFileTaskFactory.class);
TaskManager<?, ?> taskManager = getService(bc, TaskManager.class);
CyServiceRegistrar registrar = getService(bc, CyServiceRegistrar.class);
CyProperty<Properties> props = (CyProperty<Properties>) getService(bc, CyProperty.class, "(cyPropertyName=cytoscape3.props)");
StartupConfig sc = new StartupConfig(props.getProperties(), streamUtil, loadSession, networkFileLoader, networkURLLoader, visualStylesLoader, taskManager, registrar);
Parser p = new Parser(args.getArgs(), cyShutdown, cyVersion, sc, props.getProperties());
sc.start();
}
Aggregations