Author: paperwing
Date: 2012-08-15 15:03:16 -0700 (Wed, 15 Aug 2012)
New Revision: 30201

Modified:
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/KarafArchiveApp.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleAppOld.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/UpdateManager.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/AppManagerDialog.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
Log:
Removed unused functions, moved simple app parsing-related fields back to 
AppParser for convenience, can now check for and download selected updates, but 
need to handle simple apps that cannot be uninstalled without restart. Need to 
make new versions install on restart. Also fixes #1371.

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
 2012-08-15 19:26:22 UTC (rev 30200)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
 2012-08-15 22:03:16 UTC (rev 30201)
@@ -84,15 +84,10 @@
         */
        public enum AppStatus{
                INSTALLED("Installed"),
-               TO_BE_UNINSTALLED("Uninstalled-on-restart"),
-               TO_BE_DISABLED("Disable-on-restart"),
                DISABLED("Disabled"),
                UNINSTALLED("Uninstalled"),
                TO_BE_INSTALLED("Install-on-restart"),
-               FILE_MOVED("File Moved (Uninstalled)"),
-               FILE_MOVED_UNINSTALLED("File Moved (Uninstalled)"),
-               // Currently, simple apps require a restart for uninstall, so 
we require a restart even if file is moved
-               FILE_MOVED_INSTALLED("File Moved (Uninstall-on-restart)");
+               FILE_MOVED("File Moved (Uninstalled)");
                
                String readableStatus;
                
@@ -181,7 +176,6 @@
                        throw new AppInstallException("This app has already 
been installed.");
                }
                
-               
                for (App app : appManager.getApps()) {
                        if (this.heuristicEquals(app) && this != app) {
                                

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
  2012-08-15 19:26:22 UTC (rev 30200)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
  2012-08-15 22:03:16 UTC (rev 30201)
@@ -144,10 +144,10 @@
                
                setupAlterationMonitor();
 
-               // Install previously enabled apps
+               // Obtain previously disabled, installed apps
                
-               Set<App> installedFolderApps = obtainAppsFromDirectory(new 
File(getInstalledAppsPath()), false);
-               for (App app: installedFolderApps) {
+               Set<App> disabledFolderApps = obtainAppsFromDirectory(new 
File(getDisabledAppsPath()), false);
+               for (App app: disabledFolderApps) {
                        try {
                                boolean appRegistered = false;
                                for (App regApp : apps) {
@@ -156,15 +156,18 @@
                                }
                                if (!appRegistered) {
                                        apps.add(app);
-                                       app.install(this);
-                               }
-                       } catch (AppInstallException e) {
-                               logger.warn("Failed to initially install app, " 
+ e);
+                                       app.disable(this);
+                               } else {
+                                       // Delete the copy
+                                       
FileUtils.deleteQuietly(app.getAppFile());
+                                       app.setAppFile(null);
+                               }               
+                       } catch (AppDisableException e) {
                        }
                }
                
-               Set<App> disabledFolderApps = obtainAppsFromDirectory(new 
File(getDisabledAppsPath()), false);
-               for (App app: disabledFolderApps) {
+               Set<App> uninstalledFolderApps = obtainAppsFromDirectory(new 
File(getUninstalledAppsPath()), false);
+               for (App app: uninstalledFolderApps) {
                        try {
                                boolean appRegistered = false;
                                for (App regApp : apps) {
@@ -173,14 +176,18 @@
                                }
                                if (!appRegistered) {
                                        apps.add(app);
-                                       app.disable(this);
-                               }                               
-                       } catch (AppDisableException e) {
+                                       app.uninstall(this);
+                               } else {
+                                       // Delete the copy
+                                       
FileUtils.deleteQuietly(app.getAppFile());
+                                       app.setAppFile(null);
+                               }
+                       } catch (AppUninstallException e) {
                        }
                }
                
-               Set<App> uninstalledFolderApps = obtainAppsFromDirectory(new 
File(getUninstalledAppsPath()), false);
-               for (App app: uninstalledFolderApps) {
+               Set<App> installedFolderApps = obtainAppsFromDirectory(new 
File(getInstalledAppsPath()), false);
+               for (App app: installedFolderApps) {
                        try {
                                boolean appRegistered = false;
                                for (App regApp : apps) {
@@ -189,9 +196,14 @@
                                }
                                if (!appRegistered) {
                                        apps.add(app);
-                                       app.uninstall(this);
+                                       app.install(this);
+                               } else {
+                                       // Delete the copy
+                                       
FileUtils.deleteQuietly(app.getAppFile());
+                                       app.setAppFile(null);
                                }
-                       } catch (AppUninstallException e) {
+                       } catch (AppInstallException e) {
+                               logger.warn("Failed to initially install app, " 
+ e);
                        }
                }
                
@@ -243,6 +255,14 @@
                                        if (parsedApp.heuristicEquals(app)) {
                                                registeredApp = app;
                                                
+                                               // Delete old file if it was 
still there
+                                               // TODO: Possible rename from 
filename-2 to filename?
+                                               File oldFile = 
registeredApp.getAppFile();
+                                               
+                                               if (oldFile.exists()) {
+                                                       
FileUtils.deleteQuietly(oldFile);
+                                               }
+                                               
                                                // Update file reference to 
reflect file having been moved
                                                registeredApp.setAppFile(file);
                                        }
@@ -298,6 +318,14 @@
                                        if (parsedApp.heuristicEquals(app)) {
                                                registeredApp = app;
                                                
+                                               // Delete old file if it was 
still there
+                                               // TODO: Possible rename from 
filename-2 to filename?
+                                               File oldFile = 
registeredApp.getAppFile();
+                                               
+                                               if (oldFile.exists()) {
+                                                       
FileUtils.deleteQuietly(oldFile);
+                                               }
+                                               
                                                // Update file reference to 
reflect file having been moved
                                                registeredApp.setAppFile(file);
                                        }
@@ -334,7 +362,6 @@
                        }
                });
                
-               
                FileAlterationObserver uninstallAlterationObserver = new 
FileAlterationObserver(
                                getUninstalledAppsPath(), new 
SingleLevelFileFilter(new File(getUninstalledAppsPath())), IOCase.SYSTEM);
                
@@ -354,6 +381,14 @@
                                        if (parsedApp.heuristicEquals(app)) {
                                                registeredApp = app;
                                                
+                                               // Delete old file if it was 
still there
+                                               // TODO: Possible rename from 
filename-2 to filename?
+                                               File oldFile = 
registeredApp.getAppFile();
+                                               
+                                               if (oldFile.exists()) {
+                                                       
FileUtils.deleteQuietly(oldFile);
+                                               }
+                                               
                                                // Update file reference to 
reflect file having been moved
                                                registeredApp.setAppFile(file);
                                        }
@@ -410,6 +445,7 @@
                }
        }
        
+       /*
        private void setupKarafDeployMonitor(FileAlterationMonitor 
fileAlterationMonitor) {
                // Set up the FileAlterationMonitor to install/uninstall bundle 
apps when they are moved
                // to the Karaf deploy directory
@@ -475,6 +511,7 @@
                
                fileAlterationMonitor.addObserver(karafDeployObserver);
        }
+       */
        
        public CySwingAppAdapter getSwingAppAdapter() {
                return swingAppAdapter;
@@ -709,7 +746,7 @@
                }
        }
        
-       
+       /*
        public String getKarafDeployDirectory() {
                File directory = new File(System.getProperty("user.home") + 
File.separator + ".cytoscape" + File.separator + "3.0"
                                + File.separator + "apps" + File.separator + 
"deploy");
@@ -718,7 +755,9 @@
                
                return directory.getAbsolutePath();
        }
+       */
        
+       /*
        public void cleanKarafDeployDirectory() {
                String[] bundleAppExtensions = new String[]{"kar"};
                File karafDeployDirectory = new File(getKarafDeployDirectory());
@@ -732,6 +771,7 @@
                        }
                }
        }
+       */
        
        private boolean checkIfCytoscapeApp(File file) {
                JarFile jarFile = null;
@@ -819,28 +859,20 @@
                
                Set<App> parsedApps = new HashSet<App>();
                
-               String karafDeployDirectory = getKarafDeployDirectory();
-               
                App app;
                for (File potentialApp : files) {
                        
-                       if (ignoreDuplicateBundleApps
-                                       && (new File(karafDeployDirectory + 
File.separator + potentialApp.getName())).exists()) {
-                               // Skip file
-                       } else {
-                       
+                       app = null;
+                       try {
+                               app = appParser.parseApp(potentialApp);
+                       } catch (AppParsingException e) {
+                               DebugHelper.print("Failed to parse " + 
potentialApp + ", error: " + e.getMessage());
                                app = null;
-                               try {
-                                       app = appParser.parseApp(potentialApp);
-                               } catch (AppParsingException e) {
-                                       DebugHelper.print("Failed to parse " + 
potentialApp + ", error: " + e.getMessage());
-                                       app = null;
-                               } finally {
-                                       if (app != null) {
-                                               parsedApps.add(app);
-                                               
-                                               DebugHelper.print("App parsed: 
" + app);
-                                       }
+                       } finally {
+                               if (app != null) {
+                                       parsedApps.add(app);
+                                       
+                                       DebugHelper.print("App parsed: " + app);
                                }
                        }
                }

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
   2012-08-15 19:26:22 UTC (rev 30200)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
   2012-08-15 22:03:16 UTC (rev 30201)
@@ -16,6 +16,7 @@
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
+import java.util.regex.Pattern;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParserFactory;
@@ -36,7 +37,39 @@
  * 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. 
+        * */
+       public 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
+        */
+       public 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
+        */
+       public static final String APP_VERSION_TAG = "Cytoscape-App-Version";
+       
+       /**
+        * The name of the key in the app jar's manifest file indicating the 
major versions of
+        * Cytoscape that the app is known to be compatible with in 
comma-delimited form
+        */
+       public static final String APP_COMPATIBLE_TAG = 
"Cytoscape-API-Compatibility";
+       
+       /**
+        * A regular expression representing valid app versions, which are in 
the format major.minor[.patch][-tag],
+        * eg. 3.0.0-SNAPSHOT, or 3.0.
+        */
+       public static final Pattern APP_VERSION_TAG_REGEX = 
Pattern.compile("(0|([1-9]+\\d*))\\.(\\d)+(\\.(\\d)+)?(.*)?");
+
+       
+       /**
         * A regular expression representing valid values for the entry 
containing the major versions of Cytoscape
         * that the app is known to work with in, in comma-delimited form. 
Examples that work are "3.0, 3.1"  or "2, 3.0".
         * Examples that do not match are "1.0b" and "v1, v2", as these contain 
non-digit characters.
@@ -129,19 +162,19 @@
                // Bundle apps are instantiated by OSGi using their activator 
classes
                if (!bundleApp) {
                        // Obtain the fully-qualified name of the class to 
instantiate upon app installation
-                       entryClassName = 
manifest.getMainAttributes().getValue(SimpleAppOld.APP_CLASS_TAG);
+                       entryClassName = 
manifest.getMainAttributes().getValue(APP_CLASS_TAG);
                        if (entryClassName == null || 
entryClassName.trim().length() == 0) {
-                               throw new AppParsingException("Jar is missing 
value for entry " + SimpleAppOld.APP_CLASS_TAG + " in its manifest file.");
+                               throw new AppParsingException("Jar is missing 
value for entry " + APP_CLASS_TAG + " in its manifest file.");
                        }
                }
                
                // Obtain the human-readable name of the app
                String readableName = null;
                if (!bundleApp) {
-                       readableName = 
manifest.getMainAttributes().getValue(SimpleAppOld.APP_READABLE_NAME_TAG);
+                       readableName = 
manifest.getMainAttributes().getValue(APP_READABLE_NAME_TAG);
                        
                        if (readableName == null || 
readableName.trim().length() == 0) {
-                               throw new AppParsingException("Jar is missing 
value for entry " + SimpleAppOld.APP_READABLE_NAME_TAG + " in its manifest 
file.");
+                               throw new AppParsingException("Jar is missing 
value for entry " + APP_READABLE_NAME_TAG + " in its manifest file.");
                        }
                } else {
                        readableName = 
manifest.getMainAttributes().getValue("Bundle-Name");
@@ -158,12 +191,12 @@
                // Obtain the version of the app, in major.minor.patch[-tag] 
format, ie. 3.0.0-SNAPSHOT or 1.2.3
                String appVersion = null;
                if (!bundleApp) {
-                       appVersion = 
manifest.getMainAttributes().getValue(SimpleAppOld.APP_VERSION_TAG);
+                       appVersion = 
manifest.getMainAttributes().getValue(APP_VERSION_TAG);
                        
                        if (appVersion == null || appVersion.trim().length() == 
0) {
-                               throw new AppParsingException("Jar is missing 
value for entry " + SimpleAppOld.APP_VERSION_TAG + " in its manifiest file.");
-                       } else if 
(!SimpleAppOld.APP_VERSION_TAG_REGEX.matcher(appVersion).matches()) {
-                               throw new AppParsingException("The app version 
specified in its manifest file under the key " + SimpleAppOld.APP_VERSION_TAG
+                               throw new AppParsingException("Jar is missing 
value for entry " + APP_VERSION_TAG + " in its manifiest file.");
+                       } else if 
(!APP_VERSION_TAG_REGEX.matcher(appVersion).matches()) {
+                               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. 2.1, 2.1-test, 3.0.0 or 3.0.0-SNAPSHOT");
                        }
                } else {
@@ -172,7 +205,7 @@
                        if (appVersion == null || appVersion.trim().length() == 
0) {
                                
                                // For now, while it hasn't been decided, 
accept values for Cytoscape-App-Version if Bundle-Version is not found
-                               appVersion = 
manifest.getMainAttributes().getValue(SimpleAppOld.APP_VERSION_TAG);
+                               appVersion = 
manifest.getMainAttributes().getValue(APP_VERSION_TAG);
                                
                                if (appVersion == null || 
appVersion.trim().length() == 0) {
                                        throw new AppParsingException("Bundle 
jar manifest has no entry for Bundle-Version");
@@ -180,18 +213,18 @@
                        }
                }
                
-               String compatibleVersions = 
manifest.getMainAttributes().getValue(SimpleAppOld.APP_COMPATIBLE_TAG);
+               String compatibleVersions = 
manifest.getMainAttributes().getValue(APP_COMPATIBLE_TAG);
                if (compatibleVersions == null || 
compatibleVersions.trim().length() == 0) {
             if (bundleApp) {
-                logger.info("Bundle app " + file.getName() + " manifest does 
not contain the entry \"" + SimpleAppOld.APP_COMPATIBLE_TAG
+                logger.info("Bundle app " + file.getName() + " manifest does 
not contain the entry \"" + APP_COMPATIBLE_TAG
                         + "\". Assuming default value 3.0.");
                 compatibleVersions = "3.0";
             } else {
-                throw new AppParsingException("Jar is missing value for entry 
" + SimpleAppOld.APP_COMPATIBLE_TAG + " in its manifest file.");
+                throw new AppParsingException("Jar is missing value for entry 
" + APP_COMPATIBLE_TAG + " in its manifest file.");
             }
                } else if 
(!compatibleVersions.matches(APP_COMPATIBLE_TAG_REGEX)) {
                        throw new AppParsingException("The known compatible 
versions of Cytoscape specified in the manifest under the"
-                                       + " key " + 
SimpleAppOld.APP_COMPATIBLE_TAG + " does not match the form of a 
comma-delimited list of versions of the form"
+                                       + " key " + APP_COMPATIBLE_TAG + " does 
not match the form of a comma-delimited list of versions of the form"
                                        + " major[.minor] (eg. 1 or 1.0) with 
variable whitespace around versions");
                }
                

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/KarafArchiveApp.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/KarafArchiveApp.java
     2012-08-15 19:26:22 UTC (rev 30200)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/KarafArchiveApp.java
     2012-08-15 22:03:16 UTC (rev 30201)
@@ -63,8 +63,10 @@
                return bundle;
        }
 
+       
        @Override
        public void install(AppManager appManager) throws AppInstallException {
+               /*
                
                // Check if we already have an app object representing this app 
registered to the app manager
                for (App app : appManager.getApps()) {
@@ -120,22 +122,15 @@
                //System.out.println("features from app: " + 
featuresSet.size());
                //System.out.println("available features: " + 
featuresService.listFeatures().length);
                
-               /*
-               if (installedFeatures.size() == featuresSet.size()) {
-                       
-               } else {
-                       this.getAppTemporaryInstallFile().delete();
-                       throw new AppInstallException("Not all Karaf features 
were successfully installed from the bundle app.");
-               }
-               */
-               
                if (!appManager.getApps().contains(this)) {
                        appManager.getApps().add(this);
                }
                
                this.setStatus(AppStatus.INSTALLED);
+               
+               */
        }
-
+       
        private List<Feature> getCorrespondingFeatures(FeaturesService 
featuresService) {
                List<Feature> correspondingFeatures = new LinkedList<Feature>();
                
@@ -193,7 +188,7 @@
                
                this.getAppTemporaryInstallFile().delete();
                
-               this.setStatus(AppStatus.TO_BE_UNINSTALLED);
+               this.setStatus(AppStatus.UNINSTALLED);
        }
 
        @Override

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleAppOld.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleAppOld.java
        2012-08-15 19:26:22 UTC (rev 30200)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleAppOld.java
        2012-08-15 22:03:16 UTC (rev 30201)
@@ -16,36 +16,7 @@
 import org.cytoscape.app.swing.CySwingAppAdapter;
 
 public class SimpleAppOld extends App {
-       /** 
-        * 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. 
-        * */
-       public 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
-        */
-       public 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
-        */
-       public static final String APP_VERSION_TAG = "Cytoscape-App-Version";
-       
-       /**
-        * The name of the key in the app jar's manifest file indicating the 
major versions of
-        * Cytoscape that the app is known to be compatible with in 
comma-delimited form
-        */
-       public static final String APP_COMPATIBLE_TAG = 
"Cytoscape-API-Compatibility";
-       
-       /**
-        * A regular expression representing valid app versions, which are in 
the format major.minor[.patch][-tag],
-        * eg. 3.0.0-SNAPSHOT, or 3.0.
-        */
-       public static final Pattern APP_VERSION_TAG_REGEX = 
Pattern.compile("(0|([1-9]+\\d*))\\.(\\d)+(\\.(\\d)+)?(.*)?");
-
        @Override
        public Object createAppInstance(CySwingAppAdapter appAdapter) throws 
AppInstanceException {
                
@@ -127,7 +98,7 @@
                defaultUninstall(appManager);
                                
                // Simple apps require a Cytoscape restart to be uninstalled
-               setStatus(AppStatus.TO_BE_UNINSTALLED);
+               setStatus(AppStatus.UNINSTALLED);
        }
        
        @Override

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/UpdateManager.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/UpdateManager.java
   2012-08-15 19:26:22 UTC (rev 30200)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/UpdateManager.java
   2012-08-15 22:03:16 UTC (rev 30201)
@@ -13,9 +13,11 @@
 import org.cytoscape.app.internal.exception.AppDownloadException;
 import org.cytoscape.app.internal.exception.AppInstallException;
 import org.cytoscape.app.internal.exception.AppParsingException;
+import org.cytoscape.app.internal.exception.AppUninstallException;
 import org.cytoscape.app.internal.manager.App;
 import org.cytoscape.app.internal.manager.AppManager;
 import org.cytoscape.app.internal.util.DebugHelper;
+import org.cytoscape.application.events.SetSelectedNetworksEvent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -51,7 +53,13 @@
        }
        
        public Set<Update> getUpdates() {
-               return this.updates;
+               Set<Update> updatesCopy = new HashSet<Update>();
+               
+               for (Update update : updates) {
+                       updatesCopy.add(update);
+               }
+               
+               return updatesCopy;
        }
        
        /**
@@ -75,12 +83,15 @@
                }
                
                if (appFile != null) {
-               
-               App parsedApp;
+                       
+                       App parsedApp;
                        try {
                                // Parse app
                                parsedApp = 
appManager.getAppParser().parseApp(appFile);
                                
+                               // Uninstall old app
+                               appManager.uninstallApp(update.getApp());
+                               
                                // Install app
                                appManager.installApp(parsedApp);
                                
@@ -88,15 +99,28 @@
                                        this.updates.remove(update);
                                }
                                
+                               // Remove old app
+                               // appManager.removeApp(update.getApp());
+                               
                                fireUpdatesChangedEvent();
                        } catch (AppParsingException e) {
                                e.printStackTrace();
                        } catch (AppInstallException e) {
                                e.printStackTrace();
+                       } catch (AppUninstallException e) {
+                               e.printStackTrace();
                        }               
                }
        }
        
+       public void addUpdatesChangedListener(UpdatesChangedListener 
updatesChangedListener) {
+               this.updatesChangedListeners.add(updatesChangedListener);
+       }
+       
+       public void removeUpdatesChangedListener(UpdatesChangedListener 
updatesChangedListener) {
+               this.updatesChangedListeners.remove(updatesChangedListener);
+       }
+       
        private void fireUpdatesChangedEvent() {
                UpdatesChangedEvent updatesChangedEvent = new 
UpdatesChangedEvent(this);
                

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
      2012-08-15 19:26:22 UTC (rev 30200)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
      2012-08-15 22:03:16 UTC (rev 30201)
@@ -355,7 +355,7 @@
 
                                                        @Override
                                                        public int 
compare(Release first, Release second) {
-                                                               return 
compareVersions(first.getReleaseVersion(), second.getReleaseVersion());
+                                                               return 
compareVersions(second.getReleaseVersion(), first.getReleaseVersion());
                                                        }
                                                        
                                                });

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/AppManagerDialog.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/AppManagerDialog.java
 2012-08-15 19:26:22 UTC (rev 30200)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/AppManagerDialog.java
 2012-08-15 22:03:16 UTC (rev 30201)
@@ -34,7 +34,7 @@
        mainTabbedPane = new javax.swing.JTabbedPane();
         installNewAppsPanel1 = new InstallFromStorePanel(appManager, fileUtil, 
taskManager, this);
         currentlyInstalledAppsPanel1 = new 
CurrentlyInstalledAppsPanel(appManager);
-        checkForUpdatesPanel1 = new CheckForUpdatesPanel(appManager);
+        checkForUpdatesPanel1 = new CheckForUpdatesPanel(appManager, 
taskManager);
 
         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
         setTitle("App Manager");

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
     2012-08-15 19:26:22 UTC (rev 30200)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
     2012-08-15 22:03:16 UTC (rev 30201)
@@ -12,10 +12,16 @@
 import javax.swing.event.ListSelectionListener;
 import javax.swing.table.DefaultTableModel;
 
+import org.cytoscape.app.internal.event.UpdatesChangedEvent;
+import org.cytoscape.app.internal.event.UpdatesChangedListener;
 import org.cytoscape.app.internal.manager.App;
 import org.cytoscape.app.internal.manager.AppManager;
 import org.cytoscape.app.internal.net.Update;
 import org.cytoscape.app.internal.net.UpdateManager;
+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 
checking for app updates.
@@ -29,7 +35,7 @@
        private javax.swing.JLabel descriptionLabel;
     private javax.swing.JScrollPane descriptionScrollPane;
     private javax.swing.JTextArea descriptionTextArea;
-    private javax.swing.JButton installAllTable;
+    private javax.swing.JButton installAllButton;
     private javax.swing.JButton installSelectedButton;
     private javax.swing.JLabel lastCheckForUpdatesLabel;
     private javax.swing.JLabel updateCheckTimeLabel;
@@ -39,19 +45,21 @@
        
     private UpdateManager updateManager;
     private AppManager appManager;
+    private TaskManager taskManager;
     
-    public CheckForUpdatesPanel(AppManager appManager) {
-        initComponents();
-        
-        this.updateManager = new UpdateManager();
+    public CheckForUpdatesPanel(AppManager appManager, TaskManager 
taskManager) {
+       this.updateManager = new UpdateManager();
         this.appManager = appManager;
+        this.taskManager = taskManager;
+       
+       initComponents();
     }
 
     private void initComponents() {
 
         updatesAvailableLabel = new javax.swing.JLabel();
         installSelectedButton = new javax.swing.JButton();
-        installAllTable = new javax.swing.JButton();
+        installAllButton = new javax.swing.JButton();
         updatesScrollPane = new javax.swing.JScrollPane();
         updatesTable = new javax.swing.JTable();
         lastCheckForUpdatesLabel = new javax.swing.JLabel();
@@ -70,11 +78,11 @@
             }
         });
 
-        installAllTable.setText("Update All");
-        installAllTable.setEnabled(false);
-        installAllTable.addActionListener(new java.awt.event.ActionListener() {
+        installAllButton.setText("Update All");
+        installAllButton.setEnabled(false);
+        installAllButton.addActionListener(new java.awt.event.ActionListener() 
{
             public void actionPerformed(java.awt.event.ActionEvent evt) {
-                installAllTableActionPerformed(evt);
+                installAllButtonActionPerformed(evt);
             }
         });
 
@@ -132,7 +140,7 @@
                             .add(layout.createSequentialGroup()
                                 .add(installSelectedButton)
                                 
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
-                                .add(installAllTable))
+                                .add(installAllButton))
                             .add(descriptionLabel))
                         .add(0, 0, Short.MAX_VALUE))))
         );
@@ -153,10 +161,31 @@
                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                 
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                     .add(installSelectedButton)
-                    .add(installAllTable))
+                    .add(installAllButton))
                 .addContainerGap())
         );
         
+        updateManager.addUpdatesChangedListener(new UpdatesChangedListener() {
+                       
+                       @Override
+                       public void appsChanged(UpdatesChangedEvent event) {
+                               repopulateUpdatesTable();
+
+                               // Enable/disable the update all button 
depending on update availability
+                               if (event.getSource().getUpdates().size() > 0) {
+                                       if (!installAllButton.isEnabled()) {
+                                               
installAllButton.setEnabled(true);
+                                       }
+                               } else {
+                                       if (installAllButton.isEnabled()) {
+                                               
installAllButton.setEnabled(false);
+                                       }
+                               }
+                       }
+               });
+        
+        installAllButton.setEnabled(true);
+        
         this.addComponentListener(new ComponentAdapter() {
                
                @Override
@@ -176,7 +205,7 @@
                                + lastUpdateCheckTime.get(Calendar.MINUTE) + " "
                                + (lastUpdateCheckTime.get(Calendar.AM_PM) == 
Calendar.AM ? "am" : "pm"));
                        
-                       populateUpdatesTable();
+                       // populateUpdatesTable();
                }
         });
         
@@ -184,14 +213,70 @@
     }
 
     private void 
installSelectedButtonActionPerformed(java.awt.event.ActionEvent evt) {
-        // TODO add your handling code here:
+        final Set<Update> selectedUpdates = getSelectedUpdates();
+        final int updateCount = selectedUpdates.size();
+        
+        taskManager.execute(new TaskIterator(new Task() {
+
+                       @Override
+                       public void run(TaskMonitor taskMonitor) throws 
Exception {
+                               taskMonitor.setTitle("Installing updates");
+                               
+                               double progress = 0;
+                               int count = 0;
+                               
+                               for (Update update : selectedUpdates) {
+                                       count++;
+                                       
+                                       
taskMonitor.setStatusMessage("Installing update " 
+                                                       + 
update.getRelease().getReleaseVersion() 
+                                                       + " for " + 
update.getApp().getAppName() 
+                                                       + " (" + count + "/" + 
updateCount + ")");
+                                       
+                               updateManager.installUpdate(update, appManager);
+                       }
+                       }
+
+                       @Override
+                       public void cancel() {  
+                       }
+               
+        }));
     }
 
-    private void installAllTableActionPerformed(java.awt.event.ActionEvent 
evt) {
-        // TODO add your handling code here:
+    private void installAllButtonActionPerformed(java.awt.event.ActionEvent 
evt) {
+        final Set<Update> updates = updateManager.getUpdates();
+        final int updateCount = updates.size();
+        
+        taskManager.execute(new TaskIterator(new Task() {
+
+                       @Override
+                       public void run(TaskMonitor taskMonitor) throws 
Exception {
+                               taskMonitor.setTitle("Installing updates");
+                               
+                               double progress = 0;
+                               int count = 0;
+                               
+                               for (Update update : updates) {
+                                       count++;
+                                       
+                                       
taskMonitor.setStatusMessage("Installing update " 
+                                                       + 
update.getRelease().getReleaseVersion() 
+                                                       + " for " + 
update.getApp().getAppName() 
+                                                       + " (" + count + "/" + 
updateCount + ")");
+                                       
+                               updateManager.installUpdate(update, appManager);
+                       }
+                       }
+
+                       @Override
+                       public void cancel() {
+                       }
+               
+        }));
     }
     
-    private void populateUpdatesTable() {
+    private void repopulateUpdatesTable() {
    
        SwingUtilities.invokeLater(new Runnable() {
                
@@ -274,17 +359,26 @@
     
     private void updateDescriptionBox() {
        Set<Update> selectedUpdates = getSelectedUpdates();
-
-       if (selectedUpdates.size() == 1) {
+       
+       if (selectedUpdates.size() == 0) {
+               descriptionTextArea.setText("");
+               installSelectedButton.setEnabled(false);
+       } else if (selectedUpdates.size() == 1) {
                Update update = selectedUpdates.iterator().next();
                descriptionTextArea.setText("Update for " 
                                + update.getApp().getAppName() 
                                + ": " + update.getApp().getVersion() + " -> " 
                                + update.getRelease().getReleaseVersion());
                
-               
+               if (!installSelectedButton.isEnabled()) {
+                       installSelectedButton.setEnabled(true);
+               }
        } else if (selectedUpdates.size() > 1) {
+               descriptionTextArea.setText("");
                
+               if (!installSelectedButton.isEnabled()) {
+                       installSelectedButton.setEnabled(true);
+               }
        }
        
 //     descriptionTextArea.setText("Update from ")

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