]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/Clone.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / Clone.java
diff --git a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/Clone.java b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/Clone.java
new file mode 100644 (file)
index 0000000..baf0379
--- /dev/null
@@ -0,0 +1,981 @@
+/** @file\r
\r
+ The file is used to clone workspace, module, package and platform\r
\r
+ Copyright (c) 2006, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
+ **/\r
+package org.tianocore.frameworkwizard;\r
+\r
+import java.awt.event.ActionEvent;\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.Vector;\r
+\r
+import javax.swing.JFileChooser;\r
+import javax.swing.JPanel;\r
+import javax.swing.JLabel;\r
+import javax.swing.JTextField;\r
+import javax.swing.JButton;\r
+\r
+import org.apache.xmlbeans.XmlException;\r
+import org.tianocore.ModuleDefinitionsDocument.ModuleDefinitions;\r
+import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
+import org.tianocore.PackageDefinitionsDocument.PackageDefinitions;\r
+import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r
+import org.tianocore.PlatformDefinitionsDocument.PlatformDefinitions;\r
+import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;\r
+import org.tianocore.frameworkwizard.common.DataType;\r
+import org.tianocore.frameworkwizard.common.DataValidation;\r
+import org.tianocore.frameworkwizard.common.FileOperation;\r
+import org.tianocore.frameworkwizard.common.IFileFilter;\r
+import org.tianocore.frameworkwizard.common.Identification;\r
+import org.tianocore.frameworkwizard.common.Log;\r
+import org.tianocore.frameworkwizard.common.OpenFile;\r
+import org.tianocore.frameworkwizard.common.SaveFile;\r
+import org.tianocore.frameworkwizard.common.Tools;\r
+import org.tianocore.frameworkwizard.common.ui.IDialog;\r
+import org.tianocore.frameworkwizard.common.ui.IFrame;\r
+import org.tianocore.frameworkwizard.module.Identification.ModuleIdentification;\r
+import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r
+import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r
+import org.tianocore.frameworkwizard.workspace.Workspace;\r
+import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r
+import javax.swing.JComboBox;\r
+\r
+public class Clone extends IDialog {\r
+\r
+    /**\r
+     Define class members\r
+     \r
+     **/\r
+    private static final long serialVersionUID = -5469299324965727137L;\r
+\r
+    private JPanel jContentPane = null;\r
+\r
+    private JLabel jLabelType = null;\r
+\r
+    private JTextField jTextFieldType = null;\r
+\r
+    private JLabel jLabelSource = null;\r
+\r
+    private JTextField jTextFieldSource = null;\r
+\r
+    private JButton jButtonBrowse = null;\r
+\r
+    private JLabel jLabelDestinationFile = null;\r
+\r
+    private JTextField jTextFieldFilePath = null;\r
+\r
+    private JLabel jLabelBaseName = null;\r
+\r
+    private JTextField jTextFieldBaseName = null;\r
+\r
+    private JLabel jLabelGuid = null;\r
+\r
+    private JTextField jTextFieldGuid = null;\r
+\r
+    private JLabel jLabelVersion = null;\r
+\r
+    private JTextField jTextFieldVersion = null;\r
+\r
+    private JButton jButtonOk = null;\r
+\r
+    private JButton jButtonCancel = null;\r
+\r
+    private JButton jButtonGenerateGuid = null;\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
+\r
+    private ModuleIdentification mid = null;\r
+\r
+    private PackageIdentification pid = null;\r
+\r
+    private PlatformIdentification fid = null;\r
+\r
+    /**\r
+     * This method initializes jTextFieldType  \r
+     *         \r
+     * @return javax.swing.JTextField  \r
+     */\r
+    private JTextField getJTextFieldType() {\r
+        if (jTextFieldType == null) {\r
+            jTextFieldType = new JTextField();\r
+            jTextFieldType.setBounds(new java.awt.Rectangle(160, 10, 320, 20));\r
+            jTextFieldType.setEditable(false);\r
+        }\r
+        return jTextFieldType;\r
+    }\r
+\r
+    /**\r
+     * This method initializes jTextFieldSource        \r
+     *         \r
+     * @return javax.swing.JTextField  \r
+     */\r
+    private JTextField getJTextFieldSource() {\r
+        if (jTextFieldSource == null) {\r
+            jTextFieldSource = new JTextField();\r
+            jTextFieldSource.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r
+            jTextFieldSource.setEditable(false);\r
+        }\r
+        return jTextFieldSource;\r
+    }\r
+\r
+    /**\r
+     * This method initializes jButtonBrowse   \r
+     *         \r
+     * @return javax.swing.JButton     \r
+     */\r
+    private JButton getJButtonBrowse() {\r
+        if (jButtonBrowse == null) {\r
+            jButtonBrowse = new JButton();\r
+            jButtonBrowse.setBounds(new java.awt.Rectangle(395, 60, 85, 20));\r
+            jButtonBrowse.setText("Browse");\r
+            jButtonBrowse.addActionListener(this);\r
+        }\r
+        return jButtonBrowse;\r
+    }\r
+\r
+    /**\r
+     * This method initializes jTextFieldDestinationFile       \r
+     *         \r
+     * @return javax.swing.JTextField  \r
+     */\r
+    private JTextField getJTextFieldFilePath() {\r
+        if (jTextFieldFilePath == null) {\r
+            jTextFieldFilePath = new JTextField();\r
+            jTextFieldFilePath.setBounds(new java.awt.Rectangle(160, 60, 230, 20));\r
+        }\r
+        return jTextFieldFilePath;\r
+    }\r
+\r
+    /**\r
+     * This method initializes jTextFieldBaseName      \r
+     *         \r
+     * @return javax.swing.JTextField  \r
+     */\r
+    private JTextField getJTextFieldBaseName() {\r
+        if (jTextFieldBaseName == null) {\r
+            jTextFieldBaseName = new JTextField();\r
+            jTextFieldBaseName.setBounds(new java.awt.Rectangle(160, 110, 320, 20));\r
+        }\r
+        return jTextFieldBaseName;\r
+    }\r
+\r
+    /**\r
+     * This method initializes jTextFieldGuid  \r
+     *         \r
+     * @return javax.swing.JTextField  \r
+     */\r
+    private JTextField getJTextFieldGuid() {\r
+        if (jTextFieldGuid == null) {\r
+            jTextFieldGuid = new JTextField();\r
+            jTextFieldGuid.setBounds(new java.awt.Rectangle(160, 135, 230, 20));\r
+        }\r
+        return jTextFieldGuid;\r
+    }\r
+\r
+    /**\r
+     * This method initializes jTextFieldVersion       \r
+     *         \r
+     * @return javax.swing.JTextField  \r
+     */\r
+    private JTextField getJTextFieldVersion() {\r
+        if (jTextFieldVersion == null) {\r
+            jTextFieldVersion = new JTextField();\r
+            jTextFieldVersion.setBounds(new java.awt.Rectangle(160, 160, 320, 20));\r
+        }\r
+        return jTextFieldVersion;\r
+    }\r
+\r
+    /**\r
+     * This method initializes jButtonOk       \r
+     *         \r
+     * @return javax.swing.JButton     \r
+     */\r
+    private JButton getJButtonOk() {\r
+        if (jButtonOk == null) {\r
+            jButtonOk = new JButton();\r
+            jButtonOk.setBounds(new java.awt.Rectangle(235, 200, 90, 20));\r
+            jButtonOk.setText("Ok");\r
+            jButtonOk.addActionListener(this);\r
+        }\r
+        return jButtonOk;\r
+    }\r
+\r
+    /**\r
+     * This method initializes jButtonCancel   \r
+     *         \r
+     * @return javax.swing.JButton     \r
+     */\r
+    private JButton getJButtonCancel() {\r
+        if (jButtonCancel == null) {\r
+            jButtonCancel = new JButton();\r
+            jButtonCancel.setBounds(new java.awt.Rectangle(355, 200, 90, 20));\r
+            jButtonCancel.setText("Cancel");\r
+            jButtonCancel.addActionListener(this);\r
+        }\r
+        return jButtonCancel;\r
+    }\r
+\r
+    /**\r
+     * This method initializes jButtonGenerateGuid     \r
+     *         \r
+     * @return javax.swing.JButton     \r
+     */\r
+    private JButton getJButtonGenerateGuid() {\r
+        if (jButtonGenerateGuid == null) {\r
+            jButtonGenerateGuid = new JButton();\r
+            jButtonGenerateGuid.setBounds(new java.awt.Rectangle(395, 135, 85, 20));\r
+            jButtonGenerateGuid.setText("Gen");\r
+            jButtonGenerateGuid.addActionListener(this);\r
+        }\r
+        return jButtonGenerateGuid;\r
+    }\r
+\r
+    /**\r
+     * This method initializes jComboBoxExistingPackage        \r
+     *         \r
+     * @return javax.swing.JComboBox   \r
+     */\r
+    private JComboBox getJComboBoxExistingPackage() {\r
+        if (jComboBoxExistingPackage == null) {\r
+            jComboBoxExistingPackage = new JComboBox();\r
+            jComboBoxExistingPackage.setBounds(new java.awt.Rectangle(160, 85, 320, 20));\r
+        }\r
+        return jComboBoxExistingPackage;\r
+    }\r
+\r
+    /**\r
+     \r
+     @param args\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
+     \r
+     **/\r
+    public Clone(IFrame parentFrame, boolean modal, int fileType, Identification identification) {\r
+        super(parentFrame, modal);\r
+        this.mode = fileType;\r
+        if (identification != null) {\r
+            this.oldId = new Identification(identification.getName(), identification.getGuid(),\r
+                                            identification.getVersion(), identification.getPath());\r
+            this.newId = new Identification(identification.getName(), identification.getGuid(),\r
+                                            identification.getVersion(), identification.getPath());\r
+        }\r
+        init(mode);\r
+    }\r
+\r
+    /**\r
+     Query all existing packages and fill them into combox\r
+     \r
+     **/\r
+    private void initExistingPackage() {\r
+        packages = wt.getAllPackages();\r
+        for (int index = 0; index < packages.size(); index++) {\r
+            this.jComboBoxExistingPackage.addItem(packages.elementAt(index).getName());\r
+        }\r
+    }\r
+\r
+    /**\r
+     * This method initializes this\r
+     * \r
+     * @return void\r
+     */\r
+    private void init() {\r
+        this.setSize(493, 260);\r
+        this.setContentPane(getJContentPane());\r
+        this.setTitle("Clone");\r
+        this.centerWindow();\r
+    }\r
+\r
+    /**\r
+     * This method initializes this\r
+     * \r
+     * @return void\r
+     */\r
+    private void init(int mode) {\r
+        init();\r
+        if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r
+            this.jTextFieldType.setText(DataType.MODULE_SURFACE_AREA);\r
+            this.jTextFieldSource.setText(oldId.getPath());\r
+            initExistingPackage();\r
+            this.jButtonBrowse.setEnabled(false);\r
+            this.jTextFieldFilePath.setToolTipText("Input module name here. For example, Application\\HelloWorld\\HelloWorld.msa");\r
+            this.jLabelDestinationFile.setText("Module Path\\Name");\r
+        }\r
+        if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r
+            this.jTextFieldType.setText(DataType.PACKAGE_SURFACE_AREA);\r
+            this.jTextFieldSource.setText(oldId.getPath());\r
+            this.jLabelBelong.setEnabled(false);\r
+            this.jComboBoxExistingPackage.setEnabled(false);\r
+            this.jButtonBrowse.setEnabled(false);\r
+            this.jTextFieldFilePath.setToolTipText("Input package name here. For example, MdePkg\\MdePkg.fpd");\r
+            this.jLabelDestinationFile.setText("Package Path\\Name");\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
+            this.jLabelBelong.setEnabled(false);\r
+            this.jComboBoxExistingPackage.setEnabled(false);\r
+            this.jTextFieldFilePath.setToolTipText("Select platform path here. For example, C:\\MyWorkspace\\EdkNt32Pkg\\Nt32.fpd");\r
+            this.jLabelDestinationFile.setText("New Platform path");\r
+        }\r
+        if (mode == DataType.RETURN_TYPE_WORKSPACE) {\r
+            this.jTextFieldType.setText(DataType.WORKSPACE);\r
+            this.jTextFieldSource.setText(Workspace.getCurrentWorkspace());\r
+            this.jLabelBelong.setEnabled(false);\r
+            this.jComboBoxExistingPackage.setEnabled(false);\r
+            this.jLabelBaseName.setEnabled(false);\r
+            this.jTextFieldBaseName.setEditable(false);\r
+            this.jLabelGuid.setEnabled(false);\r
+            this.jTextFieldGuid.setEnabled(false);\r
+            this.jButtonGenerateGuid.setEnabled(false);\r
+            this.jLabelVersion.setEnabled(false);\r
+            this.jTextFieldVersion.setEnabled(false);\r
+            this.jTextFieldFilePath.setToolTipText("Input workspace path here. For example, C:\\MyWorkspace");\r
+            this.jLabelDestinationFile.setText("New Workspace path");\r
+        }\r
+    }\r
+\r
+    /**\r
+     * This method initializes jContentPane\r
+     * \r
+     * @return javax.swing.JPanel\r
+     */\r
+    private JPanel getJContentPane() {\r
+        if (jContentPane == null) {\r
+            jLabelBelong = new JLabel();\r
+            jLabelBelong.setBounds(new java.awt.Rectangle(15, 85, 140, 20));\r
+            jLabelBelong.setText("Clone to Package");\r
+            jLabelVersion = new JLabel();\r
+            jLabelVersion.setBounds(new java.awt.Rectangle(15, 160, 140, 20));\r
+            jLabelVersion.setText("Version");\r
+            jLabelGuid = new JLabel();\r
+            jLabelGuid.setBounds(new java.awt.Rectangle(15, 135, 140, 20));\r
+            jLabelGuid.setText("Guid");\r
+            jLabelBaseName = new JLabel();\r
+            jLabelBaseName.setBounds(new java.awt.Rectangle(15, 110, 140, 20));\r
+            jLabelBaseName.setText("Base Name");\r
+            jLabelDestinationFile = new JLabel();\r
+            jLabelDestinationFile.setBounds(new java.awt.Rectangle(15, 60, 140, 20));\r
+            jLabelDestinationFile.setText("Destination File Name");\r
+            jLabelSource = new JLabel();\r
+            jLabelSource.setBounds(new java.awt.Rectangle(15, 35, 140, 20));\r
+            jLabelSource.setText("Source");\r
+            jLabelType = new JLabel();\r
+            jLabelType.setBounds(new java.awt.Rectangle(15, 10, 140, 20));\r
+            jLabelType.setText("Type");\r
+            jContentPane = new JPanel();\r
+            jContentPane.setLayout(null);\r
+            jContentPane.setSize(new java.awt.Dimension(490, 227));\r
+            jContentPane.add(jLabelType, null);\r
+            jContentPane.add(getJTextFieldType(), null);\r
+            jContentPane.add(jLabelSource, null);\r
+            jContentPane.add(getJTextFieldSource(), null);\r
+            jContentPane.add(jLabelDestinationFile, null);\r
+            jContentPane.add(getJTextFieldFilePath(), null);\r
+            jContentPane.add(jLabelBaseName, null);\r
+            jContentPane.add(getJTextFieldBaseName(), null);\r
+            jContentPane.add(jLabelGuid, null);\r
+            jContentPane.add(getJTextFieldGuid(), null);\r
+            jContentPane.add(jLabelVersion, null);\r
+            jContentPane.add(getJTextFieldVersion(), null);\r
+            jContentPane.add(getJButtonOk(), null);\r
+            jContentPane.add(getJButtonCancel(), null);\r
+            jContentPane.add(getJButtonBrowse(), null);\r
+            jContentPane.add(getJButtonGenerateGuid(), null);\r
+            jContentPane.add(jLabelBelong, null);\r
+            jContentPane.add(getJComboBoxExistingPackage(), null);\r
+        }\r
+        return jContentPane;\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
+     * \r
+     * Override actionPerformed to listen all actions\r
+     */\r
+    public void actionPerformed(ActionEvent arg0) {\r
+        if (arg0.getSource() == jButtonCancel) {\r
+            this.setVisible(false);\r
+            this.returnType = DataType.RETURN_TYPE_CANCEL;\r
+        }\r
+\r
+        if (arg0.getSource() == jButtonOk) {\r
+            if (this.check()) {\r
+                try {\r
+                    this.save();\r
+                } catch (IOException e) {\r
+                    Log.err("Clone", e.getMessage());\r
+                    e.printStackTrace();\r
+                    return;\r
+                } catch (XmlException e) {\r
+                    Log.err("Clone", e.getMessage());\r
+                    e.printStackTrace();\r
+                    return;\r
+                } catch (Exception e) {\r
+                    Log.err("Clone", e.getMessage());\r
+                    e.printStackTrace();\r
+                    return;\r
+                }\r
+            } else {\r
+                return;\r
+            }\r
+            this.setVisible(false);\r
+        }\r
+\r
+        if (arg0.getSource() == this.jButtonGenerateGuid) {\r
+            this.jTextFieldGuid.setText(Tools.generateUuidString());\r
+        }\r
+\r
+        //\r
+        // Use different file ext\r
+        //\r
+        if (arg0.getSource() == this.jButtonBrowse) {\r
+            JFileChooser fc = new JFileChooser();\r
+            fc.setAcceptAllFileFilterUsed(false);\r
+\r
+            if (mode == DataType.RETURN_TYPE_WORKSPACE) {\r
+                fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));\r
+                fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);\r
+            }\r
+            if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r
+                fc.setCurrentDirectory(new File(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())\r
+                                                        .getPath()));\r
+                fc.addChoosableFileFilter(new IFileFilter(DataType.MODULE_SURFACE_AREA_EXT));\r
+            }\r
+            if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r
+                fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));\r
+                fc.addChoosableFileFilter(new IFileFilter(DataType.PACKAGE_SURFACE_AREA_EXT));\r
+            }\r
+            if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r
+                fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));\r
+                fc.addChoosableFileFilter(new IFileFilter(DataType.PLATFORM_SURFACE_AREA_EXT));\r
+            }\r
+            int result = fc.showSaveDialog(new JPanel());\r
+            if (result == JFileChooser.APPROVE_OPTION) {\r
+                this.jTextFieldFilePath.setText(Tools.addPathExt(fc.getSelectedFile().getPath(), mode));\r
+            }\r
+        }\r
+    }\r
+\r
+    //\r
+    // Check name, guid and version\r
+    //\r
+    private boolean checkId() {\r
+        //\r
+        // Check Basename\r
+        //\r
+        if (isEmpty(this.jTextFieldBaseName.getText())) {\r
+            Log.err("Base Name couldn't be empty!");\r
+            return false;\r
+        }\r
+        if (!DataValidation.isBaseName(this.jTextFieldBaseName.getText())) {\r
+            Log.err("Incorrect data type for Base Name");\r
+            return false;\r
+        }\r
+\r
+        //\r
+        // Check Guid\r
+        //\r
+        if (isEmpty(this.jTextFieldGuid.getText())) {\r
+            Log.err("Guid couldn't be empty!");\r
+            return false;\r
+        }\r
+        if (!DataValidation.isGuid(this.jTextFieldGuid.getText())) {\r
+            Log.err("Incorrect data type for Guid");\r
+            return false;\r
+        }\r
+\r
+        //\r
+        // Check Version\r
+        //\r
+        if (isEmpty(this.jTextFieldVersion.getText())) {\r
+            Log.err("Version couldn't be empty!");\r
+            return false;\r
+        }\r
+        if (!DataValidation.isVersion(this.jTextFieldVersion.getText())) {\r
+            Log.err("Incorrect data type for Version");\r
+            return false;\r
+        }\r
+\r
+        //\r
+        // Save information to id\r
+        //\r
+        newId.setName(this.jTextFieldBaseName.getText());\r
+        newId.setGuid(this.jTextFieldGuid.getText());\r
+        newId.setVersion(this.jTextFieldVersion.getText());\r
+        newId.setPath(this.jTextFieldFilePath.getText());\r
+\r
+        return true;\r
+    }\r
+\r
+    /**\r
+     Check before save\r
+     \r
+     @return\r
+     \r
+     **/\r
+    private boolean check() {\r
+        String src = this.jTextFieldSource.getText();\r
+        String trg = this.jTextFieldFilePath.getText();\r
+        File srcFile = new File(src);\r
+        File trgFile = new File(trg);\r
+\r
+        //\r
+        // Common Check\r
+        //\r
+        if (!srcFile.exists()) {\r
+            Log.err("The source doesn't exist");\r
+            return false;\r
+        }\r
+        if (isEmpty(trg)) {\r
+            Log.err("The destination file path couldn't be empty");\r
+            return false;\r
+        }\r
+        if (src.equals(trg)) {\r
+            Log.err("The source and destination couldn't be same");\r
+            return false;\r
+        }\r
+        if (trgFile.exists()) {\r
+            Log.err("The destination already exists");\r
+            return false;\r
+        }\r
+\r
+        //\r
+        // Check for workspace\r
+        //\r
+        if (mode == DataType.RETURN_TYPE_WORKSPACE) {\r
+            if (trg.indexOf(src + DataType.FILE_SEPARATOR) == 0) {\r
+                Log.err("The new workspace couldn't be in current workspace!");\r
+                return false;\r
+            }\r
+        }\r
+\r
+        //\r
+        // Check for Module\r
+        //\r
+        if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r
+            return checkId();\r
+        }\r
+\r
+        //\r
+        // Check for Package\r
+        //\r
+        if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r
+            if (trg.indexOf(DataType.DOS_FILE_SEPARATOR) == -1 && trg.indexOf(DataType.UNIX_FILE_SEPARATOR) == -1) {\r
+                Log.err("The package name must include a path");\r
+                return false;\r
+            }\r
+            trg = this.getPackagePath();\r
+            if (Tools.getFilePathOnly(src).equals(Tools.getFilePathOnly(trg))) {\r
+                Log.err("The source and destination couldn't be same");\r
+                return false;\r
+            }\r
+            trgFile = new File(trg);\r
+            if (trgFile.exists()) {\r
+                Log.err("The target package already exists");\r
+                return false;\r
+            }\r
+            return checkId();\r
+        }\r
+\r
+        //\r
+        // Check for Platform\r
+        //\r
+        if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r
+            if (trg.indexOf(Workspace.getCurrentWorkspace()) != 0) {\r
+                Log.err("The target platform must be in current workspace");\r
+                return false;\r
+            }\r
+            trgFile = new File(trg);\r
+            if (trgFile.exists()) {\r
+                Log.err("The target platform already exists");\r
+                return false;\r
+            }\r
+            return checkId();\r
+        }\r
+\r
+        return true;\r
+    }\r
+\r
+    private void save() throws IOException, XmlException, Exception {\r
+        String src = this.jTextFieldSource.getText();\r
+        String trg = this.jTextFieldFilePath.getText();\r
+        \r
+        //\r
+        // Clone Workspace\r
+        //\r
+        if (mode == DataType.RETURN_TYPE_WORKSPACE) {\r
+            try {\r
+                FileOperation.copyFolder(src, trg);\r
+            } catch (Exception e) {\r
+                this.returnType = DataType.RETURN_TYPE_CANCEL;\r
+                Log.err("Clone Workspace", e.getMessage());\r
+                e.printStackTrace();\r
+            }\r
+            this.returnType = DataType.RETURN_TYPE_WORKSPACE;\r
+        }\r
+\r
+        //\r
+        // Clone Module Surface Area\r
+        //\r
+        if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r
+            //\r
+            // Get target path from source path\r
+            //\r
+            trg = getModulePath();\r
+            newId.setPath(trg);\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 msa file\r
+            //\r
+            ModuleSurfaceArea msa = null;\r
+            msa = OpenFile.openMsaFile(src);\r
+\r
+            //\r
+            // Update to memory\r
+            //\r
+            msa.getMsaHeader().setModuleName(newId.getName());\r
+            msa.getMsaHeader().setGuidValue(newId.getGuid());\r
+            msa.getMsaHeader().setVersion(newId.getVersion());\r
+\r
+            //\r
+            // Update Cloned From element\r
+            //\r
+            updateModuleClonedId(msa, oldId);\r
+            \r
+            //\r
+            // Save to file\r
+            //\r
+            SaveFile.saveMsaFile(trg, msa);\r
+\r
+            //\r
+            // Update to platformId\r
+            //\r
+            this.setMid(new ModuleIdentification(newId, packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())));\r
+\r
+            //\r
+            // Open belonging package\r
+            //\r
+            PackageSurfaceArea psa = PackageSurfaceArea.Factory.newInstance();\r
+            psa = OpenFile.openSpdFile(mid.getPackageId().getPath());\r
+            \r
+            //\r
+            // Update the db file\r
+            //\r
+            wt.addModuleToPackage(mid, psa);\r
+\r
+            this.returnType = DataType.RETURN_TYPE_MODULE_SURFACE_AREA;\r
+        }\r
+\r
+        //\r
+        // Clone Package Surface Area\r
+        //\r
+        if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r
+            //\r
+            // Get target path from source path\r
+            //\r
+            trg = this.getPackagePath();\r
+            newId.setPath(trg);\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
+            PackageSurfaceArea spd = null;\r
+            spd = OpenFile.openSpdFile(src);\r
+\r
+            //\r
+            // Update to memory\r
+            //\r
+            spd.getSpdHeader().setPackageName(newId.getName());\r
+            spd.getSpdHeader().setGuidValue(newId.getGuid());\r
+            spd.getSpdHeader().setVersion(newId.getVersion());\r
+\r
+            //\r
+            // Update Cloned From element\r
+            //\r
+            updatePackageClonedId(spd, oldId);\r
+            \r
+            //\r
+            // Save to file\r
+            //\r
+            SaveFile.saveSpdFile(trg, spd);\r
+\r
+            //\r
+            // Update to platformId\r
+            //\r
+            this.setPid(new PackageIdentification(newId));\r
+\r
+            //\r
+            // Update the db file\r
+            //\r
+            wt.addPackageToDatabase(pid);\r
+\r
+            this.returnType = DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA;\r
+        }\r
+\r
+        //\r
+        // Clone Platform Surface Area\r
+        //\r
+        if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r
+            PlatformSurfaceArea fpd = null;\r
+            fpd = OpenFile.openFpdFile(src);\r
+\r
+            //\r
+            // Update to memory\r
+            //\r
+            fpd.getPlatformHeader().setPlatformName(newId.getName());\r
+            fpd.getPlatformHeader().setGuidValue(newId.getGuid());\r
+            fpd.getPlatformHeader().setVersion(newId.getVersion());\r
+\r
+            //\r
+            // Update Cloned From element\r
+            //\r
+            updatePlatformClonedId(fpd, oldId);\r
+\r
+            //\r
+            // Save to file\r
+            //\r
+            SaveFile.saveFpdFile(trg, fpd);\r
+\r
+            //\r
+            // Update to platformId\r
+            //\r
+            this.setFid(new PlatformIdentification(newId));\r
+\r
+            //\r
+            // Update the db file\r
+            //\r
+            wt.addPlatformToDatabase(fid);\r
+\r
+            this.returnType = DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA;\r
+        }\r
+    }\r
+    \r
+    private String getSelectPackagePath() {\r
+        return Tools.getFilePathOnly(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getPath());\r
+    }\r
+\r
+    private String getModulePath() {\r
+        String trg = this.jTextFieldFilePath.getText();\r
+        trg = Tools.addPathExt(trg, mode);\r
+        trg = getSelectPackagePath() + DataType.FILE_SEPARATOR + trg;\r
+        Tools.convertPathToCurrentOsType(trg);\r
+        return trg;\r
+    }\r
+    \r
+    private String getPackagePath() {\r
+        String trg = this.jTextFieldFilePath.getText();\r
+        trg = Tools.addPathExt(trg, mode);\r
+        trg = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + trg;\r
+        trg = Tools.convertPathToCurrentOsType(trg);\r
+        return trg;\r
+    }\r
+    \r
+    /**\r
+     Set target item's Cloned From element\r
+\r
+     @param id\r
+     @return\r
+\r
+     **/\r
+    private void updateModuleClonedId(ModuleSurfaceArea msa, Identification id) {\r
+        //\r
+        // Get PlatformDefinitions First\r
+        //\r
+        ModuleDefinitions pd = null;\r
+        if (msa.getModuleDefinitions() == null) {\r
+            pd = ModuleDefinitions.Factory.newInstance();\r
+            msa.addNewModuleDefinitions();\r
+        } else {\r
+            pd = msa.getModuleDefinitions();\r
+        }\r
+\r
+        //\r
+        // Get ClonedFrom then\r
+        //\r
+        ModuleDefinitions.ClonedFrom cf = null;\r
+        if (pd.getClonedFrom() == null) {\r
+            cf = ModuleDefinitions.ClonedFrom.Factory.newInstance();\r
+        } else {\r
+            cf = pd.getClonedFrom();\r
+        }\r
+\r
+        //\r
+        // Set new Cloned item\r
+        //\r
+        ModuleDefinitions.ClonedFrom.Cloned c = ModuleDefinitions.ClonedFrom.Cloned.Factory.newInstance();\r
+        c.setModuleGuid(id.getGuid());\r
+        c.setModuleVersion(id.getVersion());\r
+\r
+        cf.addNewCloned();\r
+        cf.setClonedArray(cf.getClonedList().size() - 1, c);\r
+        pd.addNewClonedFrom();\r
+        pd.setClonedFrom(cf);\r
+        msa.setModuleDefinitions(pd);\r
+    }\r
+\r
+    /**\r
+     Set target item's Cloned From element\r
+     \r
+     @param id\r
+     @return\r
+     \r
+     **/\r
+    private void updatePackageClonedId(PackageSurfaceArea spd, Identification id) {\r
+        //\r
+        // Get PlatformDefinitions First\r
+        //\r
+        PackageDefinitions pd = null;\r
+        if (spd.getPackageDefinitions() == null) {\r
+            pd = PackageDefinitions.Factory.newInstance();\r
+            spd.addNewPackageDefinitions();\r
+        } else {\r
+            pd = spd.getPackageDefinitions();\r
+        }\r
+\r
+        //\r
+        // Get ClonedFrom then\r
+        //\r
+        PackageDefinitions.ClonedFrom cf = null;\r
+        if (pd.getClonedFrom() == null) {\r
+            cf = PackageDefinitions.ClonedFrom.Factory.newInstance();\r
+        } else {\r
+            cf = pd.getClonedFrom();\r
+        }\r
+\r
+        //\r
+        // Set new Cloned item\r
+        //\r
+        PackageDefinitions.ClonedFrom.Cloned c = PackageDefinitions.ClonedFrom.Cloned.Factory.newInstance();\r
+        c.setPackageGuid(id.getGuid());\r
+        c.setPackageVersion(id.getVersion());\r
+\r
+        cf.addNewCloned();\r
+        cf.setClonedArray(cf.getClonedList().size() - 1, c);\r
+        pd.addNewClonedFrom();\r
+        pd.setClonedFrom(cf);\r
+        spd.setPackageDefinitions(pd);\r
+    }\r
+\r
+    /**\r
+     Set target item's Cloned From element\r
+     \r
+     @param id\r
+     @return\r
+     \r
+     **/\r
+    private void updatePlatformClonedId(PlatformSurfaceArea fpd, Identification id) {\r
+        //\r
+        // Get PlatformDefinitions First\r
+        //\r
+        PlatformDefinitions pd = null;\r
+        if (fpd.getPlatformDefinitions() == null) {\r
+            pd = PlatformDefinitions.Factory.newInstance();\r
+            fpd.addNewPlatformDefinitions();\r
+        } else {\r
+            pd = fpd.getPlatformDefinitions();\r
+        }\r
+\r
+        //\r
+        // Get ClonedFrom then\r
+        //\r
+        PlatformDefinitions.ClonedFrom cf = null;\r
+        if (pd.getClonedFrom() == null) {\r
+            cf = PlatformDefinitions.ClonedFrom.Factory.newInstance();\r
+        } else {\r
+            cf = pd.getClonedFrom();\r
+        }\r
+\r
+        //\r
+        // Set new Cloned item\r
+        //\r
+        PlatformDefinitions.ClonedFrom.Cloned c = PlatformDefinitions.ClonedFrom.Cloned.Factory.newInstance();\r
+        c.setPlatformGuid(id.getGuid());\r
+        c.setPlatformVersion(id.getVersion());\r
+\r
+        cf.addNewCloned();\r
+        cf.setClonedArray(cf.getClonedList().size() - 1, c);\r
+        pd.addNewClonedFrom();\r
+        pd.setClonedFrom(cf);\r
+        fpd.setPlatformDefinitions(pd);\r
+    }\r
+\r
+    public PlatformIdentification getFid() {\r
+        return fid;\r
+    }\r
+\r
+    public void setFid(PlatformIdentification fid) {\r
+        this.fid = fid;\r
+    }\r
+\r
+    public ModuleIdentification getMid() {\r
+        return mid;\r
+    }\r
+\r
+    public void setMid(ModuleIdentification mid) {\r
+        this.mid = mid;\r
+    }\r
+\r
+    public PackageIdentification getPid() {\r
+        return pid;\r
+    }\r
+\r
+    public void setPid(PackageIdentification pid) {\r
+        this.pid = pid;\r
+    }\r
+}\r