Search in sources :

Example 1 with SimpleCyProperty

use of org.cytoscape.property.SimpleCyProperty in project cytoscape-impl by cytoscape.

the class DownloadSitesManagerTest method testSaveLoad.

@Test
public void testSaveLoad() {
    // Create new DownloadSitesManager
    Properties properties = new Properties();
    CyProperty<Properties> cyProperty = new SimpleCyProperty<Properties>("TestProperties", properties, properties.getClass(), DO_NOT_SAVE);
    DownloadSitesManager downloadSitesManager = new DownloadSitesManager(cyProperty);
    // Check initially empty, and loading empty list
    assertEquals(0, downloadSitesManager.getDownloadSites().size());
    downloadSitesManager.loadDownloadSites();
    assertEquals(0, downloadSitesManager.getDownloadSites().size());
    // Insert 1, save, check result
    DownloadSite downloadSite = new DownloadSite();
    downloadSite.setSiteName("test1");
    downloadSite.setSiteUrl("http://test1");
    downloadSitesManager.getDownloadSites().add(downloadSite);
    downloadSitesManager.saveDownloadSites();
    assertEquals(1, downloadSitesManager.getDownloadSites().size());
    assertEquals("1", properties.getProperty(DownloadSitesManager.DOWNLOAD_SITES_COUNT_KEY));
    assertEquals("test1", properties.getProperty(DownloadSitesManager.DOWNLOAD_SITE_NAME_KEY_PREFIX + "1"));
    assertEquals("http://test1", properties.getProperty(DownloadSitesManager.DOWNLOAD_SITE_URL_KEY_PREFIX + "1"));
    assertNull(properties.getProperty(DownloadSitesManager.DOWNLOAD_SITE_NAME_KEY_PREFIX + "2"));
    assertNull(properties.getProperty(DownloadSitesManager.DOWNLOAD_SITE_URL_KEY_PREFIX + "2"));
    // Insert another, save, check
    downloadSite = new DownloadSite();
    downloadSite.setSiteName("test2");
    downloadSite.setSiteUrl("http://test2");
    downloadSitesManager.getDownloadSites().add(downloadSite);
    downloadSitesManager.saveDownloadSites();
    assertEquals(2, downloadSitesManager.getDownloadSites().size());
    assertEquals("2", properties.getProperty(DownloadSitesManager.DOWNLOAD_SITES_COUNT_KEY));
    // Old saved value should still be there
    assertEquals("test1", properties.getProperty(DownloadSitesManager.DOWNLOAD_SITE_NAME_KEY_PREFIX + "1"));
    assertEquals("http://test1", properties.getProperty(DownloadSitesManager.DOWNLOAD_SITE_URL_KEY_PREFIX + "1"));
    // Values should be in order of insertion
    assertEquals("test2", properties.getProperty(DownloadSitesManager.DOWNLOAD_SITE_NAME_KEY_PREFIX + "2"));
    assertEquals("http://test2", properties.getProperty(DownloadSitesManager.DOWNLOAD_SITE_URL_KEY_PREFIX + "2"));
    assertNull(properties.getProperty(DownloadSitesManager.DOWNLOAD_SITE_NAME_KEY_PREFIX + "3"));
    assertNull(properties.getProperty(DownloadSitesManager.DOWNLOAD_SITE_URL_KEY_PREFIX + "3"));
    // Test load
    // Clear sites
    downloadSitesManager.getDownloadSites().clear();
    assertEquals(0, downloadSitesManager.getDownloadSites().size());
    assertTrue(downloadSitesManager.loadDownloadSites());
    assertEquals(2, downloadSitesManager.getDownloadSites().size());
    assertEquals("test1", downloadSitesManager.getDownloadSites().get(0).getSiteName());
    assertEquals("http://test1", downloadSitesManager.getDownloadSites().get(0).getSiteUrl());
    assertEquals("test2", downloadSitesManager.getDownloadSites().get(1).getSiteName());
    assertEquals("http://test2", downloadSitesManager.getDownloadSites().get(1).getSiteUrl());
}
Also used : Properties(java.util.Properties) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) Test(org.junit.Test)

Example 2 with SimpleCyProperty

use of org.cytoscape.property.SimpleCyProperty in project cytoscape-impl by cytoscape.

the class Cy2SessionReaderImpl method extractProperties.

private void extractProperties(InputStream is, String entryName) throws Exception {
    CyPropertyReader reader = propertyReaderMgr.getReader(is, entryName);
    if (reader == null)
        return;
    reader.run(taskMonitor);
    final Properties props = (Properties) reader.getProperty();
    final Properties newProps = new Properties();
    if (props != null) {
        // Only add properties that should have the SESSION_FILE save policy
        for (String key : props.stringPropertyNames()) {
            if (isSessionProperty(key)) {
                String value = props.getProperty(key);
                newProps.put(key, value);
            }
        }
        final CyProperty<Properties> cyProps = new SimpleCyProperty<Properties>("session", newProps, Properties.class, CyProperty.SavePolicy.SESSION_FILE);
        properties.add(cyProps);
    }
}
Also used : CyPropertyReader(org.cytoscape.io.read.CyPropertyReader) Properties(java.util.Properties) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty)

Example 3 with SimpleCyProperty

use of org.cytoscape.property.SimpleCyProperty in project cytoscape-impl by cytoscape.

the class Cy2SessionReaderImpl method extractBookmarks.

private void extractBookmarks(InputStream is, String entryName) throws Exception {
    CyPropertyReader reader = propertyReaderMgr.getReader(is, entryName);
    reader.run(taskMonitor);
    final Bookmarks bookmarks = (Bookmarks) reader.getProperty();
    final CyProperty<Bookmarks> cyProps = new SimpleCyProperty<Bookmarks>("bookmarks", bookmarks, Bookmarks.class, CyProperty.SavePolicy.SESSION_FILE);
    properties.add(cyProps);
}
Also used : Bookmarks(org.cytoscape.property.bookmark.Bookmarks) CyPropertyReader(org.cytoscape.io.read.CyPropertyReader) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty)

Example 4 with SimpleCyProperty

use of org.cytoscape.property.SimpleCyProperty in project cytoscape-impl by cytoscape.

the class Cy3SessionReaderImpl method extractProperties.

private void extractProperties(InputStream is, String entryName) throws Exception {
    CyPropertyReader reader = propertyReaderMgr.getReader(is, entryName);
    if (reader == null)
        return;
    reader.run(taskMonitor);
    CyProperty<?> cyProps = null;
    Object obj = reader.getProperty();
    if (obj instanceof Properties) {
        Properties props = (Properties) obj;
        Matcher matcher = PROPERTIES_PATTERN.matcher(entryName);
        if (matcher.matches()) {
            String propsName = matcher.group(2);
            if (propsName != null) {
                cyProps = new SimpleCyProperty<>(propsName, props, Properties.class, CyProperty.SavePolicy.SESSION_FILE);
            }
        }
    } else if (obj instanceof Bookmarks) {
        cyProps = new SimpleCyProperty<>("bookmarks", (Bookmarks) obj, Bookmarks.class, CyProperty.SavePolicy.SESSION_FILE);
    } else {
        // TODO: get name and create the CyProperty for unknown types
        logger.error("Cannot extract CyProperty name from: " + entryName);
    }
    if (cyProps != null)
        properties.add(cyProps);
}
Also used : Bookmarks(org.cytoscape.property.bookmark.Bookmarks) Matcher(java.util.regex.Matcher) CyPropertyReader(org.cytoscape.io.read.CyPropertyReader) Properties(java.util.Properties) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty)

Example 5 with SimpleCyProperty

use of org.cytoscape.property.SimpleCyProperty in project cytoscape-impl by cytoscape.

the class StartupConfig method start.

public void start() {
    // set the properties
    // no need to do this in a task since it's so fast
    // globalProps.putAll(localProps);
    CyProperty<Properties> commandline = new SimpleCyProperty<Properties>("commandline", localProps, Properties.class, CyProperty.SavePolicy.DO_NOT_SAVE);
    Properties cmdlnProps = new Properties();
    cmdlnProps.setProperty("cyPropertyName", "commandline.props");
    registrar.registerService(commandline, CyProperty.class, cmdlnProps);
    // on the command line.
    if (!taskStart)
        return;
    // Since we've set command line args we presumably
    // don't want to see the welcome screen, so we
    // disable it here.
    globalProps.setProperty("tempHideWelcomeScreen", "true");
    ArrayList<TaskIterator> taskIteratorList = new ArrayList<TaskIterator>();
    if (sessionName != null) {
        taskIteratorList.add(loadSession.createTaskIterator(sessionName));
    } else {
        for (File network : networkFiles) taskIteratorList.add(networkFileLoader.createTaskIterator(network));
        for (URL network : networkURLs) taskIteratorList.add(networkURLLoader.loadCyNetworks(network));
        for (File vizmap : vizmapFiles) taskIteratorList.add(visualStylesLoader.createTaskIterator(vizmap));
    }
    Task initTask = new DummyTask();
    TaskIterator taskIterator = new TaskIterator(taskIteratorList.size(), initTask);
    for (int i = taskIteratorList.size() - 1; i >= 0; i--) {
        TaskIterator ti = taskIteratorList.get(i);
        taskIterator.insertTasksAfter(initTask, ti);
    }
    taskManager.execute(taskIterator);
}
Also used : Task(org.cytoscape.work.Task) AbstractTask(org.cytoscape.work.AbstractTask) TaskIterator(org.cytoscape.work.TaskIterator) ArrayList(java.util.ArrayList) Properties(java.util.Properties) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) File(java.io.File) URL(java.net.URL)

Aggregations

SimpleCyProperty (org.cytoscape.property.SimpleCyProperty)10 Properties (java.util.Properties)9 StreamUtilImpl (org.cytoscape.io.internal.util.StreamUtilImpl)4 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)4 Before (org.junit.Before)4 HashSet (java.util.HashSet)3 CyPropertyReader (org.cytoscape.io.read.CyPropertyReader)3 Bookmarks (org.cytoscape.property.bookmark.Bookmarks)2 TaskIterator (org.cytoscape.work.TaskIterator)2 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 CyApplicationManager (org.cytoscape.application.CyApplicationManager)1 NetworkViewRenderer (org.cytoscape.application.NetworkViewRenderer)1 NetworkViewTestSupport (org.cytoscape.ding.NetworkViewTestSupport)1 GroupTestSupport (org.cytoscape.group.GroupTestSupport)1 ReadUtils (org.cytoscape.io.internal.util.ReadUtils)1 CyTableManager (org.cytoscape.model.CyTableManager)1 NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)1