Author: rozagh
Date: 2012-06-07 17:11:23 -0700 (Thu, 07 Jun 2012)
New Revision: 29502
Modified:
core3/impl/trunk/gui-cmdline-parser-impl/src/main/java/org/cytoscape/cmdline/gui/internal/CyActivator.java
core3/impl/trunk/gui-cmdline-parser-impl/src/main/java/org/cytoscape/cmdline/gui/internal/StartupConfig.java
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/CyActivator.java
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/EdgeLinkoutTaskFactory.java
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/LinkOut.java
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/NodeLinkoutTaskFactory.java
Log:
fixes #1014 added a cyproperty for commandline properties. Enabled updating
linkouts from command line and preferences dialog.
Modified:
core3/impl/trunk/gui-cmdline-parser-impl/src/main/java/org/cytoscape/cmdline/gui/internal/CyActivator.java
===================================================================
---
core3/impl/trunk/gui-cmdline-parser-impl/src/main/java/org/cytoscape/cmdline/gui/internal/CyActivator.java
2012-06-07 21:19:32 UTC (rev 29501)
+++
core3/impl/trunk/gui-cmdline-parser-impl/src/main/java/org/cytoscape/cmdline/gui/internal/CyActivator.java
2012-06-08 00:11:23 UTC (rev 29502)
@@ -6,6 +6,7 @@
import org.cytoscape.application.CyShutdown;
import org.cytoscape.io.util.StreamUtil;
import org.cytoscape.service.util.AbstractCyActivator;
+import org.cytoscape.service.util.CyServiceRegistrar;
import org.cytoscape.task.read.LoadNetworkFileTaskFactory;
import org.cytoscape.task.read.LoadNetworkURLTaskFactory;
import org.cytoscape.task.read.LoadVizmapFileTaskFactory;
@@ -31,10 +32,11 @@
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);
+ StartupConfig sc = new
StartupConfig(props.getProperties(),streamUtil, loadSession, networkFileLoader,
networkURLLoader, visualStylesLoader, taskManager, registrar);
Parser p = new Parser(args.getArgs(), cyShutdown, cyVersion,
sc,props.getProperties());
Modified:
core3/impl/trunk/gui-cmdline-parser-impl/src/main/java/org/cytoscape/cmdline/gui/internal/StartupConfig.java
===================================================================
---
core3/impl/trunk/gui-cmdline-parser-impl/src/main/java/org/cytoscape/cmdline/gui/internal/StartupConfig.java
2012-06-07 21:19:32 UTC (rev 29501)
+++
core3/impl/trunk/gui-cmdline-parser-impl/src/main/java/org/cytoscape/cmdline/gui/internal/StartupConfig.java
2012-06-08 00:11:23 UTC (rev 29502)
@@ -33,6 +33,10 @@
import org.cytoscape.application.CyShutdown;
import org.cytoscape.application.CyVersion;
import org.cytoscape.io.util.StreamUtil;
+import org.cytoscape.model.CyTable.SavePolicy;
+import org.cytoscape.property.CyProperty;
+import org.cytoscape.property.SimpleCyProperty;
+import org.cytoscape.service.util.CyServiceRegistrar;
import org.cytoscape.task.read.LoadTableFileTaskFactory;
import org.cytoscape.task.read.LoadTableURLTaskFactory;
import org.cytoscape.task.read.LoadNetworkFileTaskFactory;
@@ -76,6 +80,9 @@
private LoadTableFileTaskFactory attributesFileLoader;
private final TaskManager taskManager;
+
+ private final CyServiceRegistrar registrar;
+
private File sessionName;
private ArrayList<File> networkFiles;
private ArrayList<URL> networkURLs;
@@ -85,7 +92,8 @@
public StartupConfig(Properties globalProps, StreamUtil streamUtil,
OpenSessionTaskFactory loadSession,
LoadNetworkFileTaskFactory networkFileLoader,
- LoadNetworkURLTaskFactory networkURLLoader,
LoadVizmapFileTaskFactory visualStylesLoader, TaskManager taskManager) {
+ LoadNetworkURLTaskFactory networkURLLoader,
LoadVizmapFileTaskFactory visualStylesLoader, TaskManager taskManager,
+ CyServiceRegistrar registrar) {
this.globalProps = globalProps;
this.streamUtil = streamUtil;
this.loadSession = loadSession;
@@ -93,6 +101,8 @@
this.networkURLLoader = networkURLLoader;
this.visualStylesLoader = visualStylesLoader;
this.taskManager = taskManager;
+
+ this.registrar = registrar;
networkFiles= new ArrayList<File>();
networkURLs = new ArrayList<URL>();
vizmapFiles = new ArrayList<File>();
@@ -214,8 +224,14 @@
public void start() {
// set the properties
// no need to do this in a task since it's so fast
- globalProps.putAll(localProps);
-
+ //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);
+
// Only proceed if we've specified tasks for execution
// on the command line.
if ( !taskStart )
Modified:
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/CyActivator.java
===================================================================
---
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/CyActivator.java
2012-06-07 21:19:32 UTC (rev 29501)
+++
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/CyActivator.java
2012-06-08 00:11:23 UTC (rev 29502)
@@ -6,6 +6,7 @@
import org.cytoscape.service.util.CyServiceRegistrar;
import org.cytoscape.linkout.internal.LinkOut;
import org.cytoscape.property.CyProperty;
+import org.cytoscape.property.PropertyUpdatedListener;
import org.cytoscape.service.util.AbstractCyActivator;
import org.osgi.framework.BundleContext;
@@ -38,6 +39,9 @@
Properties linkoutPropsProps = new Properties();
linkoutPropsProps.setProperty("cyPropertyName","linkout");
registerService(bc,linkoutProps,CyProperty.class,
linkoutPropsProps);
+ registerService(bc, linkout, PropertyUpdatedListener.class,
linkoutPropsProps);
+ registerServiceListener(bc, linkout, "addCommanLineLinkOut",
"removeCommanLineLinkOut", CyProperty.class);
+
}
}
Modified:
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/EdgeLinkoutTaskFactory.java
===================================================================
---
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/EdgeLinkoutTaskFactory.java
2012-06-07 21:19:32 UTC (rev 29501)
+++
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/EdgeLinkoutTaskFactory.java
2012-06-08 00:11:23 UTC (rev 29502)
@@ -11,7 +11,7 @@
public class EdgeLinkoutTaskFactory extends AbstractEdgeViewTaskFactory {
- private final String link;
+ private String link;
private final OpenBrowser browser;
public EdgeLinkoutTaskFactory(OpenBrowser browser, String link) {
@@ -23,4 +23,11 @@
public TaskIterator createTaskIterator(View<CyEdge> edgeView,
CyNetworkView netView) {
return new TaskIterator(new LinkoutTask(link, browser,
netView.getModel(), edgeView.getModel().getSource(),
edgeView.getModel().getTarget(), edgeView.getModel()));
}
+
+ public String getLink(){
+ return link;
+ }
+ public void setLink (String link){
+ this.link = link;
+ }
}
Modified:
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/LinkOut.java
===================================================================
---
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/LinkOut.java
2012-06-07 21:19:32 UTC (rev 29501)
+++
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/LinkOut.java
2012-06-08 00:11:23 UTC (rev 29502)
@@ -41,6 +41,8 @@
import org.cytoscape.application.swing.CyNodeViewContextMenuFactory;
import org.cytoscape.property.CyProperty;
+import org.cytoscape.property.PropertyUpdatedEvent;
+import org.cytoscape.property.PropertyUpdatedListener;
import org.cytoscape.service.util.CyServiceRegistrar;
@@ -50,13 +52,20 @@
import org.cytoscape.util.swing.OpenBrowser;
import org.cytoscape.work.SynchronousTaskManager;
+import org.cytoscape.work.TaskFactory;
import java.io.File;
import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import javax.swing.SwingUtilities;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -78,7 +87,7 @@
*
url.Pubmed=http\://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd\=Search&db\=PubMed&term\=%ID%
*
*/
-public class LinkOut {
+public class LinkOut implements PropertyUpdatedListener{
private static final Logger logger =
LoggerFactory.getLogger(LinkOut.class);
@@ -92,7 +101,12 @@
private final CyApplicationConfiguration config;
private final SynchronousTaskManager synTaskManager;
+ private final Map<String, NodeLinkoutTaskFactory> propKey2NodeVTF;
+ private final Map<String, EdgeLinkoutTaskFactory> propKey2EdgeVTF;
+ private final Map<String, NodeLinkoutTaskFactory> cpropKey2NodeVTF;
+ private final Map<String, EdgeLinkoutTaskFactory> cpropKey2EdgeVTF;
+
/**
* Creates a new LinkOut object.
*
@@ -108,7 +122,13 @@
this.browser = browser;
this.config = config;
this.synTaskManager = synTaskManager;
-
+
+ propKey2EdgeVTF = new HashMap<String, EdgeLinkoutTaskFactory>();
+ propKey2NodeVTF = new HashMap<String, NodeLinkoutTaskFactory>();
+
+ cpropKey2EdgeVTF = new HashMap<String,
EdgeLinkoutTaskFactory>();
+ cpropKey2NodeVTF = new HashMap<String,
NodeLinkoutTaskFactory>();
+
readLocalProperties();
addStaticNodeLinks();
@@ -147,6 +167,7 @@
}
NodeViewTaskFactory evtf = new
NodeLinkoutTaskFactory(browser,url);
registrar.registerService(evtf,
NodeViewTaskFactory.class, dict);
+ propKey2NodeVTF.put(propKey,
(NodeLinkoutTaskFactory) evtf);
}
} catch (Exception e) {
logger.warn("Problem processing node URLs", e);
@@ -165,6 +186,7 @@
}
EdgeViewTaskFactory evtf = new
EdgeLinkoutTaskFactory(browser,url);
registrar.registerService(evtf,
EdgeViewTaskFactory.class, dict);
+ propKey2EdgeVTF.put(propKey,
(EdgeLinkoutTaskFactory) evtf);
}
} catch (Exception e) {
logger.warn("Problem processing edge URLs", e);
@@ -197,5 +219,222 @@
CyEdgeViewContextMenuFactory dynamicEdgeUrls = new
DynamicEdgeLinkoutMenuFactory(browser, synTaskManager);
registrar.registerService(dynamicEdgeUrls,
CyEdgeViewContextMenuFactory.class, edict);
}
+
+
+ public void addCommanLineLinkOut (CyProperty<Properties> commandline,
Map p ){
+ if (!p.get("cyPropertyName").equals("commandline.props"))
+ return;
+ Properties props = commandline.getProperties();
+ try {
+ for (Object pk : props.keySet()) {
+ String propKey = pk.toString();
+ String url = props.getProperty(propKey);
+ Properties dict = createProperties(propKey,
EDGEMARKER);
+ if (url == null || dict == null ) {
+ logger.debug("Bad URL for propKey: " +
propKey);
+ continue;
+ }
+ EdgeViewTaskFactory evtf = new
EdgeLinkoutTaskFactory(browser,url);
+ registrar.registerService(evtf,
EdgeViewTaskFactory.class, dict);
+ cpropKey2EdgeVTF.put(propKey,
(EdgeLinkoutTaskFactory) evtf);
+ }
+ } catch (Exception e) {
+ logger.warn("Problem processing edge URLs", e);
+ }
+
+
+ try {
+ for (Object pk : props.keySet()) {
+ String propKey = pk.toString();
+ String url = props.getProperty(propKey);
+ Properties dict = createProperties(propKey,
NODEMARKER);
+ if (url == null || dict == null ) {
+ logger.debug("Bad URL for propKey: " +
propKey);
+ continue;
+ }
+ NodeViewTaskFactory evtf = new
NodeLinkoutTaskFactory(browser,url);
+ registrar.registerService(evtf,
NodeViewTaskFactory.class, dict);
+ cpropKey2NodeVTF.put(propKey,
(NodeLinkoutTaskFactory) evtf);
+ }
+ } catch (Exception e) {
+ logger.warn("Problem processing node URLs", e);
+ }
+ }
+ public void removeCommanLineLinkOut (CyProperty<Properties>
commandline, Map p ){
+ //do nothing
+ }
+
+ @Override
+ public void handleEvent(final PropertyUpdatedEvent e) {
+
+ if(e.getSource() == null || e.getSource().getName() == null)
+ return;
+
+ SwingUtilities.invokeLater(new Runnable() {
+
+ @Override
+ public void run() {
+ // TODO Auto-generated method stub
+
+
+ if (e.getSource().getName().equals("linkout")
) //when linkout prop is changed
+ {
+ final Properties props = (Properties)
e.getSource().getProperties();
+ List<String> removedLinks = new
ArrayList<String>();
+
+ for(String propKey:
propKey2EdgeVTF.keySet()){
+ if
(props.keySet().contains(propKey)){
+ String url =
props.getProperty(propKey);
+ EdgeLinkoutTaskFactory
eltf = propKey2EdgeVTF.get(propKey);
+
if(!url.equals(eltf.getLink())){ //linkout is modified
+
eltf.setLink(url);
+
propKey2EdgeVTF.put(propKey, eltf);
+ }
+ }else{ //linkout is removed
+ EdgeLinkoutTaskFactory
eltf = propKey2EdgeVTF.get(propKey);
+
registrar.unregisterService(eltf, EdgeViewTaskFactory.class);
+
removedLinks.add(propKey);
+ }
+ }
+
+
+ for(String propKey:
propKey2NodeVTF.keySet()){
+ if
(props.keySet().contains(propKey)){
+ String url =
props.getProperty(propKey);
+ NodeLinkoutTaskFactory
nltf = propKey2NodeVTF.get(propKey);
+
if(!url.equals(nltf.getLink())){ //linkout is modified
+
nltf.setLink(url);
+
propKey2NodeVTF.put(propKey, nltf);
+ }
+ }else{ //linkout is removed
+ NodeLinkoutTaskFactory
nltf = propKey2NodeVTF.get(propKey);
+
registrar.unregisterService((NodeViewTaskFactory)nltf,
NodeViewTaskFactory.class);
+
removedLinks.add(propKey);
+ }
+ }
+
+ for(String propkey: removedLinks){
+ propKey2EdgeVTF.remove(propkey);
+ propKey2NodeVTF.remove(propkey);
+ }
+
+ try{
+
+ for(Object pk: props.keySet()){
//added edge linkouts
+ String propKey =
pk.toString();
+
if(propKey2EdgeVTF.containsKey(propKey))
+ continue;
+ String url =
props.getProperty(propKey);
+ Properties dict =
createProperties(propKey, EDGEMARKER);
+ if (url == null || dict
== null ) {
+
logger.debug("Bad URL for propKey: " + propKey);
+ continue;
+ }
+ EdgeViewTaskFactory
evtf = new EdgeLinkoutTaskFactory(browser,url);
+
registrar.registerService(evtf, EdgeViewTaskFactory.class, dict);
+
propKey2EdgeVTF.put(propKey, (EdgeLinkoutTaskFactory) evtf);
+ }
+
+ for(Object pk: props.keySet()){
//added node linkouts
+ String propKey =
pk.toString();
+
if(propKey2NodeVTF.containsKey(propKey))
+ continue;
+ String url =
props.getProperty(propKey);
+ Properties dict =
createProperties(propKey, NODEMARKER);
+ if (url == null || dict
== null ) {
+
logger.debug("Bad URL for propKey: " + propKey);
+ continue;
+ }
+ NodeViewTaskFactory
nvtf = new NodeLinkoutTaskFactory(browser,url);
+
registrar.registerService(nvtf, NodeViewTaskFactory.class, dict);
+
propKey2NodeVTF.put(propKey, (NodeLinkoutTaskFactory) nvtf);
+ }
+ }catch(Exception ex){
+ logger.warn("Problem processing
node URLs", ex);
+
+ }
+
+
+ }else if
(e.getSource().getName().equals("commandline")){ //when commandline linkout
prop is changed
+ final Properties props = (Properties)
e.getSource().getProperties();
+ List<String> removedLinks = new
ArrayList<String>();
+
+ for(String propKey:
cpropKey2EdgeVTF.keySet()){
+ if
(props.keySet().contains(propKey)){
+ String url =
props.getProperty(propKey);
+ EdgeLinkoutTaskFactory
eltf = cpropKey2EdgeVTF.get(propKey);
+
if(!url.equals(eltf.getLink())){ //linkout is modified
+
eltf.setLink(url);
+
cpropKey2EdgeVTF.put(propKey, eltf);
+ }
+ }else{ //linkout is removed
+ EdgeLinkoutTaskFactory
eltf = cpropKey2EdgeVTF.get(propKey);
+
registrar.unregisterService(eltf, EdgeViewTaskFactory.class);
+
removedLinks.add(propKey);
+ }
+ }
+
+
+ for(String propKey:
cpropKey2NodeVTF.keySet()){
+ if
(props.keySet().contains(propKey)){
+ String url =
props.getProperty(propKey);
+ NodeLinkoutTaskFactory
nltf = cpropKey2NodeVTF.get(propKey);
+
if(!url.equals(nltf.getLink())){ //linkout is modified
+
nltf.setLink(url);
+
cpropKey2NodeVTF.put(propKey, nltf);
+ }
+ }else{ //linkout is removed
+ NodeLinkoutTaskFactory
nltf = cpropKey2NodeVTF.get(propKey);
+
registrar.unregisterService((NodeViewTaskFactory)nltf,
NodeViewTaskFactory.class);
+
removedLinks.add(propKey);
+ }
+ }
+
+ for(String propkey: removedLinks){
+
cpropKey2EdgeVTF.remove(propkey);
+
cpropKey2NodeVTF.remove(propkey);
+ }
+
+ try{
+
+ for(Object pk: props.keySet()){
//added edge linkouts
+ String propKey =
pk.toString();
+
if(cpropKey2EdgeVTF.containsKey(propKey))
+ continue;
+ String url =
props.getProperty(propKey);
+ Properties dict =
createProperties(propKey, EDGEMARKER);
+ if (url == null || dict
== null ) {
+
logger.debug("Bad URL for propKey: " + propKey);
+ continue;
+ }
+ EdgeViewTaskFactory
evtf = new EdgeLinkoutTaskFactory(browser,url);
+
registrar.registerService(evtf, EdgeViewTaskFactory.class, dict);
+
cpropKey2EdgeVTF.put(propKey, (EdgeLinkoutTaskFactory) evtf);
+ }
+
+ for(Object pk: props.keySet()){
//added node linkouts
+ String propKey =
pk.toString();
+
if(cpropKey2NodeVTF.containsKey(propKey))
+ continue;
+ String url =
props.getProperty(propKey);
+ Properties dict =
createProperties(propKey, NODEMARKER);
+ if (url == null || dict
== null ) {
+
logger.debug("Bad URL for propKey: " + propKey);
+ continue;
+ }
+ NodeViewTaskFactory
nvtf = new NodeLinkoutTaskFactory(browser,url);
+
registrar.registerService(nvtf, NodeViewTaskFactory.class, dict);
+
cpropKey2NodeVTF.put(propKey, (NodeLinkoutTaskFactory) nvtf);
+ }
+ }catch(Exception ex){
+ logger.warn("Problem processing
node URLs", ex);
+
+ }
+ }
+ }
+ });
+
+ }
+
}
Modified:
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/NodeLinkoutTaskFactory.java
===================================================================
---
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/NodeLinkoutTaskFactory.java
2012-06-07 21:19:32 UTC (rev 29501)
+++
core3/impl/trunk/linkout-impl/src/main/java/org/cytoscape/linkout/internal/NodeLinkoutTaskFactory.java
2012-06-08 00:11:23 UTC (rev 29502)
@@ -11,7 +11,7 @@
public class NodeLinkoutTaskFactory extends AbstractNodeViewTaskFactory {
- private final String link;
+ private String link;
private final OpenBrowser browser;
public NodeLinkoutTaskFactory(OpenBrowser browser, String link) {
@@ -23,4 +23,11 @@
public TaskIterator createTaskIterator(View<CyNode> nodeView,
CyNetworkView netView) {
return new TaskIterator(new LinkoutTask(link, browser,
netView.getModel(), nodeView.getModel()));
}
+
+ public String getLink(){
+ return link;
+ }
+ public void setLink (String link){
+ this.link = link;
+ }
}
--
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.