Author: paperwing
Date: 2012-07-25 13:53:06 -0700 (Wed, 25 Jul 2012)
New Revision: 29987

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/SimpleApp.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
Log:
Disable apps button now working; AppParser.java now accepts OSGi metadata for 
Bundle-Name, Bundle-Version in place of Cytoscape-App-Name, 
Cytoscape-App-Version. Installed/uninstalled/disabled apps directories should 
be scanned on start for apps and displayed in manager since recent change to 
move install/uninstall to FileAlterationObservers.

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-07-25 17:53:10 UTC (rev 29986)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
 2012-07-25 20:53:06 UTC (rev 29987)
@@ -647,7 +647,7 @@
         */
        public void moveAppFile(AppManager appManager, File targetDirectory) 
throws IOException {
                File parentPath = this.getAppFile().getParentFile();
-               File installDirectoryPath = new 
File(appManager.getKarafDeployDirectory());
+               File installDirectoryPath = new 
File(appManager.getInstalledAppsPath());
                File disabledDirectoryPath = new 
File(appManager.getDisabledAppsPath());
                File uninstallDirectoryPath = new 
File(appManager.getUninstalledAppsPath());
 
@@ -675,9 +675,11 @@
                if (!targetDirectory.equals(parentPath)) {
                        if (moveDirectories.contains(parentPath)) {
                                FileUtils.moveFile(this.getAppFile(), 
targetFile);
+                               System.out.println("Moving: " + 
this.getAppFile() + " -> " + targetFile);
                                this.setAppFile(targetFile);
                        } else {
                                FileUtils.copyFile(this.getAppFile(), 
targetFile);
+                               System.out.println("Copying: " + 
this.getAppFile() + " -> " + targetFile);
                                this.setAppFile(targetFile);
                        }
                }

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-07-25 17:53:10 UTC (rev 29986)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
  2012-07-25 20:53:06 UTC (rev 29987)
@@ -141,6 +141,33 @@
 
                // Install previously enabled apps
                
+               Set<App> installedFolderApps = obtainAppsFromDirectory(new 
File(getInstalledAppsPath()), false);
+               for (App app: installedFolderApps) {
+                       try {
+                               app.install(this);
+                               apps.add(app);
+                       } catch (AppInstallException e) {
+                       }
+               }
+               
+               Set<App> disabledFolderApps = obtainAppsFromDirectory(new 
File(getDisabledAppsPath()), false);
+               for (App app: disabledFolderApps) {
+                       try {
+                               app.disable(this);
+                               apps.add(app);
+                       } catch (AppDisableException e) {
+                       }
+               }
+               
+               Set<App> uninstalledFolderApps = obtainAppsFromDirectory(new 
File(getUninstalledAppsPath()), false);
+               for (App app: uninstalledFolderApps) {
+                       try {
+                               app.uninstall(this);
+                               apps.add(app);
+                       } catch (AppUninstallException e) {
+                       }
+               }
+               
                //installAppsInDirectory(new File(getKarafDeployDirectory()), 
false);
                //installAppsInDirectory(new File(getInstalledAppsPath()), 
true);
                
@@ -721,6 +748,7 @@
                                        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);

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-07-25 17:53:10 UTC (rev 29986)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppParser.java
   2012-07-25 20:53:06 UTC (rev 29987)
@@ -56,7 +56,7 @@
         * @throws AppParsingException If there was an error during parsing, 
such as missing data from the manifest file
         */
        public App parseApp(File file) throws AppParsingException {
-               App parsedApp = new SimpleAppOld();
+               App parsedApp = new SimpleApp();
                
                DebugHelper.print("Parsing: " + file.getPath());
                
@@ -140,31 +140,48 @@
                }
                
                // Obtain the human-readable name of the app
-               String readableName = 
manifest.getMainAttributes().getValue(SimpleAppOld.APP_READABLE_NAME_TAG);
-               if (readableName == null || readableName.trim().length() == 0) {
+               String readableName = null;
+               if (!bundleApp) {
+                       readableName = 
manifest.getMainAttributes().getValue(SimpleAppOld.APP_READABLE_NAME_TAG);
                        
-                       if (bundleApp) {
-                               readableName = "Name-not-found: karaf/" + 
file.getName();
-                       } else {
+                       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.");
-                               // readableName = "unnamed";
                        }
+               } else {
+                       readableName = 
manifest.getMainAttributes().getValue("Bundle-Name");
+                       
+                       if (readableName == null || 
readableName.trim().length() == 0) {
+                               readableName = 
manifest.getMainAttributes().getValue("Bundle-SymbolicName");
+                       }
+                       
+                       if (readableName == null || 
readableName.trim().length() == 0) {
+                               throw new AppParsingException("Bundle jar 
manifest had no entry for Bundle-Name, and no entry for Bundle-SymbolicName");
+                       }
                }
                
                // 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(SimpleAppOld.APP_VERSION_TAG);
-               if (appVersion == null || appVersion.trim().length() == 0) {
+               String appVersion = null;
+               if (!bundleApp) {
+                       appVersion = 
manifest.getMainAttributes().getValue(SimpleAppOld.APP_VERSION_TAG);
                        
-                       if (bundleApp) {
-                               appVersion = "Not found";
-                       } else {
+                       if (appVersion == null || appVersion.trim().length() == 
0) {
                                throw new AppParsingException("Jar is missing 
value for entry " + SimpleAppOld.APP_VERSION_TAG + " in its manifiest file.");
-                               // appVersion = "unversioned";
+                       } 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
+                                               + " 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 {
+                       appVersion = 
manifest.getMainAttributes().getValue("Bundle-Version");
                        
-               } 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
-                                       + " 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");
+                       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);
+                               
+                               if (appVersion == null || 
appVersion.trim().length() == 0) {
+                                       throw new AppParsingException("Bundle 
jar manifest has no entry for Bundle-Version");
+                               }
+                       }
                }
                
                String compatibleVersions = 
manifest.getMainAttributes().getValue(SimpleAppOld.APP_COMPATIBLE_TAG);

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleApp.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleApp.java
   2012-07-25 17:53:10 UTC (rev 29986)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleApp.java
   2012-07-25 20:53:06 UTC (rev 29987)
@@ -131,12 +131,12 @@
 
        @Override
        public void uninstall(AppManager appManager) throws 
AppUninstallException {
-               this.setStatus(AppStatus.UNINSTALLED);
+               this.setStatus(AppStatus.TO_BE_UNINSTALLED);
        }
 
        @Override
        public void disable(AppManager appManager) throws AppDisableException {
-               this.setStatus(AppStatus.DISABLED);
+               this.setStatus(AppStatus.TO_BE_DISABLED);
        }
 
 }

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
      2012-07-25 17:53:10 UTC (rev 29986)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
      2012-07-25 20:53:06 UTC (rev 29987)
@@ -11,6 +11,7 @@
 
 import org.cytoscape.app.internal.event.AppsChangedEvent;
 import org.cytoscape.app.internal.event.AppsChangedListener;
+import org.cytoscape.app.internal.exception.AppDisableException;
 import org.cytoscape.app.internal.exception.AppInstallException;
 import org.cytoscape.app.internal.exception.AppUninstallException;
 import org.cytoscape.app.internal.manager.App;
@@ -130,11 +131,11 @@
                         
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                             .add(descriptionLabel)
                             .add(layout.createSequentialGroup()
-                                .add(uninstallSelectedButton)
+                               .add(enableSelectedButton)
                                 
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                 .add(disableSelectedButton)
                                 
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
-                                .add(enableSelectedButton))
+                                .add(uninstallSelectedButton))
                             .add(appsInstalledLabel))
                         .add(0, 0, Short.MAX_VALUE)))
                 .addContainerGap())
@@ -187,13 +188,13 @@
         for (App app : selectedApps) {
                if (app.getStatus().equals(AppStatus.DISABLED))
                 continue;
-            /*
-            try {
-            } catch (AppInstallException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            }
-            */
+
+               try {
+                       appManager.disableApp(app);
+               } catch (AppDisableException e) {
+                       // TODO Auto-generated catch block
+                               e.printStackTrace();
+               }
         }
         
         disableSelectedButton.setEnabled(false);
@@ -208,7 +209,8 @@
         
         for (App app : selectedApps) {
                // Only uninstall apps that are installed
-               if (app.getStatus() == AppStatus.INSTALLED) {
+               if (app.getStatus() == AppStatus.INSTALLED
+                               || app.getStatus() == AppStatus.DISABLED) {
                        try {
                                        appManager.uninstallApp(app);
                                } catch (AppUninstallException e) {
@@ -311,7 +313,7 @@
     private void updateLabels() {
        int installedCount = appManager.getApps().size();
        
-       appsInstalledLabel.setText(installedCount + " Apps installed.");
+       appsInstalledLabel.setText(installedCount + installedCount == 1 ? " App 
installed." : " Apps installed.");
     }
     
     /**
@@ -338,6 +340,7 @@
                
                // Disable buttons
                enableSelectedButton.setEnabled(false);
+               disableSelectedButton.setEnabled(false);
                uninstallSelectedButton.setEnabled(false);
                
        // If a single app is selected, show its app description
@@ -350,38 +353,57 @@
                // Enable/disable the appropriate button
                if (selectedApp.getStatus() == AppStatus.INSTALLED) {
                        enableSelectedButton.setEnabled(false);
+                       disableSelectedButton.setEnabled(true);
                        uninstallSelectedButton.setEnabled(true);
-               } else {
+               } else if (selectedApp.getStatus() == AppStatus.DISABLED) {
                        enableSelectedButton.setEnabled(true);
+                       disableSelectedButton.setEnabled(false);
+                       uninstallSelectedButton.setEnabled(true);
+               } else if (selectedApp.getStatus() == AppStatus.UNINSTALLED) {
+                       enableSelectedButton.setEnabled(true);
+                       disableSelectedButton.setEnabled(true);
                        uninstallSelectedButton.setEnabled(false);
-               }
+               } 
        } else {
                descriptionTextArea.setText(numSelected + " apps selected.");
                
                // Enable/disable the appropriate buttons
                boolean allInstalled = true;
+               boolean allDisabled = true;
                boolean allUninstalled = true;
                
                for (App selectedApp : selectedApps) {
                        if (selectedApp.getStatus() == AppStatus.INSTALLED) {
+                               allDisabled = false;
                                allUninstalled = false;
                        }
                        
-                       if (selectedApp.getStatus() != AppStatus.INSTALLED) {
+                       if (selectedApp.getStatus() == AppStatus.DISABLED) {
                                allInstalled = false;
+                               allUninstalled = false;
                        }
+                       
+                       if (selectedApp.getStatus() == AppStatus.UNINSTALLED) {
+                               allInstalled = false;
+                               allDisabled = false;
+                       }
                }
                
                if (allInstalled) {
                        enableSelectedButton.setEnabled(false);
+                       disableSelectedButton.setEnabled(true);
                        uninstallSelectedButton.setEnabled(true);
+               } else if (allDisabled) {
+                       enableSelectedButton.setEnabled(true);
+                       disableSelectedButton.setEnabled(false);
+                       uninstallSelectedButton.setEnabled(true);
                } else if (allUninstalled) {
                        enableSelectedButton.setEnabled(true);
+                       disableSelectedButton.setEnabled(true);
                        uninstallSelectedButton.setEnabled(false);
                } else {
-                       // If some of the selected apps are installed and some 
are uninstalled,
-                       // enable both buttons
                        enableSelectedButton.setEnabled(true);
+                       disableSelectedButton.setEnabled(true);
                        uninstallSelectedButton.setEnabled(true);
                }
        }

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