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
.IFileFilter
;
40 import org
.tianocore
.frameworkwizard
.common
.Log
;
41 import org
.tianocore
.frameworkwizard
.common
.OpenFile
;
42 import org
.tianocore
.frameworkwizard
.common
.SaveFile
;
43 import org
.tianocore
.frameworkwizard
.common
.Tools
;
44 import org
.tianocore
.frameworkwizard
.common
.Identifications
.Identification
;
45 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
46 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
47 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
48 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
49 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
50 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
51 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
52 import javax
.swing
.JComboBox
;
55 The class is used to provide functions to clone workspace, module, package and platform
59 public class Clone
extends IDialog
{
62 /// Define Class Serial Version UID
64 private static final long serialVersionUID
= -5469299324965727137L;
67 /// Define Class Members
69 private JPanel jContentPane
= null;
71 private JLabel jLabelType
= null;
73 private JTextField jTextFieldType
= null;
75 private JLabel jLabelSource
= null;
77 private JTextField jTextFieldSource
= null;
79 private JButton jButtonBrowse
= null;
81 private JLabel jLabelDestinationFile
= null;
83 private JTextField jTextFieldFilePath
= null;
85 private JLabel jLabelBaseName
= null;
87 private JTextField jTextFieldBaseName
= null;
89 private JLabel jLabelGuid
= null;
91 private JTextField jTextFieldGuid
= null;
93 private JLabel jLabelVersion
= null;
95 private JTextField jTextFieldVersion
= null;
97 private JButton jButtonOk
= null;
99 private JButton jButtonCancel
= null;
101 private JButton jButtonGenerateGuid
= null;
103 private JLabel jLabelBelong
= null;
105 private JComboBox jComboBoxExistingPackage
= null;
108 /// Define members not for UI
111 private int mode
= -1;
113 private Vector
<PackageIdentification
> packages
= null;
115 private WorkspaceTools wt
= new WorkspaceTools();
117 private Identification oldId
= null;
119 private Identification newId
= null;
121 private ModuleIdentification mid
= null;
123 private PackageIdentification pid
= null;
125 private PlatformIdentification fid
= null;
128 This method initializes jTextFieldType
130 @return javax.swing.JTextField
133 private JTextField
getJTextFieldType() {
134 if (jTextFieldType
== null) {
135 jTextFieldType
= new JTextField();
136 jTextFieldType
.setBounds(new java
.awt
.Rectangle(210, 10, 320, 20));
137 jTextFieldType
.setEditable(false);
139 return jTextFieldType
;
143 This method initializes jTextFieldSource
145 @return javax.swing.JTextField
148 private JTextField
getJTextFieldSource() {
149 if (jTextFieldSource
== null) {
150 jTextFieldSource
= new JTextField();
151 jTextFieldSource
.setBounds(new java
.awt
.Rectangle(210, 35, 320, 20));
152 jTextFieldSource
.setEditable(false);
154 return jTextFieldSource
;
158 This method initializes jButtonBrowse
160 @return javax.swing.JButton
163 private JButton
getJButtonBrowse() {
164 if (jButtonBrowse
== null) {
165 jButtonBrowse
= new JButton();
166 jButtonBrowse
.setBounds(new java
.awt
.Rectangle(445, 85, 85, 20));
167 jButtonBrowse
.setText("Browse");
168 jButtonBrowse
.addActionListener(this);
170 return jButtonBrowse
;
174 This method initializes jTextFieldDestinationFile
176 @return javax.swing.JTextField
179 private JTextField
getJTextFieldFilePath() {
180 if (jTextFieldFilePath
== null) {
181 jTextFieldFilePath
= new JTextField();
182 jTextFieldFilePath
.setBounds(new java
.awt
.Rectangle(210, 85, 230, 20));
184 return jTextFieldFilePath
;
188 This method initializes jTextFieldBaseName
190 @return javax.swing.JTextField
193 private JTextField
getJTextFieldBaseName() {
194 if (jTextFieldBaseName
== null) {
195 jTextFieldBaseName
= new JTextField();
196 jTextFieldBaseName
.setBounds(new java
.awt
.Rectangle(210, 110, 320, 20));
198 return jTextFieldBaseName
;
202 This method initializes jTextFieldGuid
204 @return javax.swing.JTextField
207 private JTextField
getJTextFieldGuid() {
208 if (jTextFieldGuid
== null) {
209 jTextFieldGuid
= new JTextField();
210 jTextFieldGuid
.setBounds(new java
.awt
.Rectangle(210, 135, 230, 20));
212 return jTextFieldGuid
;
216 This method initializes jTextFieldVersion
218 @return javax.swing.JTextField
221 private JTextField
getJTextFieldVersion() {
222 if (jTextFieldVersion
== null) {
223 jTextFieldVersion
= new JTextField();
224 jTextFieldVersion
.setBounds(new java
.awt
.Rectangle(210, 160, 320, 20));
226 return jTextFieldVersion
;
230 This method initializes jButtonOk
232 @return javax.swing.JButton
235 private JButton
getJButtonOk() {
236 if (jButtonOk
== null) {
237 jButtonOk
= new JButton();
238 jButtonOk
.setBounds(new java
.awt
.Rectangle(285, 200, 90, 20));
239 jButtonOk
.setText("Ok");
240 jButtonOk
.addActionListener(this);
246 This method initializes jButtonCancel
248 @return javax.swing.JButton
251 private JButton
getJButtonCancel() {
252 if (jButtonCancel
== null) {
253 jButtonCancel
= new JButton();
254 jButtonCancel
.setBounds(new java
.awt
.Rectangle(405, 200, 90, 20));
255 jButtonCancel
.setText("Cancel");
256 jButtonCancel
.addActionListener(this);
258 return jButtonCancel
;
262 This method initializes jButtonGenerateGuid
264 @return javax.swing.JButton
267 private JButton
getJButtonGenerateGuid() {
268 if (jButtonGenerateGuid
== null) {
269 jButtonGenerateGuid
= new JButton();
270 jButtonGenerateGuid
.setBounds(new java
.awt
.Rectangle(445, 135, 85, 20));
271 jButtonGenerateGuid
.setText("Gen");
272 jButtonGenerateGuid
.addActionListener(this);
274 return jButtonGenerateGuid
;
278 This method initializes jComboBoxExistingPackage
280 @return javax.swing.JComboBox
283 private JComboBox
getJComboBoxExistingPackage() {
284 if (jComboBoxExistingPackage
== null) {
285 jComboBoxExistingPackage
= new JComboBox();
286 jComboBoxExistingPackage
.setBounds(new java
.awt
.Rectangle(210, 60, 320, 20));
288 return jComboBoxExistingPackage
;
292 This is the default constructor
301 This is the override constructor
303 @param parentFrame The parent frame which starts this frame
304 @param modal To identify the frame's modal
305 @param fileType To identify the clone target type
306 @param identification The clone target's identification
309 public Clone(IFrame parentFrame
, boolean modal
, int fileType
, Identification identification
) {
310 super(parentFrame
, modal
);
311 this.mode
= fileType
;
312 if (identification
!= null) {
313 this.oldId
= new Identification(identification
.getName(), identification
.getGuid(),
314 identification
.getVersion(), identification
.getPath());
315 this.newId
= new Identification(identification
.getName(), identification
.getGuid(),
316 identification
.getVersion(), identification
.getPath());
322 Query all existing packages and fill them into combox
325 private void initExistingPackage() {
326 packages
= wt
.getAllPackages();
327 for (int index
= 0; index
< packages
.size(); index
++) {
328 this.jComboBoxExistingPackage
.addItem(packages
.elementAt(index
).getName());
333 This method initializes this
336 private void init() {
337 this.setSize(550, 260);
338 this.setContentPane(getJContentPane());
339 this.setTitle("Clone");
344 This method initializes this with given clone target type.
345 Customize the frame interface via different clone target type.
347 @param mode To identify the clone target type
350 private void init(int mode
) {
353 // For MODULE_SURFACE_AREA
355 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
356 this.jTextFieldType
.setText(DataType
.MODULE_SURFACE_AREA
);
357 String s
= oldId
.getPath();
358 s
= Tools
.getRelativePath(s
, Tools
.getFilePathOnly(wt
.getPackageIdByModuleId(oldId
).getPath()));
359 this.jTextFieldSource
.setText(Tools
.convertPathToCurrentOsType(s
));
360 initExistingPackage();
361 this.jButtonBrowse
.setVisible(false);
362 this.jTextFieldFilePath
363 .setToolTipText("Input module name here. For example, Application\\HelloWorld\\HelloWorld.msa");
364 this.jTextFieldFilePath
.setSize(320, this.jTextFieldFilePath
.getSize().height
);
365 this.jLabelDestinationFile
.setText("New Module Path and Filename");
368 // For PACKAGE_SURFACE_AREA
370 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
371 this.jTextFieldType
.setText(DataType
.PACKAGE_SURFACE_AREA
);
372 String s
= oldId
.getPath();
373 s
= Tools
.getRelativePath(oldId
.getPath(), Workspace
.getCurrentWorkspace());
374 this.jTextFieldSource
.setText(Tools
.convertPathToCurrentOsType(s
));
375 this.jLabelBelong
.setEnabled(false);
376 this.jComboBoxExistingPackage
.setEnabled(false);
377 this.jButtonBrowse
.setVisible(false);
378 this.jTextFieldFilePath
.setToolTipText("Input package name here. For example, MdePkg\\MdePkg.fpd");
379 this.jTextFieldFilePath
.setSize(320, this.jTextFieldFilePath
.getSize().height
);
380 this.jLabelDestinationFile
.setText("New Package Path and Filename");
383 // For PLATFORM_SURFACE_AREA
385 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
386 this.jTextFieldType
.setText(DataType
.PLATFORM_SURFACE_AREA
);
387 this.jTextFieldSource
.setText(oldId
.getPath());
388 this.jLabelBelong
.setEnabled(false);
389 this.jComboBoxExistingPackage
.setEnabled(false);
390 this.jTextFieldFilePath
391 .setToolTipText("Select platform path here. For example, C:\\MyWorkspace\\EdkNt32Pkg\\Nt32.fpd");
392 this.jLabelDestinationFile
.setText("New Platform Path and Filename");
397 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
398 this.jTextFieldType
.setText(DataType
.WORKSPACE
);
399 this.jTextFieldSource
.setText(Workspace
.getCurrentWorkspace());
400 this.jLabelBelong
.setEnabled(false);
401 this.jComboBoxExistingPackage
.setEnabled(false);
402 this.jLabelBaseName
.setEnabled(false);
403 this.jTextFieldBaseName
.setEditable(false);
404 this.jLabelGuid
.setEnabled(false);
405 this.jTextFieldGuid
.setEnabled(false);
406 this.jButtonGenerateGuid
.setEnabled(false);
407 this.jLabelVersion
.setEnabled(false);
408 this.jTextFieldVersion
.setEnabled(false);
409 this.jTextFieldFilePath
.setToolTipText("Input workspace path here. For example, C:\\MyWorkspace");
410 this.jLabelDestinationFile
.setText("New Workspace Path");
415 This method initializes jContentPane
417 @return javax.swing.JPanel
420 private JPanel
getJContentPane() {
421 if (jContentPane
== null) {
422 jLabelBelong
= new JLabel();
423 jLabelBelong
.setBounds(new java
.awt
.Rectangle(15, 60, 190, 20));
424 jLabelBelong
.setText("Clone to Package");
425 jLabelVersion
= new JLabel();
426 jLabelVersion
.setBounds(new java
.awt
.Rectangle(15, 160, 190, 20));
427 jLabelVersion
.setText("Version");
428 jLabelGuid
= new JLabel();
429 jLabelGuid
.setBounds(new java
.awt
.Rectangle(15, 135, 190, 20));
430 jLabelGuid
.setText("Guid");
431 jLabelBaseName
= new JLabel();
432 jLabelBaseName
.setBounds(new java
.awt
.Rectangle(15, 110, 190, 20));
433 jLabelBaseName
.setText("Base Name");
434 jLabelDestinationFile
= new JLabel();
435 jLabelDestinationFile
.setBounds(new java
.awt
.Rectangle(15, 85, 190, 20));
436 jLabelDestinationFile
.setText("Destination File Name");
437 jLabelSource
= new JLabel();
438 jLabelSource
.setBounds(new java
.awt
.Rectangle(15, 35, 190, 20));
439 jLabelSource
.setText("Source");
440 jLabelType
= new JLabel();
441 jLabelType
.setBounds(new java
.awt
.Rectangle(15, 10, 190, 20));
442 jLabelType
.setText("Type");
443 jContentPane
= new JPanel();
444 jContentPane
.setLayout(null);
445 jContentPane
.setSize(new java
.awt
.Dimension(540, 227));
446 jContentPane
.add(jLabelType
, null);
447 jContentPane
.add(getJTextFieldType(), null);
448 jContentPane
.add(jLabelSource
, null);
449 jContentPane
.add(getJTextFieldSource(), null);
450 jContentPane
.add(jLabelDestinationFile
, null);
451 jContentPane
.add(getJTextFieldFilePath(), null);
452 jContentPane
.add(jLabelBaseName
, null);
453 jContentPane
.add(getJTextFieldBaseName(), null);
454 jContentPane
.add(jLabelGuid
, null);
455 jContentPane
.add(getJTextFieldGuid(), null);
456 jContentPane
.add(jLabelVersion
, null);
457 jContentPane
.add(getJTextFieldVersion(), null);
458 jContentPane
.add(getJButtonOk(), null);
459 jContentPane
.add(getJButtonCancel(), null);
460 jContentPane
.add(getJButtonBrowse(), null);
461 jContentPane
.add(getJButtonGenerateGuid(), null);
462 jContentPane
.add(jLabelBelong
, null);
463 jContentPane
.add(getJComboBoxExistingPackage(), null);
469 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
471 * Override actionPerformed to listen all actions
473 public void actionPerformed(ActionEvent arg0
) {
474 if (arg0
.getSource() == jButtonCancel
) {
475 this.setVisible(false);
476 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
479 if (arg0
.getSource() == jButtonOk
) {
486 } catch (IOException e
) {
487 Log
.wrn("Clone", e
.getMessage());
488 Log
.err("Clone", e
.getMessage());
490 } catch (XmlException e
) {
491 Log
.wrn("Clone", e
.getMessage());
492 Log
.err("Clone", e
.getMessage());
494 } catch (Exception e
) {
495 Log
.wrn("Clone", e
.getMessage());
496 Log
.err("Clone", e
.getMessage());
502 this.setVisible(false);
505 if (arg0
.getSource() == this.jButtonGenerateGuid
) {
506 this.jTextFieldGuid
.setText(Tools
.generateUuidString());
510 // Use different file ext for different clone target type
512 if (arg0
.getSource() == this.jButtonBrowse
) {
513 JFileChooser fc
= new JFileChooser();
514 fc
.setAcceptAllFileFilterUsed(false);
516 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
517 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
518 fc
.setFileSelectionMode(JFileChooser
.DIRECTORIES_ONLY
);
520 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
521 fc
.setCurrentDirectory(new File(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())
523 fc
.addChoosableFileFilter(new IFileFilter(DataType
.MODULE_SURFACE_AREA_EXT
));
525 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
526 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
527 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PACKAGE_SURFACE_AREA_EXT
));
529 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
530 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
531 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PLATFORM_SURFACE_AREA_EXT
));
533 int result
= fc
.showSaveDialog(new JPanel());
534 if (result
== JFileChooser
.APPROVE_OPTION
) {
535 this.jTextFieldFilePath
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(), mode
));
541 Check name, guid and version.
542 If all of them are valid, save information to new id
544 @retval true All name, guid and version are valid
545 @retval false Any one of name, guid and version is invalid
548 private boolean checkId() {
552 if (isEmpty(this.jTextFieldBaseName
.getText())) {
553 Log
.wrn("Clone", "Base Name couldn't be empty!");
556 if (!DataValidation
.isBaseName(this.jTextFieldBaseName
.getText())) {
557 Log
.wrn("Clone", "Incorrect data type for Base Name");
564 if (isEmpty(this.jTextFieldGuid
.getText())) {
565 Log
.wrn("Clone", "Guid couldn't be empty!");
568 if (!DataValidation
.isGuid(this.jTextFieldGuid
.getText())) {
569 Log
.wrn("Clone", "Incorrect data type for Guid");
576 if (isEmpty(this.jTextFieldVersion
.getText())) {
577 Log
.wrn("Clone", "Version couldn't be empty!");
580 if (!DataValidation
.isVersion(this.jTextFieldVersion
.getText())) {
581 Log
.wrn("Clone", "Incorrect data type for Version");
586 // Save information to id
588 newId
.setName(this.jTextFieldBaseName
.getText());
589 newId
.setGuid(this.jTextFieldGuid
.getText());
590 newId
.setVersion(this.jTextFieldVersion
.getText());
591 newId
.setPath(this.jTextFieldFilePath
.getText());
599 @retval true All check points are passed
600 @retval false Any one of check points is failed
603 private boolean check() {
604 String src
= this.oldId
.getPath();
605 String trg
= this.jTextFieldFilePath
.getText();
606 File srcFile
= new File(src
);
607 File trgFile
= new File(trg
);
612 if (!srcFile
.exists()) {
613 Log
.wrn("Clone", "The source doesn't exist");
617 Log
.wrn("Clone", "The destination file path couldn't be empty");
620 if (src
.equals(trg
)) {
621 Log
.wrn("Clone", "The source and destination couldn't be same");
624 if (trgFile
.exists()) {
625 Log
.wrn("Clone", "The destination already exists");
630 // Check for workspace
632 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
633 if (trg
.indexOf(src
+ DataType
.FILE_SEPARATOR
) == 0) {
634 Log
.wrn("Clone", "The new workspace couldn't be in current workspace!");
642 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
643 trg
= this.getModulePath();
644 if (src
.equals(trg
)) {
645 Log
.wrn("Clone", "The source and destination couldn't be same");
648 trgFile
= new File(trg
);
649 if (trgFile
.exists()) {
650 Log
.wrn("Clone", "The target module already exists");
659 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
660 if (trg
.indexOf(DataType
.DOS_FILE_SEPARATOR
) == -1 && trg
.indexOf(DataType
.UNIX_FILE_SEPARATOR
) == -1) {
661 Log
.wrn("Clone", "The package name must include a path");
664 trg
= this.getPackagePath();
665 if (Tools
.getFilePathOnly(src
).equals(Tools
.getFilePathOnly(trg
))) {
666 Log
.wrn("Clone", "The source and destination couldn't be same");
669 trgFile
= new File(trg
);
670 if (trgFile
.exists()) {
671 Log
.wrn("Clone", "The target package already exists");
678 // Check for Platform
680 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
681 if (trg
.indexOf(Workspace
.getCurrentWorkspace()) != 0) {
682 Log
.wrn("Clone", "The target platform must be in current workspace");
685 trgFile
= new File(trg
);
686 if (trgFile
.exists()) {
687 Log
.wrn("Clone", "The target platform already exists");
697 Save clone target to new location
704 private void save() throws IOException
, XmlException
, Exception
{
705 String src
= this.oldId
.getPath();
706 String trg
= this.jTextFieldFilePath
.getText();
707 Vector
<String
> vFiles
= new Vector
<String
>();
712 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
713 FileOperation
.copyFolder(src
, trg
);
714 this.returnType
= DataType
.RETURN_TYPE_WORKSPACE
;
718 // Clone Module Surface Area
720 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
722 // Get target path from source path
724 trg
= getModulePath();
726 vFiles
= wt
.getAllModuleFilesPath(src
);
729 // First copy all files to new directory
731 FileOperation
.copyFile(src
, trg
);
732 for (int index
= 1; index
< vFiles
.size(); index
++) {
733 String oldFile
= vFiles
.get(index
);
734 String newFile
= vFiles
.get(index
).replace(Tools
.getFilePathOnly(src
), Tools
.getFilePathOnly(trg
));
735 FileOperation
.copyFile(oldFile
, newFile
);
739 // Create new msa file
741 ModuleSurfaceArea msa
= null;
742 msa
= OpenFile
.openMsaFile(src
);
747 msa
.getMsaHeader().setModuleName(newId
.getName());
748 msa
.getMsaHeader().setGuidValue(newId
.getGuid());
749 msa
.getMsaHeader().setVersion(newId
.getVersion());
752 // Update <Cloned> Section
754 updateModuleClonedId(msa
, oldId
);
759 SaveFile
.saveMsaFile(trg
, msa
);
762 // Update to platformId
764 this.setMid(new ModuleIdentification(newId
,
765 packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())));
768 // Open belonging package
770 PackageSurfaceArea psa
= PackageSurfaceArea
.Factory
.newInstance();
771 psa
= OpenFile
.openSpdFile(mid
.getPackageId().getPath());
774 // Update the db file
776 wt
.addModuleToPackage(mid
, psa
);
778 this.returnType
= DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
;
782 // Clone Package Surface Area
784 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
786 // Get target path from source path
788 trg
= this.getPackagePath();
790 vFiles
= wt
.getAllPakcageFilesPath(src
);
793 // First copy all files to new directory
795 FileOperation
.copyFile(src
, trg
);
796 for (int index
= 1; index
< vFiles
.size(); index
++) {
797 String oldFile
= vFiles
.get(index
);
798 String newFile
= vFiles
.get(index
).replace(Tools
.getFilePathOnly(src
), Tools
.getFilePathOnly(trg
));
799 FileOperation
.copyFile(oldFile
, newFile
);
803 // Create new spd file
805 PackageSurfaceArea spd
= null;
806 spd
= OpenFile
.openSpdFile(src
);
811 spd
.getSpdHeader().setPackageName(newId
.getName());
812 spd
.getSpdHeader().setGuidValue(newId
.getGuid());
813 spd
.getSpdHeader().setVersion(newId
.getVersion());
816 // Update <Cloned> Section
818 updatePackageClonedId(spd
, oldId
);
823 SaveFile
.saveSpdFile(trg
, spd
);
826 // Update to platformId
828 this.setPid(new PackageIdentification(newId
));
831 // Update the db file
833 wt
.addPackageToDatabase(pid
);
835 this.returnType
= DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
;
839 // Clone Platform Surface Area
841 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
842 PlatformSurfaceArea fpd
= null;
843 fpd
= OpenFile
.openFpdFile(src
);
848 fpd
.getPlatformHeader().setPlatformName(newId
.getName());
849 fpd
.getPlatformHeader().setGuidValue(newId
.getGuid());
850 fpd
.getPlatformHeader().setVersion(newId
.getVersion());
853 // Update Cloned From element
855 updatePlatformClonedId(fpd
, oldId
);
860 SaveFile
.saveFpdFile(trg
, fpd
);
863 // Update to platformId
865 this.setFid(new PlatformIdentification(newId
));
868 // Update the db file
870 wt
.addPlatformToDatabase(fid
);
872 this.returnType
= DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
;
878 Get the path of selected package
880 @return String The path of selected package
883 private String
getSelectPackagePath() {
884 return Tools
.getFilePathOnly(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()).getPath());
888 Get the path of source module
889 Since the path of source module is relative, make it up to full path.
891 @return String The full path of source module
894 private String
getModulePath() {
895 String trg
= this.jTextFieldFilePath
.getText();
896 trg
= Tools
.addPathExt(trg
, mode
);
897 trg
= Tools
.addFileSeparator(getSelectPackagePath()) + trg
;
898 Tools
.convertPathToCurrentOsType(trg
);
903 Get the path of source package
904 Since the path of source package is relative, make it up to full path.
906 @return String The full path of source package
909 private String
getPackagePath() {
910 String trg
= this.jTextFieldFilePath
.getText();
911 trg
= Tools
.addPathExt(trg
, mode
);
912 trg
= Tools
.addFileSeparator(Workspace
.getCurrentWorkspace()) + trg
;
913 trg
= Tools
.convertPathToCurrentOsType(trg
);
918 Set msa file's <Cloned> section via given identification
920 @param msa ModuleSurfaceArea for clone target
921 @param id Identification of clone source
924 private void updateModuleClonedId(ModuleSurfaceArea msa
, Identification id
) {
926 // Get PlatformDefinitions First
928 ModuleDefinitions pd
= null;
929 if (msa
.getModuleDefinitions() == null) {
930 pd
= ModuleDefinitions
.Factory
.newInstance();
931 msa
.addNewModuleDefinitions();
933 pd
= msa
.getModuleDefinitions();
937 // Get ClonedFrom then
939 ModuleDefinitions
.ClonedFrom cf
= null;
940 BigInteger count
= new BigInteger("-1");
941 if (pd
.getClonedFrom() == null) {
942 cf
= ModuleDefinitions
.ClonedFrom
.Factory
.newInstance();
944 cf
= pd
.getClonedFrom();
946 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
947 if (cf
.getClonedList().get(index
).getId() != null) {
948 count
= count
.max(cf
.getClonedList().get(index
).getId());
955 // Set new Cloned item
957 ModuleDefinitions
.ClonedFrom
.Cloned c
= ModuleDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
958 c
.setModuleGuid(id
.getGuid());
959 c
.setModuleVersion(id
.getVersion());
960 c
.setPackageGuid(wt
.getPackageIdByModuleId(oldId
).getGuid());
961 c
.setPackageVersion(wt
.getPackageIdByModuleId(oldId
).getVersion());
962 c
.setId(count
.add(new BigInteger("1")));
963 String guid
= wt
.getModuleFarGuid(oldId
);
964 if (guid
!= null && !guid
.equals("")) {
969 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
970 pd
.addNewClonedFrom();
971 pd
.setClonedFrom(cf
);
972 msa
.setModuleDefinitions(pd
);
976 Set spd file's <Cloned> section via given identification
978 @param spd PackageSurfaceArea for clone target
979 @param id Identification of clone source
982 private void updatePackageClonedId(PackageSurfaceArea spd
, Identification id
) {
984 // Get PlatformDefinitions First
986 PackageDefinitions pd
= null;
987 if (spd
.getPackageDefinitions() == null) {
988 pd
= PackageDefinitions
.Factory
.newInstance();
989 spd
.addNewPackageDefinitions();
991 pd
= spd
.getPackageDefinitions();
995 // Get ClonedFrom then
997 PackageDefinitions
.ClonedFrom cf
= null;
998 BigInteger count
= new BigInteger("-1");
999 if (pd
.getClonedFrom() == null) {
1000 cf
= PackageDefinitions
.ClonedFrom
.Factory
.newInstance();
1002 cf
= pd
.getClonedFrom();
1004 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
1005 if (cf
.getClonedList().get(index
).getId() != null) {
1006 count
= count
.max(cf
.getClonedList().get(index
).getId());
1013 // Set new Cloned item
1015 PackageDefinitions
.ClonedFrom
.Cloned c
= PackageDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
1016 c
.setPackageGuid(id
.getGuid());
1017 c
.setPackageVersion(id
.getVersion());
1018 c
.setId(count
.add(new BigInteger("1")));
1019 String guid
= wt
.getModuleFarGuid(oldId
);
1020 if (guid
!= null && !guid
.equals("")) {
1025 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
1026 pd
.addNewClonedFrom();
1027 pd
.setClonedFrom(cf
);
1028 spd
.setPackageDefinitions(pd
);
1032 Set fpd file's <Cloned> section via given identification
1034 @param fpd PlatformSurfaceArea for clone target
1035 @param id Identification of clone source
1038 private void updatePlatformClonedId(PlatformSurfaceArea fpd
, Identification id
) {
1040 // Get PlatformDefinitions First
1042 PlatformDefinitions pd
= null;
1043 if (fpd
.getPlatformDefinitions() == null) {
1044 pd
= PlatformDefinitions
.Factory
.newInstance();
1045 fpd
.addNewPlatformDefinitions();
1047 pd
= fpd
.getPlatformDefinitions();
1051 // Get ClonedFrom then
1053 PlatformDefinitions
.ClonedFrom cf
= null;
1054 BigInteger count
= new BigInteger("-1");
1055 if (pd
.getClonedFrom() == null) {
1056 cf
= PlatformDefinitions
.ClonedFrom
.Factory
.newInstance();
1058 cf
= pd
.getClonedFrom();
1060 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
1061 if (cf
.getClonedList().get(index
).getId() != null) {
1062 count
= count
.max(cf
.getClonedList().get(index
).getId());
1069 // Set new Cloned item
1071 PlatformDefinitions
.ClonedFrom
.Cloned c
= PlatformDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
1072 c
.setPlatformGuid(id
.getGuid());
1073 c
.setPlatformVersion(id
.getVersion());
1074 c
.setId(count
.add(new BigInteger("1")));
1075 String guid
= wt
.getModuleFarGuid(oldId
);
1076 if (guid
!= null && !guid
.equals("")) {
1081 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
1082 pd
.addNewClonedFrom();
1083 pd
.setClonedFrom(cf
);
1084 fpd
.setPlatformDefinitions(pd
);
1088 Get PlatformIdentification
1090 @return PlatformIdentification
1093 public PlatformIdentification
getFid() {
1098 Set PlatformIdentification
1100 @param fid PlatformIdentification
1103 public void setFid(PlatformIdentification fid
) {
1108 Get ModuleIdentification
1110 @return ModuleIdentification
1113 public ModuleIdentification
getMid() {
1118 Set ModuleIdentification
1120 @param mid ModuleIdentification
1123 public void setMid(ModuleIdentification mid
) {
1128 Get PackageIdentification
1130 @return PackageIdentification
1133 public PackageIdentification
getPid() {
1138 Set PackageIdentification
1140 @param pid PackageIdentification
1143 public void setPid(PackageIdentification pid
) {