changeset 143:5c3c720c875e

Move duplicate project code into shared class
author Omair Majid <omajid@redhat.com>
date Thu, 05 Jun 2014 17:50:39 -0400
parents de9b5bf2278e
children 140f53e68755
files com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/Messages.java com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/ProjectUtils.java com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/messages.properties com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/wizards/ExportPluginPage.java com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/wizards/PluginXmlProjectSelectionPage.java
diffstat 5 files changed, 43 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/Messages.java	Thu Jun 05 17:33:09 2014 -0400
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/Messages.java	Thu Jun 05 17:50:39 2014 -0400
@@ -72,9 +72,7 @@
     public static String PluginXmlProjectSelectionPage_selectFileContainer;
     public static String PluginXmlProjectSelectionPage_browse;
     public static String PluginXmlProjectSelectionPage_description;
-    public static String PluginXmlProjectSelectionPage_fileContainerMustBeSpecified;
     public static String PluginXmlProjectSelectionPage_fileContainerMustExist;
-    public static String PluginXmlProjectSelectionPage_projectMustBeWritable;
     public static String PluginXmlProjectSelectionPage_projectNameLabel;
     public static String PluginXmlProjectSelectionPage_title;
     public static String ThermostatProjectCreationWizard_dialogTitle;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/ProjectUtils.java	Thu Jun 05 17:50:39 2014 -0400
@@ -0,0 +1,35 @@
+package com.redhat.thermostat.tools.eclipse.plugin;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
+
+public class ProjectUtils {
+
+    private static IWorkspaceRoot root;
+
+    static {
+        root = ResourcesPlugin.getWorkspace().getRoot();
+    }
+
+    /** Return true if {@code name} corresponds to a valid project */
+    public static boolean isValid(String name) {
+        if (name.length() == 0) {
+            return false;
+        }
+
+        IResource container = root.findMember(new Path(name));
+
+        if (container == null
+                || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
+            return false;
+        }
+
+        if (!container.isAccessible()) {
+            return false;
+        }
+
+        return true;
+    }
+}
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/messages.properties	Thu Jun 05 17:33:09 2014 -0400
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/messages.properties	Thu Jun 05 17:50:39 2014 -0400
@@ -64,9 +64,7 @@
 PluginXmlProjectSelectionPage_selectFileContainer=Select new file container
 PluginXmlProjectSelectionPage_browse=Browse...
 PluginXmlProjectSelectionPage_description=This wizard creates a new Thermostat Plugin.
-PluginXmlProjectSelectionPage_fileContainerMustBeSpecified=File container must be specified
 PluginXmlProjectSelectionPage_fileContainerMustExist=File container must exist
-PluginXmlProjectSelectionPage_projectMustBeWritable=Project must be writable
 PluginXmlProjectSelectionPage_projectNameLabel=&Project:
 PluginXmlProjectSelectionPage_title=Thermostat Wizard
 ThermostatProjectCreationWizard_dialogTitle=Create New Thermostat Plugin
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/wizards/ExportPluginPage.java	Thu Jun 05 17:33:09 2014 -0400
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/wizards/ExportPluginPage.java	Thu Jun 05 17:50:39 2014 -0400
@@ -28,6 +28,7 @@
 import com.redhat.thermostat.tools.eclipse.plugin.ProjectFinder;
 import com.redhat.thermostat.tools.eclipse.plugin.ProjectFinder.Criteria;
 import com.redhat.thermostat.tools.eclipse.plugin.ProjectPreferences;
+import com.redhat.thermostat.tools.eclipse.plugin.ProjectUtils;
 import com.redhat.thermostat.tools.eclipse.plugin.SelectionUtils;
 
 public class ExportPluginPage extends WizardPage {
@@ -120,30 +121,13 @@
 
     /** Side-effect: Update error status message */
     private boolean isProjectValid() {
-        String containerName = getProjectName();
+        boolean result = ProjectUtils.isValid(getProjectName());
 
-        if (containerName.length() == 0) {
-            setErrorMessage("Project name must be specified");
-            return false;
+        if (!result) {
+            setErrorMessage("Must select a valid project");
         }
 
-        IResource container = ResourcesPlugin
-                .getWorkspace()
-                .getRoot()
-                .findMember(new Path(containerName));
-
-        if (container == null
-                || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
-            setErrorMessage("Project must exist");
-            return false;
-        }
-        if (!container.isAccessible()) {
-            setErrorMessage("Project must be readable");
-            return false;
-        }
-
-        return true;
-
+        return result;
     }
 
     /** Side-effect: Update error status message */
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/wizards/PluginXmlProjectSelectionPage.java	Thu Jun 05 17:33:09 2014 -0400
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/wizards/PluginXmlProjectSelectionPage.java	Thu Jun 05 17:50:39 2014 -0400
@@ -26,6 +26,7 @@
 
 import com.redhat.thermostat.tools.eclipse.plugin.Messages;
 import com.redhat.thermostat.tools.eclipse.plugin.ProjectFinder;
+import com.redhat.thermostat.tools.eclipse.plugin.ProjectUtils;
 import com.redhat.thermostat.tools.eclipse.plugin.ProjectFinder.Criteria;
 import com.redhat.thermostat.tools.eclipse.plugin.SelectionUtils;
 
@@ -103,23 +104,11 @@
     private void dialogChanged() {
         String containerName = getContainerName();
 
-        if (containerName.length() == 0) {
-            updateStatus(Messages.PluginXmlProjectSelectionPage_fileContainerMustBeSpecified);
+        if (!ProjectUtils.isValid(containerName)) {
+            updateStatus(Messages.PluginXmlProjectSelectionPage_fileContainerMustExist);
             return;
         }
 
-        IResource container = ResourcesPlugin.getWorkspace().getRoot()
-                .findMember(new Path(containerName));
-
-        if (container == null
-                || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
-            updateStatus(Messages.PluginXmlProjectSelectionPage_fileContainerMustExist);
-            return;
-        }
-        if (!container.isAccessible()) {
-            updateStatus(Messages.PluginXmlProjectSelectionPage_projectMustBeWritable);
-            return;
-        }
         updateStatus(null);
     }