Search in sources :

Example 1 with CyProperty

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;
}
Also used : SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) CyProperty(org.cytoscape.property.CyProperty) Properties(java.util.Properties) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) HashSet(java.util.HashSet)

Example 2 with CyProperty

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;
}
Also used : CySession(org.cytoscape.session.CySession) CyEventHelper(org.cytoscape.event.CyEventHelper) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) HashMap(java.util.HashMap) CyNetwork(org.cytoscape.model.CyNetwork) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) CyProperty(org.cytoscape.property.CyProperty) SessionAboutToBeSavedEvent(org.cytoscape.session.events.SessionAboutToBeSavedEvent) CyTableMetadata(org.cytoscape.model.CyTableMetadata) ArrayList(java.util.ArrayList) List(java.util.List) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 3 with CyProperty

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;
}
Also used : CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyApplicationManager(org.cytoscape.application.CyApplicationManager) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) CyProperty(org.cytoscape.property.CyProperty) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyTableManager(org.cytoscape.model.CyTableManager) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyGroupManager(org.cytoscape.group.CyGroupManager)

Example 4 with CyProperty

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.");
        }
    }
}
Also used : CyProperty(org.cytoscape.property.CyProperty) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) CyApplicationConfiguration(org.cytoscape.application.CyApplicationConfiguration) File(java.io.File)

Example 5 with CyProperty

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();
}
Also used : CyVersion(org.cytoscape.application.CyVersion) Properties(java.util.Properties) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) LoadVizmapFileTaskFactory(org.cytoscape.task.read.LoadVizmapFileTaskFactory) CyProperty(org.cytoscape.property.CyProperty) LoadNetworkURLTaskFactory(org.cytoscape.task.read.LoadNetworkURLTaskFactory) StreamUtil(org.cytoscape.io.util.StreamUtil) OpenSessionTaskFactory(org.cytoscape.task.read.OpenSessionTaskFactory) CommandLineArgs(org.cytoscape.cmdline.CommandLineArgs) LoadNetworkFileTaskFactory(org.cytoscape.task.read.LoadNetworkFileTaskFactory) CyShutdown(org.cytoscape.application.CyShutdown)

Aggregations

CyProperty (org.cytoscape.property.CyProperty)11 Properties (java.util.Properties)8 SimpleCyProperty (org.cytoscape.property.SimpleCyProperty)5 PropertyConfig (edu.ucsf.rbvi.clusterMaker2.internal.treeview.PropertyConfig)4 ArrayList (java.util.ArrayList)3 CyNetwork (org.cytoscape.model.CyNetwork)3 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)3 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)3 KnnViewFrame (edu.ucsf.rbvi.clusterMaker2.internal.treeview.KnnViewFrame)2 TreeViewFrame (edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeViewFrame)2 KnnViewModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.KnnViewModel)2 TreeViewModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.TreeViewModel)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 CyEventHelper (org.cytoscape.event.CyEventHelper)2 CyNetworkView (org.cytoscape.view.model.CyNetworkView)2 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 List (java.util.List)1