1. Fix EDKT306 Output different error message for different condition in workspace...
authorhche10x <hche10x@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 26 Sep 2006 09:05:56 +0000 (09:05 +0000)
committerhche10x <hche10x@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 26 Sep 2006 09:05:56 +0000 (09:05 +0000)
2. Fix EDKT307 Workspace selection support is required by wizard

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1629 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/FrameworkWizardUI.java
Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/workspace/Workspace.java
Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/workspace/ui/SwitchWorkspace.java

index 5efa81b..ad08749 100644 (file)
@@ -1807,25 +1807,19 @@ public class FrameworkWizardUI extends IFrame implements KeyListener, MouseListe
      \r
      **/\r
     private void init() {\r
-        //\r
-        // Show splash screen\r
-        //\r
-        SplashScreen ss = new SplashScreen();\r
-        ss.setVisible(true);\r
-\r
         //\r
         // Set current workspace and check\r
         // Check if exists WORKSPACE\r
-        // \r
         //\r
         Workspace.setCurrentWorkspace(System.getenv("WORKSPACE"));\r
-        if (!Workspace.checkCurrentWorkspace()) {\r
-            JOptionPane.showConfirmDialog(null, "Workspace is not setup correctly. Please setup first.", "Warning",\r
-                                          JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);\r
-            this.dispose();\r
-            System.exit(0);\r
-        }\r
+        this.checkWorkspace();\r
 \r
+        //\r
+        // Show splash screen\r
+        //\r
+        SplashScreen ss = new SplashScreen();\r
+        ss.setVisible(true);\r
+        \r
         //\r
         // Init Global Data\r
         //\r
@@ -3675,4 +3669,48 @@ public class FrameworkWizardUI extends IFrame implements KeyListener, MouseListe
                                           JOptionPane.INFORMATION_MESSAGE);\r
         }\r
     }\r
+\r
+    /**\r
+     Check if WORKSPACE Environment is valid\r
+     \r
+     **/\r
+    private void checkWorkspace() {\r
+        switch (Workspace.checkCurrentWorkspace()) {\r
+        case Workspace.WORKSPACE_VALID:\r
+            break;\r
+        case Workspace.WORKSPACE_NOT_DEFINED:\r
+            JOptionPane\r
+                       .showConfirmDialog(\r
+                                          null,\r
+                                          "WORKSPACE Environment Variable Is Not Defined, Please select a valid WORKSPACE directory. " +\r
+                                          DataType.LINE_SEPARATOR + DataType.LINE_SEPARATOR + "NOTICE:" +\r
+                                          DataType.LINE_SEPARATOR + "This does not change the System Environment Variable." +\r
+                                          DataType.LINE_SEPARATOR + "It only applies to where the Wizard will manage modification and file creations.",\r
+                                          "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);\r
+            SwitchWorkspace sw = new SwitchWorkspace(this, true);\r
+            int result = sw.showDialog();\r
+            if (result == DataType.RETURN_TYPE_CANCEL) {\r
+                this.dispose();\r
+                System.exit(0);\r
+            } else if (result == DataType.RETURN_TYPE_OK) {\r
+                sw.dispose();\r
+                break;\r
+            }\r
+        case Workspace.WORKSPACE_NOT_EXIST:\r
+            JOptionPane.showConfirmDialog(null, "Defined WORKSPACE Is Not Existed", "Error",\r
+                                          JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);\r
+            this.dispose();\r
+            System.exit(0);\r
+        case Workspace.WORKSPACE_NOT_DIRECTORY:\r
+            JOptionPane.showConfirmDialog(null, "Defined WORKSPACE Is Not A Directory", "Error",\r
+                                          JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);\r
+            this.dispose();\r
+            System.exit(0);\r
+        case Workspace.WORKSPACE_NOT_VALID:\r
+            JOptionPane.showConfirmDialog(null, "WORKSPACE Environment Variable Is Not Valid", "Error",\r
+                                          JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);\r
+            this.dispose();\r
+            System.exit(0);\r
+        }\r
+    }\r
 }\r
index 40692c6..5785aaf 100644 (file)
@@ -20,6 +20,19 @@ import java.io.File;
 import org.tianocore.frameworkwizard.common.DataType;\r
 \r
 public class Workspace {\r
+    //\r
+    // Define static return value\r
+    //\r
+    public final static int WORKSPACE_VALID = 0;\r
+    \r
+    public final static int WORKSPACE_NOT_DEFINED = 1;\r
+    \r
+    public final static int WORKSPACE_NOT_EXIST = 2;\r
+    \r
+    public final static int WORKSPACE_NOT_DIRECTORY = 3;\r
+    \r
+    public final static int WORKSPACE_NOT_VALID = 4;\r
+    \r
     //\r
     // Define class members\r
     //\r
@@ -66,7 +79,7 @@ public class Workspace {
      @retval false - The current WORKSPACE doesn't exist\r
      \r
      */\r
-    public static boolean checkCurrentWorkspace() {\r
+    public static int checkCurrentWorkspace() {\r
         return checkWorkspace(getCurrentWorkspace());\r
     }\r
 \r
@@ -79,30 +92,38 @@ public class Workspace {
      @retval false - The current WORKSPACE doesn't exist\r
      \r
      */\r
-    public static boolean checkWorkspace(String strWorkspace) {\r
+    public static int checkWorkspace(String strWorkspace) {\r
+        //\r
+        // Check if WORKSPACE Environment is defined\r
+        //\r
         if (strWorkspace == null || strWorkspace == "") {\r
-            return false;\r
+            return Workspace.WORKSPACE_NOT_DEFINED;\r
         }\r
+        \r
         //\r
-        // Check workspace directory\r
+        // Check if WORKSPACE Environment exists\r
         //\r
         File f = new File(strWorkspace);\r
-        if (!f.isDirectory()) {\r
-            return false;\r
-        }\r
         if (!f.exists()) {\r
-            return false;\r
+            return Workspace.WORKSPACE_NOT_EXIST;\r
+        }\r
+        \r
+        //\r
+        // Check if WORKSPACE Environment is a directory\r
+        //\r
+        if (!f.isDirectory()) {\r
+            return Workspace.WORKSPACE_NOT_DIRECTORY;\r
         }\r
         \r
         //\r
-        // Check FrameworkDatabase.db\r
+        // Check if FrameworkDatabase.db exists\r
         //\r
         f = new File(strWorkspace + Workspace.getStrWorkspaceDatabaseFile());\r
         if (!f.exists()) {\r
-            return false;\r
+            return Workspace.WORKSPACE_NOT_VALID;\r
         }\r
         \r
-        return true;\r
+        return Workspace.WORKSPACE_VALID;\r
     }\r
 \r
     public static String getStrWorkspaceDatabaseFile() {\r
index f81bfce..e5f28c5 100644 (file)
@@ -2,11 +2,11 @@ package org.tianocore.frameworkwizard.workspace.ui;
 \r
 import java.awt.event.ActionEvent;\r
 \r
+import javax.swing.JButton;\r
 import javax.swing.JFileChooser;\r
-import javax.swing.JPanel;\r
 import javax.swing.JLabel;\r
+import javax.swing.JPanel;\r
 import javax.swing.JTextField;\r
-import javax.swing.JButton;\r
 \r
 import org.tianocore.frameworkwizard.common.DataType;\r
 import org.tianocore.frameworkwizard.common.Log;\r
@@ -51,7 +51,8 @@ public class SwitchWorkspace extends IDialog {
             jTextFieldOld = new JTextField();\r
             jTextFieldOld.setBounds(new java.awt.Rectangle(140, 10, 320, 20));\r
             jTextFieldOld.setEditable(false);\r
-            jTextFieldOld.setText(Workspace.getCurrentWorkspace());\r
+            jTextFieldOld.setText(Workspace.getCurrentWorkspace() == null ? "Not Defined"\r
+                                                                         : Workspace.getCurrentWorkspace());\r
         }\r
         return jTextFieldOld;\r
     }\r
@@ -114,16 +115,6 @@ public class SwitchWorkspace extends IDialog {
         return jButtonBrowse;\r
     }\r
 \r
-    /**\r
-     \r
-     @param args\r
-     \r
-     **/\r
-    public static void main(String[] args) {\r
-        // TODO Auto-generated method stub\r
-\r
-    }\r
-\r
     /**\r
      * This is the default constructor\r
      * \r
@@ -150,7 +141,7 @@ public class SwitchWorkspace extends IDialog {
     private void initialize() {\r
         this.setSize(472, 132);\r
         this.setContentPane(getJContentPane());\r
-        this.setTitle("Change workspace");\r
+        this.setTitle("Select workspace");\r
         this.centerWindow();\r
     }\r
 \r
@@ -185,7 +176,7 @@ public class SwitchWorkspace extends IDialog {
             Log.wrn("Switch Workspace", "New workspace must be entered!");\r
             return false;\r
         }\r
-        if (!Workspace.checkWorkspace(this.jTextFieldNew.getText())) {\r
+        if (Workspace.checkWorkspace(this.jTextFieldNew.getText()) != Workspace.WORKSPACE_VALID) {\r
             Log.wrn("Switch Workspace", "Please select a valid workspace!");\r
             return false;\r
         }\r
@@ -207,9 +198,9 @@ public class SwitchWorkspace extends IDialog {
             if (!check()) {\r
                 return;\r
             } else {\r
-                this.setVisible(false);\r
                 Workspace.setCurrentWorkspace(this.jTextFieldNew.getText());\r
                 returnType = DataType.RETURN_TYPE_OK;\r
+                this.setVisible(false);\r
             }\r
         }\r
 \r