Author: clopes
Date: 2012-10-31 12:48:14 -0700 (Wed, 31 Oct 2012)
New Revision: 30725

Added:
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODECloseTask.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODECloseTaskFactory.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEOpenTask.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEOpenTaskFactory.java
Removed:
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODECloseAction.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEOpenAction.java
Modified:
   csplugins/trunk/toronto/clopes/mcode/pom.xml
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/CyActivator.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEAboutDialog.java
Log:
- Fix MCODE's Open/Close menu items so they can be disabled when not required 
(they are Tasks now, not CyActions).
- Makes About dialog modal, so only one is open at a time.
- Adds dependency to event-api (required for unit tests)


Modified: csplugins/trunk/toronto/clopes/mcode/pom.xml
===================================================================
--- csplugins/trunk/toronto/clopes/mcode/pom.xml        2012-10-31 17:08:25 UTC 
(rev 30724)
+++ csplugins/trunk/toronto/clopes/mcode/pom.xml        2012-10-31 19:48:14 UTC 
(rev 30725)
@@ -18,7 +18,7 @@
        <artifactId>mcode-cy3</artifactId>
        <name>MCODE</name>
        <packaging>bundle</packaging>
-       <version>1.4.0-beta1</version>
+       <version>1.4.0-beta2</version>
 
        <build>
                <resources>
@@ -219,6 +219,13 @@
                </dependency>
                <dependency>
                        <groupId>org.cytoscape</groupId>
+                       <artifactId>event-api</artifactId>
+                       <version>${cytoscape.api.version}</version>
+                       <type>test-jar</type>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
                        <artifactId>model-impl</artifactId>
                        <version>${cytoscape.impl.version}</version>
                        <scope>test</scope>

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/CyActivator.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/CyActivator.java
    2012-10-31 17:08:25 UTC (rev 30724)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/CyActivator.java
    2012-10-31 19:48:14 UTC (rev 30725)
@@ -1,5 +1,13 @@
 package org.cytoscape.mcode.internal;
 
+import static org.cytoscape.work.ServiceProperties.ACCELERATOR;
+import static org.cytoscape.work.ServiceProperties.COMMAND;
+import static org.cytoscape.work.ServiceProperties.COMMAND_NAMESPACE;
+import static org.cytoscape.work.ServiceProperties.ENABLE_FOR;
+import static org.cytoscape.work.ServiceProperties.MENU_GRAVITY;
+import static org.cytoscape.work.ServiceProperties.PREFERRED_MENU;
+import static org.cytoscape.work.ServiceProperties.TITLE;
+
 import java.util.Properties;
 
 import org.cytoscape.application.CyApplicationManager;
@@ -7,6 +15,8 @@
 import org.cytoscape.application.swing.CySwingApplication;
 import 
org.cytoscape.application.swing.events.CytoPanelComponentSelectedListener;
 import org.cytoscape.event.CyEventHelper;
+import org.cytoscape.mcode.internal.task.MCODECloseTaskFactory;
+import org.cytoscape.mcode.internal.task.MCODEOpenTaskFactory;
 import org.cytoscape.mcode.internal.util.MCODEUtil;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNetworkManager;
@@ -22,6 +32,7 @@
 import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
 import org.cytoscape.view.vizmap.VisualMappingManager;
 import org.cytoscape.view.vizmap.VisualStyleFactory;
+import org.cytoscape.work.TaskFactory;
 import org.cytoscape.work.TaskManager;
 import org.osgi.framework.BundleContext;
 
@@ -62,19 +73,32 @@
                                                                                
        continuousMappingFactory, fileUtil);
                
                MCODEAnalyzeAction analyzeAction = new 
MCODEAnalyzeAction("Analyze current network", appMgr, swingApp, netViewMgr, 
serviceRegistrar, taskMgr, mcodeUtil);
-               MCODEOpenAction openAction = new MCODEOpenAction("Open MCODE", 
appMgr, swingApp, netViewMgr, serviceRegistrar, analyzeAction, mcodeUtil);
-               MCODECloseAction closeAction = new MCODECloseAction("Close 
MCODE", appMgr, swingApp, netViewMgr, serviceRegistrar, mcodeUtil);
                MCODEHelpAction helpAction = new MCODEHelpAction("Help", 
appMgr, swingApp, netViewMgr, openBrowser);
                MCODEVisualStyleAction visualStyleAction = new 
MCODEVisualStyleAction("Apply MCODE style", appMgr, swingApp, netViewMgr, 
visualMappingMgr, mcodeUtil);
                MCODEAboutAction aboutAction = new MCODEAboutAction("About", 
appMgr, swingApp, netViewMgr, openBrowser, mcodeUtil);
                
-               registerService(bc, openAction, CyAction.class, new 
Properties());
-               registerService(bc, closeAction, CyAction.class, new 
Properties());
-               registerService(bc, closeAction, 
NetworkAboutToBeDestroyedListener.class, new Properties());
                registerService(bc, helpAction, CyAction.class, new 
Properties());
                registerService(bc, aboutAction, CyAction.class, new 
Properties());
                registerAllServices(bc, analyzeAction, new Properties());
                registerService(bc, visualStyleAction, CyAction.class, new 
Properties());
                registerService(bc, visualStyleAction, 
CytoPanelComponentSelectedListener.class, new Properties());
+               
+               MCODEOpenTaskFactory openTaskFactory = new 
MCODEOpenTaskFactory(swingApp, serviceRegistrar, mcodeUtil, analyzeAction);
+               Properties openTaskFactoryProps = new Properties();
+               openTaskFactoryProps.setProperty(PREFERRED_MENU, "Apps.MCODE");
+               openTaskFactoryProps.setProperty(TITLE, "Open MCODE");
+               openTaskFactoryProps.setProperty(MENU_GRAVITY,"1.0");
+               
+               registerService(bc, openTaskFactory, TaskFactory.class, 
openTaskFactoryProps);
+               
+               MCODECloseTaskFactory closeTaskFactory = new 
MCODECloseTaskFactory(swingApp, serviceRegistrar, mcodeUtil);
+               Properties closeTaskFactoryProps = new Properties();
+               closeTaskFactoryProps.setProperty(PREFERRED_MENU, "Apps.MCODE");
+               closeTaskFactoryProps.setProperty(TITLE, "Close MCODE");
+               closeTaskFactoryProps.setProperty(MENU_GRAVITY,"2.0");
+               
+               registerService(bc, closeTaskFactory, TaskFactory.class, 
closeTaskFactoryProps);
+               registerService(bc, closeTaskFactory, 
NetworkAboutToBeDestroyedListener.class, new Properties());
+               
        }
 }

Deleted: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODECloseAction.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODECloseAction.java
       2012-10-31 17:08:25 UTC (rev 30724)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODECloseAction.java
       2012-10-31 19:48:14 UTC (rev 30725)
@@ -1,107 +0,0 @@
-package org.cytoscape.mcode.internal;
-
-import java.awt.event.ActionEvent;
-import java.util.Collection;
-import java.util.Set;
-
-import javax.swing.JOptionPane;
-
-import org.cytoscape.application.CyApplicationManager;
-import org.cytoscape.application.swing.ActionEnableSupport;
-import org.cytoscape.application.swing.CySwingApplication;
-import org.cytoscape.application.swing.CytoPanel;
-import org.cytoscape.application.swing.CytoPanelComponent;
-import org.cytoscape.application.swing.CytoPanelName;
-import org.cytoscape.application.swing.CytoPanelState;
-import org.cytoscape.mcode.internal.util.MCODEUtil;
-import org.cytoscape.mcode.internal.view.MCODEMainPanel;
-import org.cytoscape.mcode.internal.view.MCODEResultsPanel;
-import org.cytoscape.model.CyNetwork;
-import org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent;
-import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener;
-import org.cytoscape.service.util.CyServiceRegistrar;
-import org.cytoscape.view.model.CyNetworkViewManager;
-
-/**
- * Closes the app panels.
- */
-public class MCODECloseAction extends AbstractMCODEAction implements 
NetworkAboutToBeDestroyedListener {
-
-       private static final long serialVersionUID = -8309835257402089360L;
-
-       private final CyServiceRegistrar registrar;
-       private final MCODEUtil mcodeUtil;
-
-       public MCODECloseAction(final String name,
-                                                       final 
CyApplicationManager applicationManager,
-                                                       final 
CySwingApplication swingApplication,
-                                                       final 
CyNetworkViewManager netViewManager,
-                                                       final 
CyServiceRegistrar registrar,
-                                                       final MCODEUtil 
mcodeUtil) {
-               super(name, applicationManager, swingApplication, 
netViewManager, ActionEnableSupport.ENABLE_FOR_ALWAYS);
-               this.registrar = registrar;
-               this.mcodeUtil = mcodeUtil;
-               setPreferredMenu("Apps.MCODE");
-       }
-
-       /**
-        * This method is called when the user wants to close MCODE.
-        * @param event Menu Item Selected.
-        */
-       @Override
-       public void actionPerformed(final ActionEvent event) {
-               //First we must make sure that the app is opened
-               if (isOpened()) {
-                       Collection<MCODEResultsPanel> resultPanels = 
getResultPanels();
-
-                       if (resultPanels.size() > 0) {
-                               String message = "You are about to close the 
MCODE app.\nDo you wish to continue?";
-                               int result = 
JOptionPane.showOptionDialog(swingApplication.getJFrame(),
-                                                                               
                                  new Object[] { message },
-                                                                               
                                  "Confirm",
-                                                                               
                                  JOptionPane.YES_NO_OPTION,
-                                                                               
                                  JOptionPane.QUESTION_MESSAGE,
-                                                                               
                                  null,
-                                                                               
                                  null,
-                                                                               
                                  null);
-                               if (result == JOptionPane.YES_OPTION) {
-                                       for (MCODEResultsPanel panel : 
resultPanels) {
-                                               panel.discard(false);
-                                       }
-
-                                       CytoPanel cytoPanel = 
swingApplication.getCytoPanel(CytoPanelName.WEST);
-
-                                       if 
(cytoPanel.getCytoPanelComponentCount() == 0) {
-                                               
cytoPanel.setState(CytoPanelState.HIDE);
-                                       }
-                               }
-                       }
-
-                       MCODEMainPanel mainPanel = getMainPanel();
-
-                       if (mainPanel != null) {
-                               registrar.unregisterService(mainPanel, 
CytoPanelComponent.class);
-                       }
-
-                       mcodeUtil.reset();
-               }
-       }
-
-       @Override
-       public void updateEnableState() {
-               setEnabled(isOpened());
-       }
-
-       @Override
-       public void handleEvent(final NetworkAboutToBeDestroyedEvent e) {
-               if (isOpened()) {
-                       CyNetwork network = e.getNetwork();
-                       Set<Integer> resultIds = 
mcodeUtil.getNetworkResults(network.getSUID());
-
-                       for (int id : resultIds) {
-                               MCODEResultsPanel panel = getResultPanel(id);
-                               if (panel != null) panel.discard(false);
-                       }
-               }
-       }
-}

Deleted: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEOpenAction.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEOpenAction.java
        2012-10-31 17:08:25 UTC (rev 30724)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEOpenAction.java
        2012-10-31 19:48:14 UTC (rev 30725)
@@ -1,74 +0,0 @@
-package org.cytoscape.mcode.internal;
-
-import java.awt.event.ActionEvent;
-import java.util.Properties;
-
-import org.cytoscape.application.CyApplicationManager;
-import org.cytoscape.application.swing.ActionEnableSupport;
-import org.cytoscape.application.swing.CySwingApplication;
-import org.cytoscape.application.swing.CytoPanel;
-import org.cytoscape.application.swing.CytoPanelComponent;
-import org.cytoscape.mcode.internal.util.MCODEUtil;
-import org.cytoscape.mcode.internal.view.MCODEMainPanel;
-import org.cytoscape.service.util.CyServiceRegistrar;
-import org.cytoscape.view.model.CyNetworkViewManager;
-
-/**
- * Creates a new menu item under Apps menu section.
- */
-public class MCODEOpenAction extends AbstractMCODEAction {
-
-       private static final long serialVersionUID = 3521389398662580589L;
-
-       private final CyServiceRegistrar registrar;
-       private final MCODEAnalyzeAction analyzeAction;
-       private final MCODEUtil mcodeUtil;
-
-       public MCODEOpenAction(final String name,
-                                                  final CyApplicationManager 
applicationManager,
-                                                  final CySwingApplication 
swingApplication,
-                                                  final CyNetworkViewManager 
netViewManager,
-                                                  final CyServiceRegistrar 
registrar,
-                                                  final MCODEAnalyzeAction 
analyzeAction,
-                                                  final MCODEUtil mcodeUtil) {
-               super(name, applicationManager, swingApplication, 
netViewManager, ActionEnableSupport.ENABLE_FOR_ALWAYS);
-               this.registrar = registrar;
-               this.analyzeAction = analyzeAction;
-               this.mcodeUtil = mcodeUtil;
-               setPreferredMenu("Apps.MCODE");
-       }
-
-       /**
-        * This method is called when the user wants to start MCODE.
-        * @param event Menu Item Selected.
-        */
-       @Override
-       public void actionPerformed(ActionEvent event) {
-               // Display MCODEMainPanel in left cytopanel
-               synchronized (this) {
-                       MCODEMainPanel mainPanel = null;
-
-                       // First we must make sure that the app is not already 
open
-                       if (!isOpened()) {
-                               mainPanel = new 
MCODEMainPanel(swingApplication, mcodeUtil);
-                               mainPanel.addAction(analyzeAction);
-
-                               registrar.registerService(mainPanel, 
CytoPanelComponent.class, new Properties());
-                               analyzeAction.updateEnableState();
-                       } else {
-                               mainPanel = getMainPanel();
-                       }
-
-                       if (mainPanel != null) {
-                               CytoPanel cytoPanel = getControlCytoPanel();
-                               int index = 
cytoPanel.indexOfComponent(mainPanel);
-                               cytoPanel.setSelectedIndex(index);
-                       }
-               }
-       }
-
-       @Override
-       public void updateEnableState() {
-               setEnabled(!isOpened());
-       }
-}

Added: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODECloseTask.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODECloseTask.java
                            (rev 0)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODECloseTask.java
    2012-10-31 19:48:14 UTC (rev 30725)
@@ -0,0 +1,78 @@
+package org.cytoscape.mcode.internal.task;
+
+import java.util.Collection;
+
+import javax.swing.JOptionPane;
+
+import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.application.swing.CytoPanel;
+import org.cytoscape.application.swing.CytoPanelComponent;
+import org.cytoscape.application.swing.CytoPanelName;
+import org.cytoscape.application.swing.CytoPanelState;
+import org.cytoscape.mcode.internal.util.MCODEUtil;
+import org.cytoscape.mcode.internal.view.MCODEMainPanel;
+import org.cytoscape.mcode.internal.view.MCODEResultsPanel;
+import org.cytoscape.service.util.CyServiceRegistrar;
+import org.cytoscape.work.Task;
+import org.cytoscape.work.TaskMonitor;
+
+/**
+ * Closes the app panels.
+ */
+public class MCODECloseTask implements Task {
+
+       private final CySwingApplication swingApplication;
+       private final CyServiceRegistrar registrar;
+       private final MCODEUtil mcodeUtil;
+       
+       public MCODECloseTask(final CySwingApplication swingApplication,
+                                                 final CyServiceRegistrar 
registrar,
+                                                 final MCODEUtil mcodeUtil) {
+               this.swingApplication = swingApplication;
+               this.registrar = registrar;
+               this.mcodeUtil = mcodeUtil;
+       }
+
+       @Override
+       public void run(TaskMonitor taskMonitor) throws Exception {
+               if (mcodeUtil.isOpened()) {
+                       Collection<MCODEResultsPanel> resultPanels = 
mcodeUtil.getResultPanels();
+
+                       if (resultPanels.size() > 0) {
+                               String message = "You are about to close the 
MCODE app.\nDo you wish to continue?";
+                               int result = 
JOptionPane.showOptionDialog(swingApplication.getJFrame(),
+                                                                               
                                  new Object[] { message },
+                                                                               
                                  "Confirm",
+                                                                               
                                  JOptionPane.YES_NO_OPTION,
+                                                                               
                                  JOptionPane.QUESTION_MESSAGE,
+                                                                               
                                  null,
+                                                                               
                                  null,
+                                                                               
                                  null);
+                               if (result == JOptionPane.YES_OPTION) {
+                                       for (MCODEResultsPanel panel : 
resultPanels) {
+                                               panel.discard(false);
+                                       }
+
+                                       CytoPanel cytoPanel = 
swingApplication.getCytoPanel(CytoPanelName.WEST);
+
+                                       if 
(cytoPanel.getCytoPanelComponentCount() == 0) {
+                                               
cytoPanel.setState(CytoPanelState.HIDE);
+                                       }
+                               }
+                       }
+
+                       MCODEMainPanel mainPanel = mcodeUtil.getMainPanel();
+
+                       if (mainPanel != null) {
+                               registrar.unregisterService(mainPanel, 
CytoPanelComponent.class);
+                       }
+
+                       mcodeUtil.reset();
+               }
+       }
+
+       @Override
+       public void cancel() {
+               // Do nothing
+       }
+}

Added: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODECloseTaskFactory.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODECloseTaskFactory.java
                             (rev 0)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODECloseTaskFactory.java
     2012-10-31 19:48:14 UTC (rev 30725)
@@ -0,0 +1,51 @@
+package org.cytoscape.mcode.internal.task;
+
+import java.util.Set;
+
+import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.mcode.internal.util.MCODEUtil;
+import org.cytoscape.mcode.internal.view.MCODEResultsPanel;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent;
+import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener;
+import org.cytoscape.service.util.CyServiceRegistrar;
+import org.cytoscape.work.TaskFactory;
+import org.cytoscape.work.TaskIterator;
+
+public class MCODECloseTaskFactory implements TaskFactory, 
NetworkAboutToBeDestroyedListener {
+       
+       private final CySwingApplication swingApplication;
+       private final CyServiceRegistrar registrar;
+       private final MCODEUtil mcodeUtil;
+       
+       public MCODECloseTaskFactory(final CySwingApplication swingApplication,
+                                                                final 
CyServiceRegistrar registrar,
+                                                                final 
MCODEUtil mcodeUtil) {
+               this.swingApplication = swingApplication;
+               this.registrar = registrar;
+               this.mcodeUtil = mcodeUtil;
+       }
+
+       @Override
+       public TaskIterator createTaskIterator() {
+               return new TaskIterator(new MCODECloseTask(swingApplication, 
registrar, mcodeUtil));
+       }
+
+       @Override
+       public boolean isReady() {
+               return mcodeUtil.isOpened();
+       }
+       
+       @Override
+       public void handleEvent(final NetworkAboutToBeDestroyedEvent e) {
+               if (mcodeUtil.isOpened()) {
+                       CyNetwork network = e.getNetwork();
+                       Set<Integer> resultIds = 
mcodeUtil.getNetworkResults(network.getSUID());
+
+                       for (int id : resultIds) {
+                               MCODEResultsPanel panel = 
mcodeUtil.getResultPanel(id);
+                               if (panel != null) panel.discard(false);
+                       }
+               }
+       }
+}

Added: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEOpenTask.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEOpenTask.java
                             (rev 0)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEOpenTask.java
     2012-10-31 19:48:14 UTC (rev 30725)
@@ -0,0 +1,64 @@
+package org.cytoscape.mcode.internal.task;
+
+import java.util.Properties;
+
+import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.application.swing.CytoPanel;
+import org.cytoscape.application.swing.CytoPanelComponent;
+import org.cytoscape.mcode.internal.MCODEAnalyzeAction;
+import org.cytoscape.mcode.internal.util.MCODEUtil;
+import org.cytoscape.mcode.internal.view.MCODEMainPanel;
+import org.cytoscape.service.util.CyServiceRegistrar;
+import org.cytoscape.work.Task;
+import org.cytoscape.work.TaskMonitor;
+
+/**
+ * Open the MCODE panel in the Control panel.
+ */
+public class MCODEOpenTask implements Task {
+
+       private final CySwingApplication swingApplication;
+       private final CyServiceRegistrar registrar;
+       private final MCODEUtil mcodeUtil;
+       private final MCODEAnalyzeAction analyzeAction;
+       
+       public MCODEOpenTask(final CySwingApplication swingApplication,
+                                                final CyServiceRegistrar 
registrar,
+                                                final MCODEUtil mcodeUtil,
+                                                final MCODEAnalyzeAction 
analyzeAction) {
+               this.swingApplication = swingApplication;
+               this.registrar = registrar;
+               this.mcodeUtil = mcodeUtil;
+               this.analyzeAction = analyzeAction;
+       }
+
+       @Override
+       public void run(TaskMonitor taskMonitor) throws Exception {
+               // Display MCODEMainPanel in left cytopanel
+               synchronized (this) {
+                       MCODEMainPanel mainPanel = null;
+
+                       // First we must make sure that the app is not already 
open
+                       if (!mcodeUtil.isOpened()) {
+                               mainPanel = new 
MCODEMainPanel(swingApplication, mcodeUtil);
+                               mainPanel.addAction(analyzeAction);
+
+                               registrar.registerService(mainPanel, 
CytoPanelComponent.class, new Properties());
+                               analyzeAction.updateEnableState();
+                       } else {
+                               mainPanel = mcodeUtil.getMainPanel();
+                       }
+
+                       if (mainPanel != null) {
+                               CytoPanel cytoPanel = 
mcodeUtil.getControlCytoPanel();
+                               int index = 
cytoPanel.indexOfComponent(mainPanel);
+                               cytoPanel.setSelectedIndex(index);
+                       }
+               }
+       }
+
+       @Override
+       public void cancel() {
+               // Do nothing
+       }
+}

Added: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEOpenTaskFactory.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEOpenTaskFactory.java
                              (rev 0)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEOpenTaskFactory.java
      2012-10-31 19:48:14 UTC (rev 30725)
@@ -0,0 +1,36 @@
+package org.cytoscape.mcode.internal.task;
+
+import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.mcode.internal.MCODEAnalyzeAction;
+import org.cytoscape.mcode.internal.util.MCODEUtil;
+import org.cytoscape.service.util.CyServiceRegistrar;
+import org.cytoscape.work.TaskFactory;
+import org.cytoscape.work.TaskIterator;
+
+public class MCODEOpenTaskFactory implements TaskFactory {
+
+       private final CySwingApplication swingApplication;
+       private final CyServiceRegistrar registrar;
+       private final MCODEUtil mcodeUtil;
+       private final MCODEAnalyzeAction analyzeAction;
+       
+       public MCODEOpenTaskFactory(final CySwingApplication swingApplication,
+                                                               final 
CyServiceRegistrar registrar,
+                                                               final MCODEUtil 
mcodeUtil,
+                                                               final 
MCODEAnalyzeAction analyzeAction) {
+               this.swingApplication = swingApplication;
+               this.registrar = registrar;
+               this.mcodeUtil = mcodeUtil;
+               this.analyzeAction = analyzeAction;
+       }
+       
+       @Override
+       public TaskIterator createTaskIterator() {
+               return new TaskIterator(new MCODEOpenTask(swingApplication, 
registrar, mcodeUtil, analyzeAction));
+       }
+
+       @Override
+       public boolean isReady() {
+               return !mcodeUtil.isOpened();
+       }
+}

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
 2012-10-31 17:08:25 UTC (rev 30724)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
 2012-10-31 19:48:14 UTC (rev 30725)
@@ -54,6 +54,8 @@
 
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.application.swing.CytoPanel;
+import org.cytoscape.application.swing.CytoPanelName;
 import org.cytoscape.event.CyEventHelper;
 import org.cytoscape.mcode.internal.CyActivator;
 import org.cytoscape.mcode.internal.model.MCODEAlgorithm;
@@ -61,6 +63,8 @@
 import org.cytoscape.mcode.internal.model.MCODECurrentParameters;
 import org.cytoscape.mcode.internal.util.layout.SpringEmbeddedLayouter;
 import org.cytoscape.mcode.internal.view.MCODELoader;
+import org.cytoscape.mcode.internal.view.MCODEMainPanel;
+import org.cytoscape.mcode.internal.view.MCODEResultsPanel;
 import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyIdentifiable;
 import org.cytoscape.model.CyNetwork;
@@ -818,6 +822,66 @@
                return false;
        }
        
+       /**
+        * @return Cytoscape's control panel
+        */
+       public CytoPanel getControlCytoPanel() {
+               return swingApplication.getCytoPanel(CytoPanelName.WEST);
+       }
+
+       /**
+        * @return Cytoscape's results panel
+        */
+       public CytoPanel getResultsCytoPanel() {
+               return swingApplication.getCytoPanel(CytoPanelName.EAST);
+       }
+
+       /**
+        * @return The main panel of the app if it is opened, and null otherwise
+        */
+       public MCODEMainPanel getMainPanel() {
+               CytoPanel cytoPanel = getControlCytoPanel();
+               int count = cytoPanel.getCytoPanelComponentCount();
+
+               for (int i = 0; i < count; i++) {
+                       if (cytoPanel.getComponentAt(i) instanceof 
MCODEMainPanel)
+                               return (MCODEMainPanel) 
cytoPanel.getComponentAt(i);
+               }
+
+               return null;
+       }
+
+       /**
+        * @return The result panels of the app if it is opened, or an empty 
collection otherwise
+        */
+       public Collection<MCODEResultsPanel> getResultPanels() {
+               Collection<MCODEResultsPanel> panels = new 
ArrayList<MCODEResultsPanel>();
+               CytoPanel cytoPanel = getResultsCytoPanel();
+               int count = cytoPanel.getCytoPanelComponentCount();
+
+               for (int i = 0; i < count; i++) {
+                       if (cytoPanel.getComponentAt(i) instanceof 
MCODEResultsPanel)
+                               panels.add((MCODEResultsPanel) 
cytoPanel.getComponentAt(i));
+               }
+
+               return panels;
+       }
+
+       public MCODEResultsPanel getResultPanel(final int resultId) {
+               for (MCODEResultsPanel panel : getResultPanels()) {
+                       if (panel.getResultId() == resultId) return panel;
+               }
+
+               return null;
+       }
+
+       /**
+        * @return true if the app is opened and false otherwise
+        */
+       public boolean isOpened() {
+               return getMainPanel() != null;
+       }
+       
        private static Properties loadProperties(String name) {
                Properties props = new Properties();
 

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEAboutDialog.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEAboutDialog.java
  2012-10-31 17:08:25 UTC (rev 30724)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEAboutDialog.java
  2012-10-31 19:48:14 UTC (rev 30725)
@@ -79,7 +79,7 @@
        public MCODEAboutDialog(final CySwingApplication swingApplication,
                                                        final OpenBrowser 
openBrowser,
                                                        final MCODEUtil 
mcodeUtil) {
-               super(swingApplication.getJFrame(), "About MCODE", false);
+               super(swingApplication.getJFrame(), "About MCODE", true);
                this.swingApplication = swingApplication;
                this.openBrowser = openBrowser;
                version = mcodeUtil.getProperty("project.version");
@@ -170,7 +170,7 @@
        }
        
        private class HyperlinkAction implements HyperlinkListener {
-
+               @Override
                public void hyperlinkUpdate(HyperlinkEvent event) {
                        if (event.getEventType() == 
HyperlinkEvent.EventType.ACTIVATED) {
                                openBrowser.openURL(event.getURL().toString());

-- 
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.

Reply via email to