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());
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations