Author: mes
Date: 2011-12-22 16:43:20 -0800 (Thu, 22 Dec 2011)
New Revision: 27863
Removed:
core3/impl/trunk/application-impl/src/main/java/org/cytoscape/application/internal/CyApplicationCoreProperty.java
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyOperatingContextImpl.java
Modified:
core3/impl/trunk/application-impl/src/main/java/org/cytoscape/application/internal/CyActivator.java
core3/impl/trunk/property-impl/pom.xml
core3/impl/trunk/property-impl/src/main/java/org/cytoscape/property/internal/PropsReader.java
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogFactoryImpl.java
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogImpl.java
Log:
props cleanup
Modified:
core3/impl/trunk/application-impl/src/main/java/org/cytoscape/application/internal/CyActivator.java
===================================================================
---
core3/impl/trunk/application-impl/src/main/java/org/cytoscape/application/internal/CyActivator.java
2011-12-22 23:21:20 UTC (rev 27862)
+++
core3/impl/trunk/application-impl/src/main/java/org/cytoscape/application/internal/CyActivator.java
2011-12-23 00:43:20 UTC (rev 27863)
@@ -10,7 +10,6 @@
import org.cytoscape.application.internal.CyApplicationManagerImpl;
import org.cytoscape.application.internal.CyApplicationConfigurationImpl;
-import org.cytoscape.application.internal.CyApplicationCoreProperty;
import org.cytoscape.application.internal.ShutdownHandler;
import org.cytoscape.application.internal.CyVersionImpl;
@@ -43,7 +42,7 @@
CyApplicationManagerImpl cyApplicationManager = new
CyApplicationManagerImpl(cyEventHelperServiceRef,cyNetworkManagerServiceRef,cyNetworkViewManagerServiceRef);
ShutdownHandler cytoscapeShutdown = new
ShutdownHandler(cyEventHelperServiceRef);
CyApplicationConfigurationImpl cyApplicationConfiguration = new
CyApplicationConfigurationImpl();
- CyProperty cyApplicationCoreProperty =
getService(bc,CyProperty.class,"(cyPropertyName=cytoscape3.props)");
+ CyProperty cyApplicationCoreProperty =
getService(bc,CyProperty.class,"(cyPropertyName=cytoscape3.props)");
CyVersionImpl cytoscapeVersion = new
CyVersionImpl(cyApplicationCoreProperty);
registerService(bc,cyApplicationManager,CyApplicationManager.class, new
Properties());
@@ -53,13 +52,6 @@
registerAllServices(bc,cytoscapeVersion, new Properties());
registerAllServices(bc,cyApplicationConfiguration, new
Properties());
- Properties cyApplicationCorePropertyProps = new Properties();
-
cyApplicationCorePropertyProps.setProperty("cyPropertyName","cytoscape3.props");
-
cyApplicationCorePropertyProps.setProperty("serviceType","property");
- registerAllServices(bc,cyApplicationCoreProperty,
cyApplicationCorePropertyProps);
-
-
-
}
}
Deleted:
core3/impl/trunk/application-impl/src/main/java/org/cytoscape/application/internal/CyApplicationCoreProperty.java
===================================================================
---
core3/impl/trunk/application-impl/src/main/java/org/cytoscape/application/internal/CyApplicationCoreProperty.java
2011-12-22 23:21:20 UTC (rev 27862)
+++
core3/impl/trunk/application-impl/src/main/java/org/cytoscape/application/internal/CyApplicationCoreProperty.java
2011-12-23 00:43:20 UTC (rev 27863)
@@ -1,107 +0,0 @@
-package org.cytoscape.application.internal;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-import org.cytoscape.application.CyApplicationConfiguration;
-import org.cytoscape.property.CyProperty;
-import org.cytoscape.session.CySession;
-import org.cytoscape.session.events.SessionLoadedEvent;
-import org.cytoscape.session.events.SessionLoadedListener;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class CyApplicationCoreProperty implements CyProperty<Properties>,
SessionLoadedListener {
- private static final Logger logger =
LoggerFactory.getLogger(CyApplicationCoreProperty.class);
-
- // This is in the resource file (jar)
- private static final String DEF_PROP_FILE_NAME = "cytoscape3.props";
-
- private Properties props;
-
- /**
- * Creates a new PropsReader object.
- *
- */
- public CyApplicationCoreProperty(final CyApplicationConfiguration
config) {
-
- InputStream is = null;
-
- // Load default Cytoscape properties
- Properties defaultProps = new Properties();
-
- is =
this.getClass().getClassLoader().getResourceAsStream(DEF_PROP_FILE_NAME);
- try {
- defaultProps.load(is);
- } catch (IOException e1) {
- logger.warn("Could not read core property. Use empty
one.", e1);
- }
-
- //Load existing properties from config directory if any
- final File propFile = new
File(config.getConfigurationDirectoryLocation(), "cytoscape3.props");
-
- props = new Properties();
-
- try {
- if (propFile.exists()) {
- is = new FileInputStream(propFile);
- props.load(is);
- }
- } catch (Exception e) {
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException ioe) {
- }
- is = null;
- }
- }
-
- if(props.size() == 0){
- // Properties does not exist in config directory, use
the default properties
- props = defaultProps;
- }
- else {
- // Properties already existed, merge default properties
with existing properties
- Object[] keys = defaultProps.keySet().toArray();
- for (Object key: keys){
- if (!props.containsKey(key)){
- props.setProperty((String)key,
defaultProps.getProperty((String)key));
- }
- }
- }
- }
-
- @Override
- public CyProperty.SavePolicy getSavePolicy() {
- return CyProperty.SavePolicy.SESSION_FILE_AND_CONFIG_DIR;
- }
-
- @Override
- public Properties getProperties() {
- return props;
- }
-
- @Override
- public void handleEvent(SessionLoadedEvent e) {
- logger.debug("Updating Properties from loaded session...");
-
- Properties newProps = null;
- CySession sess = e.getLoadedSession();
-
- if (sess != null)
- newProps = sess.getCytoscapeProperties();
- else
- logger.warn("Loaded session is null.");
-
- if (newProps == null) {
- logger.warn("Could not get new properties from loaded
session - using empty properties.");
- newProps = new Properties();
- }
-
- this.props = newProps;
- }
-}
Modified: core3/impl/trunk/property-impl/pom.xml
===================================================================
--- core3/impl/trunk/property-impl/pom.xml 2011-12-22 23:21:20 UTC (rev
27862)
+++ core3/impl/trunk/property-impl/pom.xml 2011-12-23 00:43:20 UTC (rev
27863)
@@ -76,6 +76,10 @@
<artifactId>session-api</artifactId>
</dependency>
<dependency>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>application-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Modified:
core3/impl/trunk/property-impl/src/main/java/org/cytoscape/property/internal/PropsReader.java
===================================================================
---
core3/impl/trunk/property-impl/src/main/java/org/cytoscape/property/internal/PropsReader.java
2011-12-22 23:21:20 UTC (rev 27862)
+++
core3/impl/trunk/property-impl/src/main/java/org/cytoscape/property/internal/PropsReader.java
2011-12-23 00:43:20 UTC (rev 27863)
@@ -3,12 +3,15 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.File;
+import java.io.FileInputStream;
import java.util.Properties;
import org.cytoscape.property.CyProperty;
import org.cytoscape.session.CySession;
import org.cytoscape.session.events.SessionLoadedEvent;
import org.cytoscape.session.events.SessionLoadedListener;
+import static org.cytoscape.application.CyApplicationConfiguration.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -20,21 +23,45 @@
/**
* Creates a new PropsReader object.
*/
- public PropsReader(String resourceLocation) {
- InputStream is = null;
+ public PropsReader(String propsName) {
+ try {
+ props = new Properties();
+ readDefaultFromJar(props,propsName);
+ readLocalModifications(props,propsName);
+ } catch (Exception e) {
+ logger.warn("Error reading properties file - using
empty intance.", e);
+ props = new Properties();
+ }
+ }
+ private void readLocalModifications(Properties props, String propsName)
throws Exception {
+ InputStream is = null;
try {
- if (resourceLocation == null)
- throw new
NullPointerException("resourceLocation is null");
+ final File configDir = new
File(System.getProperty("user.home"), DEFAULT_CONFIG_DIR);
+ final File localPropsFile = new File(configDir,propsName);
- is =
this.getClass().getClassLoader().getResourceAsStream(resourceLocation);
+ if (localPropsFile.exists()) {
+ is = new FileInputStream(localPropsFile);
+ props.load(is);
+ is.close();
+ }
+ } finally {
+ if (is != null) {
+ try { is.close(); } catch (IOException ioe) {}
+ is = null;
+ }
+ }
+ }
- props = new Properties();
+ private void readDefaultFromJar(Properties props, String propsName)
throws Exception {
+ InputStream is = null;
+ try {
+ if (propsName == null)
+ throw new NullPointerException("propsName is
null");
+
+ is =
this.getClass().getClassLoader().getResourceAsStream(propsName);
+
props.load(is);
-
- } catch (Exception e) {
- logger.warn("Could not read properties file - using
empty intance.", e);
- props = new Properties();
} finally {
if (is != null) {
try { is.close(); } catch (IOException ioe) {}
@@ -45,7 +72,7 @@
@Override
public CyProperty.SavePolicy getSavePolicy() {
- return CyProperty.SavePolicy.DO_NOT_SAVE;
+ return CyProperty.SavePolicy.CONFIG_DIR;
}
@Override
Modified:
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
===================================================================
---
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
2011-12-22 23:21:20 UTC (rev 27862)
+++
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
2011-12-23 00:43:20 UTC (rev 27863)
@@ -194,12 +194,9 @@
ConfigDirPropertyWriter configDirPropertyWriter = new
ConfigDirPropertyWriter(dialogTaskManagerServiceRef,
propertyWriterManagerRef,
cyApplicationConfigurationServiceRef);
- CyOperatingContextImpl cyOperatingContext = new
CyOperatingContextImpl(cytoscapePropertiesServiceRef,
-
cyApplicationConfigurationServiceRef);
CyHelpBrokerImpl cyHelpBroker = new CyHelpBrokerImpl();
AboutDialogFactoryImpl aboutDialogFactory = new
AboutDialogFactoryImpl(openBrowserServiceRef);
- PreferencesDialogFactoryImpl preferencesDialogFactory = new
PreferencesDialogFactoryImpl(cyOperatingContext,
-
cyEventHelperServiceRef);
+ PreferencesDialogFactoryImpl preferencesDialogFactory = new
PreferencesDialogFactoryImpl(cyEventHelperServiceRef);
BookmarkDialogFactoryImpl bookmarkDialogFactory = new
BookmarkDialogFactoryImpl(bookmarkServiceRef,
bookmarksUtilServiceRef);
CytoscapeMenuBar cytoscapeMenuBar = new CytoscapeMenuBar();
Deleted:
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyOperatingContextImpl.java
===================================================================
---
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyOperatingContextImpl.java
2011-12-22 23:21:20 UTC (rev 27862)
+++
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyOperatingContextImpl.java
2011-12-23 00:43:20 UTC (rev 27863)
@@ -1,112 +0,0 @@
-/*
- File: CyOpertatingContextImpl.java
-
- Copyright (c) 2006, 2011, The Cytoscape Consortium (www.cytoscape.org)
-
- This library is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of the License, or
- any later version.
-
- This library is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
- MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
- documentation provided hereunder is on an "as is" basis, and the
- Institute for Systems Biology and the Whitehead Institute
- have no obligations to provide maintenance, support,
- updates, enhancements or modifications. In no event shall the
- Institute for Systems Biology and the Whitehead Institute
- be liable to any party for direct, indirect, special,
- incidental or consequential damages, including lost profits, arising
- out of the use of this software and its documentation, even if the
- Institute for Systems Biology and the Whitehead Institute
- have been advised of the possibility of such damage. See
- the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this library; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-*/
-package org.cytoscape.internal;
-
-
-import java.util.Properties;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import org.cytoscape.application.CyApplicationConfiguration;
-import org.cytoscape.property.CyProperty;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Basic access to Cytoscape's operating context.
- */
-// TODO This is currently only used to store properties when saved in the
preferences
-// dialog - this needs to be supported more generally on an application level,
perhaps
-// on a shutdown event?
-public class CyOperatingContextImpl {
- public static final String PROPS = "cytoscape3.props";
-
- private static final Logger logger =
LoggerFactory.getLogger(CyOperatingContextImpl.class);
-
- private CyProperty<Properties> props;
- private final CyApplicationConfiguration config;
-
- public CyOperatingContextImpl(CyProperty<Properties> props, final
CyApplicationConfiguration config) {
- if ( props == null )
- throw new NullPointerException("Cytoscape Properties is
null");
- if(config == null)
- throw new NullPointerException("Application Config is
missing.");
-
- this.props = props;
- this.config = config;
-
- loadLocalProps();
- }
-
- private void loadLocalProps() {
- try {
- File vmp = getConfigFile(PROPS);
-
- if (vmp != null)
- props.getProperties().load(new
FileInputStream(vmp));
- else
- logger.warn("couldn't read " + PROPS + " from "
+ config.getConfigurationDirectoryLocation());
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- }
-
- /**
- * Returns cytoscape.props.
- */
- // TODO Should we be returning a copy here to keep thing synchronized or
- // do we want just one properties object?
- public Properties getProperties() {
- return props.getProperties();
- }
-
-
- /**
- * Returns the specified file if it's found in the config directory.
- */
- public File getConfigFile(String file_name) {
- try {
- File file = new
File(config.getConfigurationDirectoryLocation(), file_name);
-
- if (file.createNewFile())
- logger.warn("Config file: " + file + "
created.");
-
- return file;
- } catch (Exception e) {
- logger.warn("error getting config file:" + file_name);
- }
-
- return null;
- }
-}
-
Modified:
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogFactoryImpl.java
===================================================================
---
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogFactoryImpl.java
2011-12-22 23:21:20 UTC (rev 27862)
+++
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogFactoryImpl.java
2011-12-23 00:43:20 UTC (rev 27863)
@@ -41,7 +41,6 @@
import java.util.Properties;
import org.cytoscape.event.CyEventHelper;
-import org.cytoscape.internal.CyOperatingContextImpl;
import org.cytoscape.property.CyProperty;
import org.cytoscape.property.bookmark.Bookmarks;
import org.cytoscape.property.bookmark.BookmarksUtil;
@@ -51,10 +50,8 @@
public class PreferencesDialogFactoryImpl {
private CyEventHelper eh;
- private CyOperatingContextImpl coc;
- public PreferencesDialogFactoryImpl(CyOperatingContextImpl coc,
CyEventHelper eh) {
- this.coc = coc;
+ public PreferencesDialogFactoryImpl(CyEventHelper eh) {
this.eh = eh;
}
Modified:
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogImpl.java
===================================================================
---
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogImpl.java
2011-12-22 23:21:20 UTC (rev 27862)
+++
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogImpl.java
2011-12-23 00:43:20 UTC (rev 27863)
@@ -71,7 +71,6 @@
import org.cytoscape.application.swing.events.PreferencesUpdatedEvent;
import org.cytoscape.event.CyEventHelper;
-import org.cytoscape.internal.CyOperatingContextImpl;
import org.cytoscape.property.SimpleCyProperty;
import org.cytoscape.property.CyProperty;
import org.cytoscape.property.bookmark.Bookmarks;
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.