Author: paperwing
Date: 2012-04-24 13:29:22 -0700 (Tue, 24 Apr 2012)
New Revision: 28969

Modified:
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/action/AppManagerAction.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/AppManagerDialog.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
   
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallFromStorePanel.java
Log:
Buttons on "currently installed" tab and "updates" tab are now disabled/enabled 
according to context. AppParser class updated to look for Cytoscape-App-Name 
and Cytoscape-App-Version entries in manifest file. App manager now executes 
the initial series of web queries inside a Task object and uses 
SwingUtilities.invokeLater() to update the UI once the queries are completed.

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
 2012-04-24 20:24:48 UTC (rev 28968)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
 2012-04-24 20:29:22 UTC (rev 28969)
@@ -123,7 +123,7 @@
                registerService(bc, appManager, AppManager.class, new 
Properties());
                
                // AbstractCyAction implementation for updated app manager
-               AppManagerAction appManagerAction2 = new 
AppManagerAction(appManager, cySwingApplicationRef, fileUtilServiceRef);
+               AppManagerAction appManagerAction2 = new 
AppManagerAction(appManager, cySwingApplicationRef, fileUtilServiceRef, 
taskManagerRef);
                registerService(bc, appManagerAction2, CyAction.class, new 
Properties());
        }
 }

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/action/AppManagerAction.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/action/AppManagerAction.java
     2012-04-24 20:24:48 UTC (rev 28968)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/action/AppManagerAction.java
     2012-04-24 20:29:22 UTC (rev 28969)
@@ -1,12 +1,19 @@
 package org.cytoscape.app.internal.action;
 
 import java.awt.event.ActionEvent;
+import java.util.Set;
 
 import org.cytoscape.app.internal.manager.AppManager;
+import org.cytoscape.app.internal.net.WebApp;
+import org.cytoscape.app.internal.net.WebQuerier;
 import org.cytoscape.app.internal.ui.AppManagerDialog;
 import org.cytoscape.application.swing.AbstractCyAction;
 import org.cytoscape.application.swing.CySwingApplication;
 import org.cytoscape.util.swing.FileUtil;
+import org.cytoscape.work.Task;
+import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.TaskManager;
+import org.cytoscape.work.TaskMonitor;
 
 public class AppManagerAction extends AbstractCyAction {
 
@@ -29,9 +36,14 @@
        private FileUtil fileUtil;
        
        /**
+        * A reference to the {@link TaskManager} service used to execute 
Cytoscape tasks
+        */
+       private TaskManager taskManager;
+       
+       /**
         * Creates and sets up the AbstractCyAction, placing an item into the 
menu.
         */
-       public AppManagerAction(AppManager appManager, CySwingApplication 
swingApplication, FileUtil fileUtil) {
+       public AppManagerAction(AppManager appManager, CySwingApplication 
swingApplication, FileUtil fileUtil, TaskManager taskManager) {
                super("App Manager 2");
                
                setPreferredMenu("Apps");
@@ -40,12 +52,14 @@
                this.appManager = appManager;
                this.swingApplication = swingApplication;
                this.fileUtil = fileUtil;
+               this.taskManager = taskManager;
        }
 
        @Override
        public void actionPerformed(ActionEvent event) {
+                               
                // Create and display the App Manager dialog
-               AppManagerDialog appManagerDialog = new 
AppManagerDialog(appManager, fileUtil, swingApplication.getJFrame(), false);
+               AppManagerDialog appManagerDialog = new 
AppManagerDialog(appManager, fileUtil, taskManager, 
swingApplication.getJFrame(), false);
        }
 
 }

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
   2012-04-24 20:24:48 UTC (rev 28968)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
   2012-04-24 20:29:22 UTC (rev 28969)
@@ -13,11 +13,30 @@
  * to verify the app.
  */
 public class AppParser {
-       /** The name of the key in the app jar's manifest file that indicates 
the fully-qualified name 
-        * of the class to instantiate upon app installation. */
+       /** 
+        * The name of the key in the app jar's manifest file that indicates 
the fully-qualified name 
+        * of the class to instantiate upon app installation. 
+        * */
        private static final String APP_CLASS_TAG = "Cytoscape-App";
        
        /**
+        * The name of the key in the app jar's manifest file indicating the 
human-readable
+        * name of the app
+        */
+       private static final String APP_READABLE_NAME_TAG = 
"Cytoscape-App-Name";
+       
+       /**
+        * The name of the key in the app jar's manifest file indicating the 
version of the app
+        * in the format major.minor.patch[-tag], eg. 3.0.0-SNAPSHOT or 1.2.3
+        */
+       private static final String APP_VERSION_TAG = "Cytoscape-App-Version";
+       
+       /**
+        * A regular a expression representing valid app versions, which are in 
the format major.minor.patch[-tag]
+        */
+       private static final String APP_VERSION_TAG_REGEX = 
"(0|([1-9]+\\d*))\\.(\\d)+\\.(\\d)+(-.*)?";
+       
+       /**
         * Attempt to parse a given {@link File} object as an {@link App} 
object.
         * @param file The file to use for parsing
         * @return An {@link App} object representing the given file if parsing 
was successful
@@ -52,11 +71,25 @@
                        throw new AppParsingException("Jar is missing value for 
entry " + APP_CLASS_TAG + " in its manifest file.");
                }
                
-               // Attempt to guess the app's name
-               parsedApp.setAppName(file.getName()); // Use filename for now
+               // Obtain the human-readable name of the app
+               String readableName = 
manifest.getMainAttributes().getValue(APP_READABLE_NAME_TAG);
+               if (readableName == null || readableName.trim().length() == 0) {
+                       throw new AppParsingException("Jar is missing value for 
entry " + APP_READABLE_NAME_TAG + " in its manifest file.");
+               }
                
+               // Obtain the version of the app, in major.minor.patch[-tag] 
format, ie. 3.0.0-SNAPSHOT or 1.2.3
+               String appVersion = 
manifest.getMainAttributes().getValue(APP_VERSION_TAG);
+               if (appVersion == null || appVersion.trim().length() == 0) {
+                       throw new AppParsingException("Jar is missing value for 
entry " + APP_VERSION_TAG + " in its manifiest file.");
+               } else if (!appVersion.matches(APP_VERSION_TAG_REGEX)) {
+                       throw new AppParsingException("The app version 
specified in its manifest file under the key " + APP_VERSION_TAG
+                                       + " was found to not match the format 
major.minor.patch[-tag], eg. 1.0.0 or 1.0.0-SNAPSHOT");
+               }
+               
                parsedApp.setAppFile(file);
                parsedApp.setEntryClassName(entryClassName);
+               parsedApp.setAppName(readableName);
+               parsedApp.setVersion(appVersion);
                parsedApp.setAppValidated(true);
                
                return parsedApp;

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/AppManagerDialog.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/AppManagerDialog.java
 2012-04-24 20:24:48 UTC (rev 28968)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/AppManagerDialog.java
 2012-04-24 20:29:22 UTC (rev 28969)
@@ -2,6 +2,7 @@
 
 import org.cytoscape.app.internal.manager.AppManager;
 import org.cytoscape.util.swing.FileUtil;
+import org.cytoscape.work.TaskManager;
 
 /**
  * This class represents the App Manager dialog window. Its UI setup code is 
generated by the Netbeans 7 GUI builder.
@@ -15,12 +16,14 @@
     
     private AppManager appManager;
        private FileUtil fileUtil;
+       private TaskManager taskManager;
     
-    public AppManagerDialog(AppManager appManager, FileUtil fileUtil, 
java.awt.Frame parent, boolean modal) {
+    public AppManagerDialog(AppManager appManager, FileUtil fileUtil, 
TaskManager taskManager, java.awt.Frame parent, boolean modal) {
         super(parent, modal);
         
         this.appManager = appManager;
         this.fileUtil = fileUtil;
+        this.taskManager = taskManager;
         initComponents();
         
         this.setLocationRelativeTo(parent);
@@ -30,7 +33,7 @@
     private void initComponents() {
 
        mainTabbedPane = new javax.swing.JTabbedPane();
-        installNewAppsPanel1 = new InstallFromStorePanel(appManager, fileUtil, 
this);
+        installNewAppsPanel1 = new InstallFromStorePanel(appManager, fileUtil, 
taskManager, this);
         currentlyInstalledAppsPanel1 = new 
CurrentlyInstalledAppsPanel(appManager);
         checkForUpdatesPanel1 = new CheckForUpdatesPanel();
 

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
     2012-04-24 20:24:48 UTC (rev 28968)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
     2012-04-24 20:29:22 UTC (rev 28969)
@@ -40,6 +40,7 @@
         updatesAvailableLabel.setText("0 updates available.");
 
         installSelectedButton.setText("Update Selected");
+        installSelectedButton.setEnabled(false);
         installSelectedButton.addActionListener(new 
java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 installSelectedButtonActionPerformed(evt);
@@ -47,6 +48,7 @@
         });
 
         installAllTable.setText("Update All");
+        installAllTable.setEnabled(false);
         installAllTable.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 installAllTableActionPerformed(evt);

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
      2012-04-24 20:24:48 UTC (rev 28968)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
      2012-04-24 20:29:22 UTC (rev 28969)
@@ -78,6 +78,7 @@
         appsInstalledLabel.setText("0 Apps installed.");
 
         enableSelectedButton.setText("Reinstall");
+        enableSelectedButton.setEnabled(false);
         enableSelectedButton.addActionListener(new 
java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 enableSelectedButtonActionPerformed(evt);
@@ -85,6 +86,7 @@
         });
 
         disableSelectedButton.setText("Uninstall");
+        disableSelectedButton.setEnabled(false);
         disableSelectedButton.addActionListener(new 
java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 disableSelectedButtonActionPerformed(evt);
@@ -142,8 +144,14 @@
         Set<App> selectedApps = getSelectedApps();
         
         for (App app : selectedApps) {
-                       appManager.installApp(app);
+               // Only install apps that are not already installed
+               if (app.getStatus() != AppStatus.INSTALLED) {
+                       appManager.installApp(app);
+               }
         }
+        
+        enableSelectedButton.setEnabled(false);
+        disableSelectedButton.setEnabled(true);
     }
 
     private void 
disableSelectedButtonActionPerformed(java.awt.event.ActionEvent evt) {
@@ -151,8 +159,14 @@
        Set<App> selectedApps = getSelectedApps();
         
         for (App app : selectedApps) {
-                       appManager.uninstallApp(app);
+               // Only uninstall apps that are installed
+               if (app.getStatus() == AppStatus.INSTALLED) {
+                       appManager.uninstallApp(app);
+               }
         }
+        
+        disableSelectedButton.setEnabled(false);
+        enableSelectedButton.setEnabled(true);
     }
 
     private void showTypeComboxBoxActionPerformed(java.awt.event.ActionEvent 
evt) {
@@ -220,8 +234,8 @@
                tableModel.addRow(new Object[]{
                                        app,
                                        app.getAppName(),
+                                       app.getAuthors(),
                                        app.getVersion(),
-                                       app.getAuthors(),
                                        app.getStatus()
                        });
        }
@@ -268,15 +282,54 @@
        if (numSelected == 0) {
                descriptionTextArea.setText("");
                
+               // Disable buttons
+               enableSelectedButton.setEnabled(false);
+               disableSelectedButton.setEnabled(false);
+               
        // If a single app is selected, show its app description
        } else if (numSelected == 1){
                App selectedApp = selectedApps.iterator().next();
                
-               String text = String.valueOf(selectedApp.getAppStoreUrl());
-               text += "\n";
+               String text = "App description not found.";
                descriptionTextArea.setText(text);
+               
+               // Enable/disable the appropriate button
+               if (selectedApp.getStatus() == AppStatus.INSTALLED) {
+                       enableSelectedButton.setEnabled(false);
+                       disableSelectedButton.setEnabled(true);
+               } else {
+                       enableSelectedButton.setEnabled(true);
+                       disableSelectedButton.setEnabled(false);
+               }
        } else {
-               descriptionTextArea.setText("");
+               descriptionTextArea.setText(numSelected + " apps selected.");
+               
+               // Enable/disable the appropriate buttons
+               boolean allInstalled = true;
+               boolean allUninstalled = true;
+               
+               for (App selectedApp : selectedApps) {
+                       if (selectedApp.getStatus() == AppStatus.INSTALLED) {
+                               allUninstalled = false;
+                       }
+                       
+                       if (selectedApp.getStatus() != AppStatus.INSTALLED) {
+                               allInstalled = false;
+                       }
+               }
+               
+               if (allInstalled) {
+                       enableSelectedButton.setEnabled(false);
+                       disableSelectedButton.setEnabled(true);
+               } else if (allUninstalled) {
+                       enableSelectedButton.setEnabled(true);
+                       disableSelectedButton.setEnabled(false);
+               } else {
+                       // If some of the selected apps are installed and some 
are uninstalled,
+                       // enable both buttons
+                       enableSelectedButton.setEnabled(true);
+                       disableSelectedButton.setEnabled(true);
+               }
        }
     }
 }

Modified: 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallFromStorePanel.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallFromStorePanel.java
    2012-04-24 20:24:48 UTC (rev 28968)
+++ 
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallFromStorePanel.java
    2012-04-24 20:29:22 UTC (rev 28969)
@@ -3,8 +3,11 @@
 import java.awt.Container;
 import java.awt.Desktop;
 import java.awt.Font;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
 import java.io.File;
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
 import java.net.URISyntaxException;
 import java.util.Collection;
 import java.util.HashMap;
@@ -16,6 +19,7 @@
 
 import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
 import javax.swing.event.HyperlinkEvent;
 import javax.swing.event.HyperlinkEvent.EventType;
@@ -38,6 +42,10 @@
 import org.cytoscape.app.internal.net.WebQuerier;
 import org.cytoscape.util.swing.FileChooserFilter;
 import org.cytoscape.util.swing.FileUtil;
+import org.cytoscape.work.Task;
+import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.TaskManager;
+import org.cytoscape.work.TaskMonitor;
 
 /**
  * This class represents the panel in the App Manager dialog's tab used for 
installing new apps.
@@ -63,17 +71,70 @@
        
        private AppManager appManager;
        private FileUtil fileUtil;
+       private TaskManager taskManager;
        private Container parent;
        
-    public InstallFromStorePanel(AppManager appManager, FileUtil fileUtil, 
Container parent) {
+    public InstallFromStorePanel(final AppManager appManager, FileUtil 
fileUtil, TaskManager taskManager, Container parent) {
         this.appManager = appManager;
         this.fileUtil = fileUtil;
+        this.taskManager = taskManager;
         this.parent = parent;
        initComponents();
         
-       addTagInformation();
+               taskManager.execute(new TaskIterator(new Task(){
+
+                       // Obtain information for all available apps, then 
append tag information
+                       @Override
+                       public void run(TaskMonitor taskMonitor) throws 
Exception {
+                               taskMonitor.setTitle("Obtaining Apps from App 
Store");
+                               
+                               WebQuerier webQuerier = 
appManager.getWebQuerier();
+                       
+                               taskMonitor.setStatusMessage("Getting available 
apps");
+                               Set<WebApp> availableApps = 
webQuerier.getAllApps();
+                               
+                       // Obtain available tags
+                       Set<WebQuerier.AppTag> availableTags = 
webQuerier.getAllTags();
+                       
+                       double progress = 0;
+                       
+                       for (WebQuerier.AppTag appTag : availableTags) {
+
+                               taskMonitor.setStatusMessage("Getting apps for 
tag: " + appTag.getFullName());
+                               progress += 1.0 / availableTags.size();
+                               taskMonitor.setProgress(progress);
+                               
+                               // Obtain apps for the current tag
+                               Set<WebApp> tagApps = 
webQuerier.getAppsByTag(appTag.getName());
+                               
+                               // Assume the set of apps returned is a subset 
of all available apps
+                               for (WebApp tagApp : tagApps) {
+                                       tagApp.getAppTags().add(appTag);
+                               }
+                       }
+                               
+                               // Once the information is obtained, update the 
tree
+                               SwingUtilities.invokeLater(new Runnable() {
+
+                                       @Override
+                                       public void run() {
+                                               
populateTree(appManager.getWebQuerier().getAllApps());
+                                       }
+                                       
+                               });
+                       }
+
+                       @Override
+                       public void cancel() {
+                       }
+                       
+               }));
+       
+               /*
+               addTagInformation();
         populateTree(appManager.getWebQuerier().getAllApps());
-        
+        */
+               
         setupDescriptionListener();
         setupHyperlinkListener();
         setupTextFieldListener();
@@ -103,7 +164,7 @@
 
         resultsSplitPane.setDividerLocation(245);
 
-        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new 
javax.swing.tree.DefaultMutableTreeNode("JTree");
+        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new 
javax.swing.tree.DefaultMutableTreeNode("Available Apps (0)");
         resultsTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
         resultsScrollPane.setViewportView(resultsTree);
 
@@ -417,22 +478,7 @@
     
     // Adds tag information to the set of available apps
     private void addTagInformation() {
-       WebQuerier webQuerier = appManager.getWebQuerier();
-       Set<WebApp> webApps = webQuerier.getAllApps();
        
-       // Obtain available tags
-       Set<WebQuerier.AppTag> availableTags = webQuerier.getAllTags();
-       
-       for (WebQuerier.AppTag appTag : availableTags) {
-
-               // Obtain apps for the current tag
-               Set<WebApp> tagApps = webQuerier.getAppsByTag(appTag.getName());
-               
-               // Assume the set of apps returned is a subset of all available 
apps
-               for (WebApp tagApp : tagApps) {
-                       tagApp.getAppTags().add(appTag);
-               }
-       }
     }
     
     private void updateDescriptionBox() {

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