3 The file is used to clone workspace, module, package and platform
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 package org
.tianocore
.frameworkwizard
;
17 import java
.awt
.event
.ActionEvent
;
19 import java
.io
.IOException
;
20 import java
.math
.BigInteger
;
21 import java
.util
.Vector
;
23 import javax
.swing
.JFileChooser
;
24 import javax
.swing
.JPanel
;
25 import javax
.swing
.JLabel
;
26 import javax
.swing
.JTextField
;
27 import javax
.swing
.JButton
;
29 import org
.apache
.xmlbeans
.XmlException
;
30 import org
.tianocore
.ModuleDefinitionsDocument
.ModuleDefinitions
;
31 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
32 import org
.tianocore
.PackageDefinitionsDocument
.PackageDefinitions
;
33 import org
.tianocore
.PackageSurfaceAreaDocument
.PackageSurfaceArea
;
34 import org
.tianocore
.PlatformDefinitionsDocument
.PlatformDefinitions
;
35 import org
.tianocore
.PlatformSurfaceAreaDocument
.PlatformSurfaceArea
;
36 import org
.tianocore
.frameworkwizard
.common
.DataType
;
37 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
38 import org
.tianocore
.frameworkwizard
.common
.FileOperation
;
39 import org
.tianocore
.frameworkwizard
.common
.GlobalData
;
40 import org
.tianocore
.frameworkwizard
.common
.IFileFilter
;
41 import org
.tianocore
.frameworkwizard
.common
.Log
;
42 import org
.tianocore
.frameworkwizard
.common
.OpenFile
;
43 import org
.tianocore
.frameworkwizard
.common
.SaveFile
;
44 import org
.tianocore
.frameworkwizard
.common
.Tools
;
45 import org
.tianocore
.frameworkwizard
.common
.Identifications
.Identification
;
46 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
47 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
48 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
49 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
50 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
51 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
52 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
53 import javax
.swing
.JComboBox
;
56 The class is used to provide functions to clone workspace, module, package and platform
60 public class Clone
extends IDialog
{
63 /// Define Class Serial Version UID
65 private static final long serialVersionUID
= -5469299324965727137L;
68 /// Define Class Members
70 private JPanel jContentPane
= null;
72 private JLabel jLabelType
= null;
74 private JTextField jTextFieldType
= null;
76 private JLabel jLabelSource
= null;
78 private JTextField jTextFieldSource
= null;
80 private JButton jButtonBrowse
= null;
82 private JLabel jLabelDestinationFile
= null;
84 private JTextField jTextFieldFilePath
= null;
86 private JLabel jLabelBaseName
= null;
88 private JTextField jTextFieldBaseName
= null;
90 private JLabel jLabelGuid
= null;
92 private JTextField jTextFieldGuid
= null;
94 private JLabel jLabelVersion
= null;
96 private JTextField jTextFieldVersion
= null;
98 private JButton jButtonOk
= null;
100 private JButton jButtonCancel
= null;
102 private JButton jButtonGenerateGuid
= null;
104 private JLabel jLabelBelong
= null;
106 private JComboBox jComboBoxExistingPackage
= null;
109 /// Define members not for UI
112 private int mode
= -1;
114 private Vector
<PackageIdentification
> packages
= null;
116 private WorkspaceTools wt
= new WorkspaceTools();
118 private Identification oldId
= null;
120 private Identification newId
= null;
122 private ModuleIdentification mid
= null;
124 private PackageIdentification pid
= null;
126 private PlatformIdentification fid
= null;
129 This method initializes jTextFieldType
131 @return javax.swing.JTextField
134 private JTextField
getJTextFieldType() {
135 if (jTextFieldType
== null) {
136 jTextFieldType
= new JTextField();
137 jTextFieldType
.setBounds(new java
.awt
.Rectangle(210, 10, 320, 20));
138 jTextFieldType
.setEditable(false);
140 return jTextFieldType
;
144 This method initializes jTextFieldSource
146 @return javax.swing.JTextField
149 private JTextField
getJTextFieldSource() {
150 if (jTextFieldSource
== null) {
151 jTextFieldSource
= new JTextField();
152 jTextFieldSource
.setBounds(new java
.awt
.Rectangle(210, 35, 320, 20));
153 jTextFieldSource
.setEditable(false);
155 return jTextFieldSource
;
159 This method initializes jButtonBrowse
161 @return javax.swing.JButton
164 private JButton
getJButtonBrowse() {
165 if (jButtonBrowse
== null) {
166 jButtonBrowse
= new JButton();
167 jButtonBrowse
.setBounds(new java
.awt
.Rectangle(445, 85, 85, 20));
168 jButtonBrowse
.setText("Browse");
169 jButtonBrowse
.addActionListener(this);
171 return jButtonBrowse
;
175 This method initializes jTextFieldDestinationFile
177 @return javax.swing.JTextField
180 private JTextField
getJTextFieldFilePath() {
181 if (jTextFieldFilePath
== null) {
182 jTextFieldFilePath
= new JTextField();
183 jTextFieldFilePath
.setBounds(new java
.awt
.Rectangle(210, 85, 230, 20));
185 return jTextFieldFilePath
;
189 This method initializes jTextFieldBaseName
191 @return javax.swing.JTextField
194 private JTextField
getJTextFieldBaseName() {
195 if (jTextFieldBaseName
== null) {
196 jTextFieldBaseName
= new JTextField();
197 jTextFieldBaseName
.setBounds(new java
.awt
.Rectangle(210, 110, 320, 20));
199 return jTextFieldBaseName
;
203 This method initializes jTextFieldGuid
205 @return javax.swing.JTextField
208 private JTextField
getJTextFieldGuid() {
209 if (jTextFieldGuid
== null) {
210 jTextFieldGuid
= new JTextField();
211 jTextFieldGuid
.setBounds(new java
.awt
.Rectangle(210, 135, 230, 20));
213 return jTextFieldGuid
;
217 This method initializes jTextFieldVersion
219 @return javax.swing.JTextField
222 private JTextField
getJTextFieldVersion() {
223 if (jTextFieldVersion
== null) {
224 jTextFieldVersion
= new JTextField();
225 jTextFieldVersion
.setBounds(new java
.awt
.Rectangle(210, 160, 320, 20));
227 return jTextFieldVersion
;
231 This method initializes jButtonOk
233 @return javax.swing.JButton
236 private JButton
getJButtonOk() {
237 if (jButtonOk
== null) {
238 jButtonOk
= new JButton();
239 jButtonOk
.setBounds(new java
.awt
.Rectangle(285, 200, 90, 20));
240 jButtonOk
.setText("Ok");
241 jButtonOk
.addActionListener(this);
247 This method initializes jButtonCancel
249 @return javax.swing.JButton
252 private JButton
getJButtonCancel() {
253 if (jButtonCancel
== null) {
254 jButtonCancel
= new JButton();
255 jButtonCancel
.setBounds(new java
.awt
.Rectangle(405, 200, 90, 20));
256 jButtonCancel
.setText("Cancel");
257 jButtonCancel
.addActionListener(this);
259 return jButtonCancel
;
263 This method initializes jButtonGenerateGuid
265 @return javax.swing.JButton
268 private JButton
getJButtonGenerateGuid() {
269 if (jButtonGenerateGuid
== null) {
270 jButtonGenerateGuid
= new JButton();
271 jButtonGenerateGuid
.setBounds(new java
.awt
.Rectangle(445, 135, 85, 20));
272 jButtonGenerateGuid
.setText("Gen");
273 jButtonGenerateGuid
.addActionListener(this);
275 return jButtonGenerateGuid
;
279 This method initializes jComboBoxExistingPackage
281 @return javax.swing.JComboBox
284 private JComboBox
getJComboBoxExistingPackage() {
285 if (jComboBoxExistingPackage
== null) {
286 jComboBoxExistingPackage
= new JComboBox();
287 jComboBoxExistingPackage
.setBounds(new java
.awt
.Rectangle(210, 60, 320, 20));
289 return jComboBoxExistingPackage
;
293 This is the default constructor
302 This is the override constructor
304 @param parentFrame The parent frame which starts this frame
305 @param modal To identify the frame's modal
306 @param fileType To identify the clone target type
307 @param identification The clone target's identification
310 public Clone(IFrame parentFrame
, boolean modal
, int fileType
, Identification identification
) {
311 super(parentFrame
, modal
);
312 this.mode
= fileType
;
313 if (identification
!= null) {
314 this.oldId
= new Identification(identification
.getName(), identification
.getGuid(),
315 identification
.getVersion(), identification
.getPath());
316 this.newId
= new Identification(identification
.getName(), identification
.getGuid(),
317 identification
.getVersion(), identification
.getPath());
323 Query all existing packages and fill them into combox
326 private void initExistingPackage() {
327 packages
= wt
.getAllPackages();
328 for (int index
= 0; index
< packages
.size(); index
++) {
329 this.jComboBoxExistingPackage
.addItem(packages
.elementAt(index
).getName());
334 This method initializes this
337 private void init() {
338 this.setSize(550, 260);
339 this.setContentPane(getJContentPane());
340 this.setTitle("Clone");
345 This method initializes this with given clone target type.
346 Customize the frame interface via different clone target type.
348 @param mode To identify the clone target type
351 private void init(int mode
) {
354 // For MODULE_SURFACE_AREA
356 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
357 this.jTextFieldType
.setText(DataType
.MODULE_SURFACE_AREA
);
358 String s
= oldId
.getPath();
359 s
= Tools
.getRelativePath(s
, Tools
.getFilePathOnly(wt
.getPackageIdByModuleId(oldId
).getPath()));
360 this.jTextFieldSource
.setText(Tools
.convertPathToCurrentOsType(s
));
361 initExistingPackage();
362 this.jButtonBrowse
.setVisible(false);
363 this.jTextFieldFilePath
364 .setToolTipText("<html>Input the module's relative path and filename, for example:<br>Application\\HelloWorld\\HelloWorld.msa</html>");
365 this.jTextFieldFilePath
.setSize(320, this.jTextFieldFilePath
.getSize().height
);
366 this.jLabelDestinationFile
.setText("New Module Path and Filename");
369 // For PACKAGE_SURFACE_AREA
371 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
372 this.jTextFieldType
.setText(DataType
.PACKAGE_SURFACE_AREA
);
373 String s
= oldId
.getPath();
374 s
= Tools
.getRelativePath(oldId
.getPath(), Workspace
.getCurrentWorkspace());
375 this.jTextFieldSource
.setText(Tools
.convertPathToCurrentOsType(s
));
376 this.jLabelBelong
.setEnabled(false);
377 this.jComboBoxExistingPackage
.setEnabled(false);
378 this.jButtonBrowse
.setVisible(false);
379 this.jTextFieldFilePath
.setToolTipText("<html>Input the package's relative path and file name, for example:<br>MdePkg\\MdePkg.spd</html>");
380 this.jTextFieldFilePath
.setSize(320, this.jTextFieldFilePath
.getSize().height
);
381 this.jLabelDestinationFile
.setText("New Package Path and Filename");
384 // For PLATFORM_SURFACE_AREA
386 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
387 this.jTextFieldType
.setText(DataType
.PLATFORM_SURFACE_AREA
);
388 this.jTextFieldSource
.setText(oldId
.getPath());
389 this.jLabelBelong
.setEnabled(false);
390 this.jComboBoxExistingPackage
.setEnabled(false);
391 this.jTextFieldFilePath
392 .setToolTipText("<html>Select the platform's relative path and filename. For example:<br>C:\\MyWorkspace\\EdkNt32Pkg\\Nt32.fpd</html>");
393 this.jLabelDestinationFile
.setText("New Platform Path and Filename");
398 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
399 this.jTextFieldType
.setText(DataType
.WORKSPACE
);
400 this.jTextFieldSource
.setText(Workspace
.getCurrentWorkspace());
401 this.jLabelBelong
.setEnabled(false);
402 this.jComboBoxExistingPackage
.setEnabled(false);
403 this.jLabelBaseName
.setEnabled(false);
404 this.jTextFieldBaseName
.setEditable(false);
405 this.jLabelGuid
.setEnabled(false);
406 this.jTextFieldGuid
.setEnabled(false);
407 this.jButtonGenerateGuid
.setEnabled(false);
408 this.jLabelVersion
.setEnabled(false);
409 this.jTextFieldVersion
.setEnabled(false);
410 this.jTextFieldFilePath
.setToolTipText("<html>Input the workspace path, for example:<br>C:\\MyWorkspace</html>");
411 this.jLabelDestinationFile
.setText("New Workspace Path");
416 This method initializes jContentPane
418 @return javax.swing.JPanel
421 private JPanel
getJContentPane() {
422 if (jContentPane
== null) {
423 jLabelBelong
= new JLabel();
424 jLabelBelong
.setBounds(new java
.awt
.Rectangle(15, 60, 190, 20));
425 jLabelBelong
.setText("Clone Package");
426 jLabelVersion
= new JLabel();
427 jLabelVersion
.setBounds(new java
.awt
.Rectangle(15, 160, 190, 20));
428 jLabelVersion
.setText("Version");
429 jLabelGuid
= new JLabel();
430 jLabelGuid
.setBounds(new java
.awt
.Rectangle(15, 135, 190, 20));
431 jLabelGuid
.setText("Guid");
432 jLabelBaseName
= new JLabel();
433 jLabelBaseName
.setBounds(new java
.awt
.Rectangle(15, 110, 190, 20));
434 jLabelBaseName
.setText("Base Name");
435 jLabelDestinationFile
= new JLabel();
436 jLabelDestinationFile
.setBounds(new java
.awt
.Rectangle(15, 85, 190, 20));
437 jLabelDestinationFile
.setText("Destination File Name");
438 jLabelSource
= new JLabel();
439 jLabelSource
.setBounds(new java
.awt
.Rectangle(15, 35, 190, 20));
440 jLabelSource
.setText("Source");
441 jLabelType
= new JLabel();
442 jLabelType
.setBounds(new java
.awt
.Rectangle(15, 10, 190, 20));
443 jLabelType
.setText("Type");
444 jContentPane
= new JPanel();
445 jContentPane
.setLayout(null);
446 jContentPane
.setSize(new java
.awt
.Dimension(540, 227));
447 jContentPane
.add(jLabelType
, null);
448 jContentPane
.add(getJTextFieldType(), null);
449 jContentPane
.add(jLabelSource
, null);
450 jContentPane
.add(getJTextFieldSource(), null);
451 jContentPane
.add(jLabelDestinationFile
, null);
452 jContentPane
.add(getJTextFieldFilePath(), null);
453 jContentPane
.add(jLabelBaseName
, null);
454 jContentPane
.add(getJTextFieldBaseName(), null);
455 jContentPane
.add(jLabelGuid
, null);
456 jContentPane
.add(getJTextFieldGuid(), null);
457 jContentPane
.add(jLabelVersion
, null);
458 jContentPane
.add(getJTextFieldVersion(), null);
459 jContentPane
.add(getJButtonOk(), null);
460 jContentPane
.add(getJButtonCancel(), null);
461 jContentPane
.add(getJButtonBrowse(), null);
462 jContentPane
.add(getJButtonGenerateGuid(), null);
463 jContentPane
.add(jLabelBelong
, null);
464 jContentPane
.add(getJComboBoxExistingPackage(), null);
470 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
472 * Override actionPerformed to listen all actions
474 public void actionPerformed(ActionEvent arg0
) {
475 if (arg0
.getSource() == jButtonCancel
) {
476 this.setVisible(false);
477 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
480 if (arg0
.getSource() == jButtonOk
) {
487 } catch (IOException e
) {
488 Log
.wrn("Clone", e
.getMessage());
489 Log
.err("Clone", e
.getMessage());
491 } catch (XmlException e
) {
492 Log
.wrn("Clone", e
.getMessage());
493 Log
.err("Clone", e
.getMessage());
495 } catch (Exception e
) {
496 Log
.wrn("Clone", e
.getMessage());
497 Log
.err("Clone", e
.getMessage());
503 this.setVisible(false);
506 if (arg0
.getSource() == this.jButtonGenerateGuid
) {
507 this.jTextFieldGuid
.setText(Tools
.generateUuidString());
511 // Use different file ext for different clone target type
513 if (arg0
.getSource() == this.jButtonBrowse
) {
514 JFileChooser fc
= new JFileChooser();
515 fc
.setAcceptAllFileFilterUsed(false);
517 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
518 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
519 fc
.setFileSelectionMode(JFileChooser
.DIRECTORIES_ONLY
);
521 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
522 fc
.setCurrentDirectory(new File(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())
524 fc
.addChoosableFileFilter(new IFileFilter(DataType
.MODULE_SURFACE_AREA_EXT
));
526 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
527 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
528 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PACKAGE_SURFACE_AREA_EXT
));
530 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
531 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
532 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PLATFORM_SURFACE_AREA_EXT
));
534 int result
= fc
.showSaveDialog(new JPanel());
535 if (result
== JFileChooser
.APPROVE_OPTION
) {
536 this.jTextFieldFilePath
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(), mode
));
542 Check name, guid and version.
543 If all of them are valid, save information to new id
545 @retval true All name, guid and version are valid
546 @retval false Any one of name, guid and version is invalid
549 private boolean checkId() {
553 if (isEmpty(this.jTextFieldBaseName
.getText())) {
554 Log
.wrn("Clone", "The Name is required!");
557 if (!DataValidation
.isBaseName(this.jTextFieldBaseName
.getText())) {
558 Log
.wrn("Clone", "<html>Incorrect data type for the Name, it must<br>be a single word, starting with an alpha character.</html>");
565 if (isEmpty(this.jTextFieldGuid
.getText())) {
566 Log
.wrn("Clone", "A Guid is required!!");
569 if (!DataValidation
.isGuid(this.jTextFieldGuid
.getText())) {
570 Log
.wrn("Clone", "<html>Incorrect data type for Guid, which must<br>be in registry format (8-4-4-4-12) for example:<br>d3adb123-eef1-466d-39ac-02febcaf5997</html>");
577 if (isEmpty(this.jTextFieldVersion
.getText())) {
578 Log
.wrn("Clone", "A Version must be entered!");
581 if (!DataValidation
.isVersion(this.jTextFieldVersion
.getText())) {
582 Log
.wrn("Clone", "<html>Incorrect data type for Version, which must<br>be one or more digits, optionally followed by sequence<br>of one or more dot, one or more digits; examples:<br>1.0 1.0.1 12.25.256</html>");
587 // Save information to id
589 newId
.setName(this.jTextFieldBaseName
.getText());
590 newId
.setGuid(this.jTextFieldGuid
.getText());
591 newId
.setVersion(this.jTextFieldVersion
.getText());
592 newId
.setPath(this.jTextFieldFilePath
.getText());
600 @retval true All check points are passed
601 @retval false Any one of check points is failed
604 private boolean check() {
605 String src
= this.oldId
.getPath();
606 String trg
= this.jTextFieldFilePath
.getText();
607 File srcFile
= new File(src
);
608 File trgFile
= new File(trg
);
613 if (!srcFile
.exists()) {
614 Log
.wrn("Clone", "The source file does not exist!");
618 Log
.wrn("Clone", "The destination file path must be entered!");
621 if (src
.equals(trg
)) {
622 Log
.wrn("Clone", "The source and destination can not be same!");
625 if (trgFile
.exists()) {
626 Log
.wrn("Clone", "The destination already exists!");
631 // Check for workspace
633 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
634 if (trg
.indexOf(src
+ DataType
.FILE_SEPARATOR
) == 0) {
635 Log
.wrn("Clone", "The new workspace can not be located within the current workspace!");
643 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
644 trg
= this.getModulePath();
645 if (src
.equals(trg
)) {
646 Log
.wrn("Clone", "The source and destination paths for cloning a module must be different!");
649 trgFile
= new File(trg
);
650 if (trgFile
.exists()) {
651 Log
.wrn("Clone", "The target module already exists!");
660 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
661 if (trg
.indexOf(DataType
.DOS_FILE_SEPARATOR
) == -1 && trg
.indexOf(DataType
.UNIX_FILE_SEPARATOR
) == -1) {
662 Log
.wrn("Clone", "The package name must include a path!");
665 trg
= this.getPackagePath();
666 if (Tools
.getFilePathOnly(src
).equals(Tools
.getFilePathOnly(trg
))) {
667 Log
.wrn("Clone", "The source and destination paths for cloning a package must be different!");
670 trgFile
= new File(trg
);
671 if (trgFile
.exists()) {
672 Log
.wrn("Clone", "The target package already exists!");
679 // Check for Platform
681 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
682 if (trg
.indexOf(Workspace
.getCurrentWorkspace()) != 0) {
683 Log
.wrn("Clone", "The platform clone must be located in the current workspace!");
686 trgFile
= new File(trg
);
687 if (trgFile
.exists()) {
688 Log
.wrn("Clone", "The target platform already exists.");
698 Save clone target to new location
705 private void save() throws IOException
, XmlException
, Exception
{
706 String src
= this.oldId
.getPath();
707 String trg
= this.jTextFieldFilePath
.getText();
708 Vector
<String
> vFiles
= new Vector
<String
>();
713 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
714 FileOperation
.copyFolder(src
, trg
);
715 this.returnType
= DataType
.RETURN_TYPE_WORKSPACE
;
719 // Clone Module Surface Area
721 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
723 // Get target path from source path
725 trg
= getModulePath();
727 vFiles
= wt
.getAllFilesPathOfModule(src
);
730 // First copy all files to new directory
732 FileOperation
.copyFile(src
, trg
);
733 for (int index
= 1; index
< vFiles
.size(); index
++) {
734 String oldFile
= vFiles
.get(index
);
735 String newFile
= vFiles
.get(index
).replace(Tools
.getFilePathOnly(src
), Tools
.getFilePathOnly(trg
));
736 FileOperation
.copyFile(oldFile
, newFile
);
740 // Create new msa file
742 ModuleSurfaceArea msa
= null;
743 msa
= OpenFile
.openMsaFile(src
);
748 msa
.getMsaHeader().setModuleName(newId
.getName());
749 msa
.getMsaHeader().setGuidValue(newId
.getGuid());
750 msa
.getMsaHeader().setVersion(newId
.getVersion());
753 // Update <Cloned> Section
755 updateModuleClonedId(msa
, oldId
);
760 SaveFile
.saveMsaFile(trg
, msa
);
763 // Update to platformId
765 this.setMid(new ModuleIdentification(newId
,
766 packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())));
769 // Open belonging package
771 PackageSurfaceArea psa
= PackageSurfaceArea
.Factory
.newInstance();
772 psa
= OpenFile
.openSpdFile(mid
.getPackageId().getPath());
775 // Update the db file
777 wt
.addModuleToPackage(mid
, psa
);
782 GlobalData
.vModuleList
.addElement(mid
);
783 GlobalData
.openingModuleList
.insertToOpeningModuleList(mid
, msa
);
785 this.returnType
= DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
;
789 // Clone Package Surface Area
791 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
793 // Get target path from source path
795 trg
= this.getPackagePath();
797 vFiles
= wt
.getAllFilesPathOfPakcage(src
);
800 // First copy all files to new directory
802 FileOperation
.copyFile(src
, trg
);
803 for (int index
= 1; index
< vFiles
.size(); index
++) {
804 String oldFile
= vFiles
.get(index
);
805 String newFile
= vFiles
.get(index
).replace(Tools
.getFilePathOnly(src
), Tools
.getFilePathOnly(trg
));
806 FileOperation
.copyFile(oldFile
, newFile
);
810 // Create new spd file
812 PackageSurfaceArea spd
= null;
813 spd
= OpenFile
.openSpdFile(src
);
818 spd
.getSpdHeader().setPackageName(newId
.getName());
819 spd
.getSpdHeader().setGuidValue(newId
.getGuid());
820 spd
.getSpdHeader().setVersion(newId
.getVersion());
823 // Update <Cloned> Section
825 updatePackageClonedId(spd
, oldId
);
830 SaveFile
.saveSpdFile(trg
, spd
);
833 // Update to platformId
835 this.setPid(new PackageIdentification(newId
));
838 // Update the db file
840 wt
.addPackageToDatabase(pid
);
845 GlobalData
.vPackageList
.addElement(pid
);
846 GlobalData
.openingPackageList
.insertToOpeningPackageList(pid
, spd
);
849 // Add all cloned modules
851 Vector
<String
> modulePaths
= GlobalData
.getAllModulesOfPackage(pid
.getPath());
852 String modulePath
= null;
853 ModuleSurfaceArea msa
= null;
855 for (int indexJ
= 0; indexJ
< modulePaths
.size(); indexJ
++) {
857 modulePath
= modulePaths
.get(indexJ
);
858 msa
= OpenFile
.openMsaFile(modulePath
);
859 } catch (IOException e
) {
860 Log
.err("Open Module Surface Area " + modulePath
, e
.getMessage());
862 } catch (XmlException e
) {
863 Log
.err("Open Module Surface Area " + modulePath
, e
.getMessage());
865 } catch (Exception e
) {
866 Log
.err("Open Module Surface Area " + modulePath
, "Invalid file type");
869 Identification id
= Tools
.getId(modulePath
, msa
);
870 mid
= new ModuleIdentification(id
, pid
);
871 GlobalData
.vModuleList
.addElement(mid
);
872 GlobalData
.openingModuleList
.insertToOpeningModuleList(mid
, msa
);
875 this.returnType
= DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
;
879 // Clone Platform Surface Area
881 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
882 PlatformSurfaceArea fpd
= null;
883 fpd
= OpenFile
.openFpdFile(src
);
888 fpd
.getPlatformHeader().setPlatformName(newId
.getName());
889 fpd
.getPlatformHeader().setGuidValue(newId
.getGuid());
890 fpd
.getPlatformHeader().setVersion(newId
.getVersion());
893 // Update Cloned From element
895 updatePlatformClonedId(fpd
, oldId
);
900 SaveFile
.saveFpdFile(trg
, fpd
);
903 // Update to platformId
905 this.setFid(new PlatformIdentification(newId
));
908 // Update the db file
910 wt
.addPlatformToDatabase(fid
);
915 GlobalData
.vPlatformList
.addElement(fid
);
916 GlobalData
.openingPlatformList
.insertToOpeningPlatformList(fid
, fpd
);
918 this.returnType
= DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
;
924 Get the path of selected package
926 @return String The path of selected package
929 private String
getSelectPackagePath() {
930 return Tools
.getFilePathOnly(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()).getPath());
934 Get the path of source module
935 Since the path of source module is relative, make it up to full path.
937 @return String The full path of source module
940 private String
getModulePath() {
941 String trg
= this.jTextFieldFilePath
.getText();
942 trg
= Tools
.addPathExt(trg
, mode
);
943 trg
= Tools
.addFileSeparator(getSelectPackagePath()) + trg
;
944 Tools
.convertPathToCurrentOsType(trg
);
949 Get the path of source package
950 Since the path of source package is relative, make it up to full path.
952 @return String The full path of source package
955 private String
getPackagePath() {
956 String trg
= this.jTextFieldFilePath
.getText();
957 trg
= Tools
.addPathExt(trg
, mode
);
958 trg
= Tools
.addFileSeparator(Workspace
.getCurrentWorkspace()) + trg
;
959 trg
= Tools
.convertPathToCurrentOsType(trg
);
964 Set msa file's <Cloned> section via given identification
966 @param msa ModuleSurfaceArea for clone target
967 @param id Identification of clone source
970 private void updateModuleClonedId(ModuleSurfaceArea msa
, Identification id
) {
972 // Get PlatformDefinitions First
974 ModuleDefinitions pd
= null;
975 if (msa
.getModuleDefinitions() == null) {
976 pd
= ModuleDefinitions
.Factory
.newInstance();
977 msa
.addNewModuleDefinitions();
979 pd
= msa
.getModuleDefinitions();
983 // Get ClonedFrom then
985 ModuleDefinitions
.ClonedFrom cf
= null;
986 BigInteger count
= new BigInteger("-1");
987 if (pd
.getClonedFrom() == null) {
988 cf
= ModuleDefinitions
.ClonedFrom
.Factory
.newInstance();
990 cf
= pd
.getClonedFrom();
992 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
993 if (cf
.getClonedList().get(index
).getId() != null) {
994 count
= count
.max(cf
.getClonedList().get(index
).getId());
1001 // Set new Cloned item
1003 ModuleDefinitions
.ClonedFrom
.Cloned c
= ModuleDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
1004 c
.setModuleGuid(id
.getGuid());
1005 c
.setModuleVersion(id
.getVersion());
1006 c
.setPackageGuid(wt
.getPackageIdByModuleId(oldId
).getGuid());
1007 c
.setPackageVersion(wt
.getPackageIdByModuleId(oldId
).getVersion());
1008 c
.setId(count
.add(new BigInteger("1")));
1009 String guid
= wt
.getModuleFarGuid(oldId
);
1010 if (guid
!= null && !guid
.equals("")) {
1015 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
1016 pd
.addNewClonedFrom();
1017 pd
.setClonedFrom(cf
);
1018 msa
.setModuleDefinitions(pd
);
1022 Set spd file's <Cloned> section via given identification
1024 @param spd PackageSurfaceArea for clone target
1025 @param id Identification of clone source
1028 private void updatePackageClonedId(PackageSurfaceArea spd
, Identification id
) {
1030 // Get PlatformDefinitions First
1032 PackageDefinitions pd
= null;
1033 if (spd
.getPackageDefinitions() == null) {
1034 pd
= PackageDefinitions
.Factory
.newInstance();
1035 spd
.addNewPackageDefinitions();
1037 pd
= spd
.getPackageDefinitions();
1041 // Get ClonedFrom then
1043 PackageDefinitions
.ClonedFrom cf
= null;
1044 BigInteger count
= new BigInteger("-1");
1045 if (pd
.getClonedFrom() == null) {
1046 cf
= PackageDefinitions
.ClonedFrom
.Factory
.newInstance();
1048 cf
= pd
.getClonedFrom();
1050 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
1051 if (cf
.getClonedList().get(index
).getId() != null) {
1052 count
= count
.max(cf
.getClonedList().get(index
).getId());
1059 // Set new Cloned item
1061 PackageDefinitions
.ClonedFrom
.Cloned c
= PackageDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
1062 c
.setPackageGuid(id
.getGuid());
1063 c
.setPackageVersion(id
.getVersion());
1064 c
.setId(count
.add(new BigInteger("1")));
1065 String guid
= wt
.getPackageFarGuid(oldId
);
1066 if (guid
!= null && !guid
.equals("")) {
1071 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
1072 pd
.addNewClonedFrom();
1073 pd
.setClonedFrom(cf
);
1074 spd
.setPackageDefinitions(pd
);
1078 Set fpd file's <Cloned> section via given identification
1080 @param fpd PlatformSurfaceArea for clone target
1081 @param id Identification of clone source
1084 private void updatePlatformClonedId(PlatformSurfaceArea fpd
, Identification id
) {
1086 // Get PlatformDefinitions First
1088 PlatformDefinitions pd
= null;
1089 if (fpd
.getPlatformDefinitions() == null) {
1090 pd
= PlatformDefinitions
.Factory
.newInstance();
1091 fpd
.addNewPlatformDefinitions();
1093 pd
= fpd
.getPlatformDefinitions();
1097 // Get ClonedFrom then
1099 PlatformDefinitions
.ClonedFrom cf
= null;
1100 BigInteger count
= new BigInteger("-1");
1101 if (pd
.getClonedFrom() == null) {
1102 cf
= PlatformDefinitions
.ClonedFrom
.Factory
.newInstance();
1104 cf
= pd
.getClonedFrom();
1106 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
1107 if (cf
.getClonedList().get(index
).getId() != null) {
1108 count
= count
.max(cf
.getClonedList().get(index
).getId());
1115 // Set new Cloned item
1117 PlatformDefinitions
.ClonedFrom
.Cloned c
= PlatformDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
1118 c
.setPlatformGuid(id
.getGuid());
1119 c
.setPlatformVersion(id
.getVersion());
1120 c
.setId(count
.add(new BigInteger("1")));
1121 String guid
= wt
.getPlatformFarGuid(oldId
);
1122 if (guid
!= null && !guid
.equals("")) {
1127 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
1128 pd
.addNewClonedFrom();
1129 pd
.setClonedFrom(cf
);
1130 fpd
.setPlatformDefinitions(pd
);
1134 Get PlatformIdentification
1136 @return PlatformIdentification
1139 public PlatformIdentification
getFid() {
1144 Set PlatformIdentification
1146 @param fid PlatformIdentification
1149 public void setFid(PlatformIdentification fid
) {
1154 Get ModuleIdentification
1156 @return ModuleIdentification
1159 public ModuleIdentification
getMid() {
1164 Set ModuleIdentification
1166 @param mid ModuleIdentification
1169 public void setMid(ModuleIdentification mid
) {
1174 Get PackageIdentification
1176 @return PackageIdentification
1179 public PackageIdentification
getPid() {
1184 Set PackageIdentification
1186 @param pid PackageIdentification
1189 public void setPid(PackageIdentification pid
) {