]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/Clone.java
1. Fix bug for wrong Variable name in msa file
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / Clone.java
index 9253793ca966d137311af29b506413fff59a26a9..3d8c267484e5290e81ae4ec9726be05e1c4076c8 100644 (file)
@@ -51,14 +51,21 @@ import org.tianocore.frameworkwizard.workspace.Workspace;
 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r
 import javax.swing.JComboBox;\r
 \r
+/**\r
+ The class is used to provide functions to clone workspace, module, package and platform\r
+ It extends IDialog\r
+\r
+ **/\r
 public class Clone extends IDialog {\r
 \r
-    /**\r
-     Define class members\r
-     \r
-     **/\r
+    ///\r
+    /// Define Class Serial Version UID\r
+    ///\r
     private static final long serialVersionUID = -5469299324965727137L;\r
 \r
+    ///\r
+    /// Define Class Members\r
+    ///\r
     private JPanel jContentPane = null;\r
 \r
     private JLabel jLabelType = null;\r
@@ -93,16 +100,20 @@ public class Clone extends IDialog {
 \r
     private JButton jButtonGenerateGuid = null;\r
 \r
+    private JLabel jLabelBelong = null;\r
+\r
+    private JComboBox jComboBoxExistingPackage = null;\r
+\r
+    ///\r
+    /// Define members not for UI\r
+    ///\r
+\r
     private int mode = -1;\r
 \r
     private Vector<PackageIdentification> packages = null;\r
 \r
     private WorkspaceTools wt = new WorkspaceTools();\r
 \r
-    private JLabel jLabelBelong = null;\r
-\r
-    private JComboBox jComboBoxExistingPackage = null;\r
-\r
     private Identification oldId = null;\r
 \r
     private Identification newId = null;\r
@@ -114,10 +125,11 @@ public class Clone extends IDialog {
     private PlatformIdentification fid = null;\r
 \r
     /**\r
-     * This method initializes jTextFieldType  \r
-     *         \r
-     * @return javax.swing.JTextField  \r
-     */\r
+     This method initializes jTextFieldType    \r
+     \r
+     @return javax.swing.JTextField\r
+     \r
+     **/\r
     private JTextField getJTextFieldType() {\r
         if (jTextFieldType == null) {\r
             jTextFieldType = new JTextField();\r
@@ -128,10 +140,11 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes jTextFieldSource        \r
-     *         \r
-     * @return javax.swing.JTextField  \r
-     */\r
+     This method initializes jTextFieldSource  \r
+     \r
+     @return javax.swing.JTextField    \r
+     \r
+     **/\r
     private JTextField getJTextFieldSource() {\r
         if (jTextFieldSource == null) {\r
             jTextFieldSource = new JTextField();\r
@@ -142,10 +155,11 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes jButtonBrowse   \r
-     *         \r
-     * @return javax.swing.JButton     \r
-     */\r
+     This method initializes jButtonBrowse     \r
+     \r
+     @return javax.swing.JButton       \r
+     \r
+     **/\r
     private JButton getJButtonBrowse() {\r
         if (jButtonBrowse == null) {\r
             jButtonBrowse = new JButton();\r
@@ -157,10 +171,11 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes jTextFieldDestinationFile       \r
-     *         \r
-     * @return javax.swing.JTextField  \r
-     */\r
+     This method initializes jTextFieldDestinationFile \r
+     \r
+     @return javax.swing.JTextField    \r
+     \r
+     **/\r
     private JTextField getJTextFieldFilePath() {\r
         if (jTextFieldFilePath == null) {\r
             jTextFieldFilePath = new JTextField();\r
@@ -170,10 +185,11 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes jTextFieldBaseName      \r
-     *         \r
-     * @return javax.swing.JTextField  \r
-     */\r
+     This method initializes jTextFieldBaseName        \r
+     \r
+     @return javax.swing.JTextField    \r
+     \r
+     **/\r
     private JTextField getJTextFieldBaseName() {\r
         if (jTextFieldBaseName == null) {\r
             jTextFieldBaseName = new JTextField();\r
@@ -183,10 +199,11 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes jTextFieldGuid  \r
-     *         \r
-     * @return javax.swing.JTextField  \r
-     */\r
+     This method initializes jTextFieldGuid    \r
+     \r
+     @return javax.swing.JTextField    \r
+     \r
+     **/\r
     private JTextField getJTextFieldGuid() {\r
         if (jTextFieldGuid == null) {\r
             jTextFieldGuid = new JTextField();\r
@@ -196,10 +213,11 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes jTextFieldVersion       \r
-     *         \r
-     * @return javax.swing.JTextField  \r
-     */\r
+     This method initializes jTextFieldVersion \r
+     \r
+     @return javax.swing.JTextField    \r
+     \r
+     **/\r
     private JTextField getJTextFieldVersion() {\r
         if (jTextFieldVersion == null) {\r
             jTextFieldVersion = new JTextField();\r
@@ -209,10 +227,11 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes jButtonOk       \r
-     *         \r
-     * @return javax.swing.JButton     \r
-     */\r
+     This method initializes jButtonOk \r
+     \r
+     @return javax.swing.JButton       \r
+     \r
+     **/\r
     private JButton getJButtonOk() {\r
         if (jButtonOk == null) {\r
             jButtonOk = new JButton();\r
@@ -224,10 +243,11 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes jButtonCancel   \r
-     *         \r
-     * @return javax.swing.JButton     \r
-     */\r
+     This method initializes jButtonCancel     \r
+     \r
+     @return javax.swing.JButton       \r
+     \r
+     **/\r
     private JButton getJButtonCancel() {\r
         if (jButtonCancel == null) {\r
             jButtonCancel = new JButton();\r
@@ -239,10 +259,11 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes jButtonGenerateGuid     \r
-     *         \r
-     * @return javax.swing.JButton     \r
-     */\r
+     This method initializes jButtonGenerateGuid       \r
+     \r
+     @return javax.swing.JButton       \r
+     \r
+     **/\r
     private JButton getJButtonGenerateGuid() {\r
         if (jButtonGenerateGuid == null) {\r
             jButtonGenerateGuid = new JButton();\r
@@ -254,10 +275,11 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes jComboBoxExistingPackage        \r
-     *         \r
-     * @return javax.swing.JComboBox   \r
-     */\r
+     This method initializes jComboBoxExistingPackage  \r
+     \r
+     @return javax.swing.JComboBox     \r
+     \r
+     **/\r
     private JComboBox getJComboBoxExistingPackage() {\r
         if (jComboBoxExistingPackage == null) {\r
             jComboBoxExistingPackage = new JComboBox();\r
@@ -267,24 +289,21 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     \r
-     @param args\r
+     This is the default constructor\r
      \r
      **/\r
-    public static void main(String[] args) {\r
-\r
-    }\r
-\r
-    /**\r
-     * This is the default constructor\r
-     */\r
     public Clone() {\r
         super();\r
         init();\r
     }\r
 \r
     /**\r
-     This is the default constructor\r
+     This is the override constructor\r
+     \r
+     @param parentFrame       The parent frame which starts this frame\r
+     @param modal             To identify the frame's modal\r
+     @param fileType          To identify the clone target type\r
+     @param identification    The clone target's identification\r
      \r
      **/\r
     public Clone(IFrame parentFrame, boolean modal, int fileType, Identification identification) {\r
@@ -311,10 +330,9 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes this\r
-     * \r
-     * @return void\r
-     */\r
+     This method initializes this\r
+     \r
+     **/\r
     private void init() {\r
         this.setSize(550, 260);\r
         this.setContentPane(getJContentPane());\r
@@ -323,12 +341,17 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes this\r
-     * \r
-     * @return void\r
-     */\r
+     This method initializes this with given clone target type.\r
+     Customize the frame interface via different clone target type.\r
+     \r
+     @param mode To identify the clone target type\r
+     \r
+     **/\r
     private void init(int mode) {\r
         init();\r
+        //\r
+        // For MODULE_SURFACE_AREA\r
+        //\r
         if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r
             this.jTextFieldType.setText(DataType.MODULE_SURFACE_AREA);\r
             String s = oldId.getPath();\r
@@ -341,6 +364,9 @@ public class Clone extends IDialog {
             this.jTextFieldFilePath.setSize(320, this.jTextFieldFilePath.getSize().height);\r
             this.jLabelDestinationFile.setText("New Module Path and Filename");\r
         }\r
+        //\r
+        // For PACKAGE_SURFACE_AREA\r
+        //\r
         if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r
             this.jTextFieldType.setText(DataType.PACKAGE_SURFACE_AREA);\r
             String s = oldId.getPath();\r
@@ -353,6 +379,9 @@ public class Clone extends IDialog {
             this.jTextFieldFilePath.setSize(320, this.jTextFieldFilePath.getSize().height);\r
             this.jLabelDestinationFile.setText("New Package Path and Filename");\r
         }\r
+        //\r
+        // For PLATFORM_SURFACE_AREA\r
+        //\r
         if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r
             this.jTextFieldType.setText(DataType.PLATFORM_SURFACE_AREA);\r
             this.jTextFieldSource.setText(oldId.getPath());\r
@@ -362,6 +391,9 @@ public class Clone extends IDialog {
                                    .setToolTipText("Select platform path here. For example, C:\\MyWorkspace\\EdkNt32Pkg\\Nt32.fpd");\r
             this.jLabelDestinationFile.setText("New Platform Path and Filename");\r
         }\r
+        //\r
+        // For WORKSPACE\r
+        //\r
         if (mode == DataType.RETURN_TYPE_WORKSPACE) {\r
             this.jTextFieldType.setText(DataType.WORKSPACE);\r
             this.jTextFieldSource.setText(Workspace.getCurrentWorkspace());\r
@@ -380,10 +412,11 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     * This method initializes jContentPane\r
-     * \r
-     * @return javax.swing.JPanel\r
-     */\r
+     This method initializes jContentPane\r
+     \r
+     @return javax.swing.JPanel\r
+     \r
+     **/\r
     private JPanel getJContentPane() {\r
         if (jContentPane == null) {\r
             jLabelBelong = new JLabel();\r
@@ -446,6 +479,9 @@ public class Clone extends IDialog {
         if (arg0.getSource() == jButtonOk) {\r
             if (this.check()) {\r
                 try {\r
+                    //\r
+                    // Save to file\r
+                    //\r
                     this.save();\r
                 } catch (IOException e) {\r
                     Log.wrn("Clone", e.getMessage());\r
@@ -471,7 +507,7 @@ public class Clone extends IDialog {
         }\r
 \r
         //\r
-        // Use different file ext\r
+        // Use different file ext for different clone target type\r
         //\r
         if (arg0.getSource() == this.jButtonBrowse) {\r
             JFileChooser fc = new JFileChooser();\r
@@ -501,9 +537,14 @@ public class Clone extends IDialog {
         }\r
     }\r
 \r
-    //\r
-    // Check name, guid and version\r
-    //\r
+    /**\r
+     Check name, guid and version.\r
+     If all of them are valid, save information to new id\r
+     \r
+     @retval true   All name, guid and version are valid\r
+     @retval false  Any one of name, guid and version is invalid\r
+     \r
+     **/\r
     private boolean checkId() {\r
         //\r
         // Check Basename\r
@@ -555,7 +596,8 @@ public class Clone extends IDialog {
     /**\r
      Check before save\r
      \r
-     @return\r
+     @retval true   All check points are passed\r
+     @retval false  Any one of check points is failed\r
      \r
      **/\r
     private boolean check() {\r
@@ -598,10 +640,6 @@ public class Clone extends IDialog {
         // Check for Module\r
         //\r
         if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r
-            //            if (trg.indexOf(DataType.DOS_FILE_SEPARATOR) == -1 && trg.indexOf(DataType.UNIX_FILE_SEPARATOR) == -1) {\r
-            //                Log.err("The module name must include a path");\r
-            //                return false;\r
-            //            }\r
             trg = this.getModulePath();\r
             if (src.equals(trg)) {\r
                 Log.wrn("Clone", "The source and destination couldn't be same");\r
@@ -655,6 +693,14 @@ public class Clone extends IDialog {
         return true;\r
     }\r
 \r
+    /**\r
+     Save clone target to new location\r
+     \r
+     @throws IOException\r
+     @throws XmlException\r
+     @throws Exception\r
+     \r
+     **/\r
     private void save() throws IOException, XmlException, Exception {\r
         String src = this.oldId.getPath();\r
         String trg = this.jTextFieldFilePath.getText();\r
@@ -703,7 +749,7 @@ public class Clone extends IDialog {
             msa.getMsaHeader().setVersion(newId.getVersion());\r
 \r
             //\r
-            // Update Cloned From element\r
+            // Update <Cloned> Section\r
             //\r
             updateModuleClonedId(msa, oldId);\r
 \r
@@ -743,6 +789,9 @@ public class Clone extends IDialog {
             newId.setPath(trg);\r
             vFiles = wt.getAllPakcageFilesPath(src);\r
 \r
+            //\r
+            // First copy all files to new directory\r
+            //\r
             FileOperation.copyFile(src, trg);\r
             for (int index = 1; index < vFiles.size(); index++) {\r
                 String oldFile = vFiles.get(index);\r
@@ -750,16 +799,6 @@ public class Clone extends IDialog {
                 FileOperation.copyFile(oldFile, newFile);\r
             }\r
 \r
-            //\r
-            // First copy all files to new directory\r
-            //\r
-            //FileOperation.copyFolder(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));\r
-\r
-            //\r
-            // Delete old spd file\r
-            //\r
-            //FileOperation.delFile(Tools.getFilePathOnly(trg) + DataType.FILE_SEPARATOR + Tools.getFileNameOnly(src));\r
-\r
             //\r
             // Create new spd file\r
             //\r
@@ -774,7 +813,7 @@ public class Clone extends IDialog {
             spd.getSpdHeader().setVersion(newId.getVersion());\r
 \r
             //\r
-            // Update Cloned From element\r
+            // Update <Cloned> Section\r
             //\r
             updatePackageClonedId(spd, oldId);\r
 \r
@@ -835,10 +874,23 @@ public class Clone extends IDialog {
         vFiles = null;\r
     }\r
 \r
+    /**\r
+     Get the path of selected package\r
+     \r
+     @return String The path of selected package\r
+     \r
+     **/\r
     private String getSelectPackagePath() {\r
         return Tools.getFilePathOnly(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getPath());\r
     }\r
 \r
+    /**\r
+     Get the path of source module\r
+     Since the path of source module is relative, make it up to full path.\r
+     \r
+     @return String The full path of source module\r
+     \r
+     **/\r
     private String getModulePath() {\r
         String trg = this.jTextFieldFilePath.getText();\r
         trg = Tools.addPathExt(trg, mode);\r
@@ -847,6 +899,13 @@ public class Clone extends IDialog {
         return trg;\r
     }\r
 \r
+    /**\r
+     Get the path of source package\r
+     Since the path of source package is relative, make it up to full path.\r
+     \r
+     @return String The full path of source package\r
+     \r
+     **/\r
     private String getPackagePath() {\r
         String trg = this.jTextFieldFilePath.getText();\r
         trg = Tools.addPathExt(trg, mode);\r
@@ -856,11 +915,11 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     Set target item's Cloned From element\r
-\r
-     @param id\r
-     @return\r
-\r
+     Set msa file's <Cloned> section via given identification\r
+     \r
+     @param msa ModuleSurfaceArea for clone target\r
+     @param id Identification of clone source\r
+     \r
      **/\r
     private void updateModuleClonedId(ModuleSurfaceArea msa, Identification id) {\r
         //\r
@@ -914,10 +973,10 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     Set target item's Cloned From element\r
+     Set spd file's <Cloned> section via given identification\r
      \r
-     @param id\r
-     @return\r
+     @param spd PackageSurfaceArea for clone target\r
+     @param id Identification of clone source\r
      \r
      **/\r
     private void updatePackageClonedId(PackageSurfaceArea spd, Identification id) {\r
@@ -970,10 +1029,10 @@ public class Clone extends IDialog {
     }\r
 \r
     /**\r
-     Set target item's Cloned From element\r
+     Set fpd file's <Cloned> section via given identification\r
      \r
-     @param id\r
-     @return\r
+     @param fpd PlatformSurfaceArea for clone target\r
+     @param id Identification of clone source\r
      \r
      **/\r
     private void updatePlatformClonedId(PlatformSurfaceArea fpd, Identification id) {\r
@@ -1025,26 +1084,62 @@ public class Clone extends IDialog {
         fpd.setPlatformDefinitions(pd);\r
     }\r
 \r
+    /**\r
+     Get PlatformIdentification\r
+     \r
+     @return PlatformIdentification\r
+     \r
+     **/\r
     public PlatformIdentification getFid() {\r
         return fid;\r
     }\r
 \r
+    /**\r
+     Set PlatformIdentification\r
+     \r
+     @param fid PlatformIdentification\r
+     \r
+     **/\r
     public void setFid(PlatformIdentification fid) {\r
         this.fid = fid;\r
     }\r
 \r
+    /**\r
+     Get ModuleIdentification\r
+     \r
+     @return ModuleIdentification\r
+     \r
+     **/\r
     public ModuleIdentification getMid() {\r
         return mid;\r
     }\r
 \r
+    /**\r
+     Set ModuleIdentification\r
+     \r
+     @param mid ModuleIdentification\r
+     \r
+     **/\r
     public void setMid(ModuleIdentification mid) {\r
         this.mid = mid;\r
     }\r
 \r
+    /**\r
+     Get PackageIdentification\r
+     \r
+     @return PackageIdentification\r
+     \r
+     **/\r
     public PackageIdentification getPid() {\r
         return pid;\r
     }\r
 \r
+    /**\r
+     Set PackageIdentification\r
+     \r
+     @param pid PackageIdentification\r
+     \r
+     **/\r
     public void setPid(PackageIdentification pid) {\r
         this.pid = pid;\r
     }\r