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
.SaveFile
;
42 import org
.tianocore
.frameworkwizard
.common
.Tools
;
43 import org
.tianocore
.frameworkwizard
.common
.Identifications
.Identification
;
44 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpenFile
;
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
;
54 public class Clone
extends IDialog
{
60 private static final long serialVersionUID
= -5469299324965727137L;
62 private JPanel jContentPane
= null;
64 private JLabel jLabelType
= null;
66 private JTextField jTextFieldType
= null;
68 private JLabel jLabelSource
= null;
70 private JTextField jTextFieldSource
= null;
72 private JButton jButtonBrowse
= null;
74 private JLabel jLabelDestinationFile
= null;
76 private JTextField jTextFieldFilePath
= null;
78 private JLabel jLabelBaseName
= null;
80 private JTextField jTextFieldBaseName
= null;
82 private JLabel jLabelGuid
= null;
84 private JTextField jTextFieldGuid
= null;
86 private JLabel jLabelVersion
= null;
88 private JTextField jTextFieldVersion
= null;
90 private JButton jButtonOk
= null;
92 private JButton jButtonCancel
= null;
94 private JButton jButtonGenerateGuid
= null;
96 private int mode
= -1;
98 private Vector
<PackageIdentification
> packages
= null;
100 private WorkspaceTools wt
= new WorkspaceTools();
102 private JLabel jLabelBelong
= null;
104 private JComboBox jComboBoxExistingPackage
= null;
106 private Identification oldId
= null;
108 private Identification newId
= null;
110 private ModuleIdentification mid
= null;
112 private PackageIdentification pid
= null;
114 private PlatformIdentification fid
= null;
117 * This method initializes jTextFieldType
119 * @return javax.swing.JTextField
121 private JTextField
getJTextFieldType() {
122 if (jTextFieldType
== null) {
123 jTextFieldType
= new JTextField();
124 jTextFieldType
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
125 jTextFieldType
.setEditable(false);
127 return jTextFieldType
;
131 * This method initializes jTextFieldSource
133 * @return javax.swing.JTextField
135 private JTextField
getJTextFieldSource() {
136 if (jTextFieldSource
== null) {
137 jTextFieldSource
= new JTextField();
138 jTextFieldSource
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
139 jTextFieldSource
.setEditable(false);
141 return jTextFieldSource
;
145 * This method initializes jButtonBrowse
147 * @return javax.swing.JButton
149 private JButton
getJButtonBrowse() {
150 if (jButtonBrowse
== null) {
151 jButtonBrowse
= new JButton();
152 jButtonBrowse
.setBounds(new java
.awt
.Rectangle(395, 60, 85, 20));
153 jButtonBrowse
.setText("Browse");
154 jButtonBrowse
.addActionListener(this);
156 return jButtonBrowse
;
160 * This method initializes jTextFieldDestinationFile
162 * @return javax.swing.JTextField
164 private JTextField
getJTextFieldFilePath() {
165 if (jTextFieldFilePath
== null) {
166 jTextFieldFilePath
= new JTextField();
167 jTextFieldFilePath
.setBounds(new java
.awt
.Rectangle(160, 60, 230, 20));
169 return jTextFieldFilePath
;
173 * This method initializes jTextFieldBaseName
175 * @return javax.swing.JTextField
177 private JTextField
getJTextFieldBaseName() {
178 if (jTextFieldBaseName
== null) {
179 jTextFieldBaseName
= new JTextField();
180 jTextFieldBaseName
.setBounds(new java
.awt
.Rectangle(160, 110, 320, 20));
182 return jTextFieldBaseName
;
186 * This method initializes jTextFieldGuid
188 * @return javax.swing.JTextField
190 private JTextField
getJTextFieldGuid() {
191 if (jTextFieldGuid
== null) {
192 jTextFieldGuid
= new JTextField();
193 jTextFieldGuid
.setBounds(new java
.awt
.Rectangle(160, 135, 230, 20));
195 return jTextFieldGuid
;
199 * This method initializes jTextFieldVersion
201 * @return javax.swing.JTextField
203 private JTextField
getJTextFieldVersion() {
204 if (jTextFieldVersion
== null) {
205 jTextFieldVersion
= new JTextField();
206 jTextFieldVersion
.setBounds(new java
.awt
.Rectangle(160, 160, 320, 20));
208 return jTextFieldVersion
;
212 * This method initializes jButtonOk
214 * @return javax.swing.JButton
216 private JButton
getJButtonOk() {
217 if (jButtonOk
== null) {
218 jButtonOk
= new JButton();
219 jButtonOk
.setBounds(new java
.awt
.Rectangle(235, 200, 90, 20));
220 jButtonOk
.setText("Ok");
221 jButtonOk
.addActionListener(this);
227 * This method initializes jButtonCancel
229 * @return javax.swing.JButton
231 private JButton
getJButtonCancel() {
232 if (jButtonCancel
== null) {
233 jButtonCancel
= new JButton();
234 jButtonCancel
.setBounds(new java
.awt
.Rectangle(355, 200, 90, 20));
235 jButtonCancel
.setText("Cancel");
236 jButtonCancel
.addActionListener(this);
238 return jButtonCancel
;
242 * This method initializes jButtonGenerateGuid
244 * @return javax.swing.JButton
246 private JButton
getJButtonGenerateGuid() {
247 if (jButtonGenerateGuid
== null) {
248 jButtonGenerateGuid
= new JButton();
249 jButtonGenerateGuid
.setBounds(new java
.awt
.Rectangle(395, 135, 85, 20));
250 jButtonGenerateGuid
.setText("Gen");
251 jButtonGenerateGuid
.addActionListener(this);
253 return jButtonGenerateGuid
;
257 * This method initializes jComboBoxExistingPackage
259 * @return javax.swing.JComboBox
261 private JComboBox
getJComboBoxExistingPackage() {
262 if (jComboBoxExistingPackage
== null) {
263 jComboBoxExistingPackage
= new JComboBox();
264 jComboBoxExistingPackage
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
266 return jComboBoxExistingPackage
;
274 public static void main(String
[] args
) {
279 * This is the default constructor
287 This is the default constructor
290 public Clone(IFrame parentFrame
, boolean modal
, int fileType
, Identification identification
) {
291 super(parentFrame
, modal
);
292 this.mode
= fileType
;
293 if (identification
!= null) {
294 this.oldId
= new Identification(identification
.getName(), identification
.getGuid(),
295 identification
.getVersion(), identification
.getPath());
296 this.newId
= new Identification(identification
.getName(), identification
.getGuid(),
297 identification
.getVersion(), identification
.getPath());
303 Query all existing packages and fill them into combox
306 private void initExistingPackage() {
307 packages
= wt
.getAllPackages();
308 for (int index
= 0; index
< packages
.size(); index
++) {
309 this.jComboBoxExistingPackage
.addItem(packages
.elementAt(index
).getName());
314 * This method initializes this
318 private void init() {
319 this.setSize(493, 260);
320 this.setContentPane(getJContentPane());
321 this.setTitle("Clone");
326 * This method initializes this
330 private void init(int mode
) {
332 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
333 this.jTextFieldType
.setText(DataType
.MODULE_SURFACE_AREA
);
334 this.jTextFieldSource
.setText(oldId
.getPath());
335 initExistingPackage();
336 this.jButtonBrowse
.setEnabled(false);
337 this.jTextFieldFilePath
.setToolTipText("Input module name here. For example, Application\\HelloWorld\\HelloWorld.msa");
338 this.jLabelDestinationFile
.setText("Module Path\\Name");
340 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
341 this.jTextFieldType
.setText(DataType
.PACKAGE_SURFACE_AREA
);
342 this.jTextFieldSource
.setText(oldId
.getPath());
343 this.jLabelBelong
.setEnabled(false);
344 this.jComboBoxExistingPackage
.setEnabled(false);
345 this.jButtonBrowse
.setEnabled(false);
346 this.jTextFieldFilePath
.setToolTipText("Input package name here. For example, MdePkg\\MdePkg.fpd");
347 this.jLabelDestinationFile
.setText("Package Path\\Name");
349 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
350 this.jTextFieldType
.setText(DataType
.PLATFORM_SURFACE_AREA
);
351 this.jTextFieldSource
.setText(oldId
.getPath());
352 this.jLabelBelong
.setEnabled(false);
353 this.jComboBoxExistingPackage
.setEnabled(false);
354 this.jTextFieldFilePath
.setToolTipText("Select platform path here. For example, C:\\MyWorkspace\\EdkNt32Pkg\\Nt32.fpd");
355 this.jLabelDestinationFile
.setText("New Platform path");
357 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
358 this.jTextFieldType
.setText(DataType
.WORKSPACE
);
359 this.jTextFieldSource
.setText(Workspace
.getCurrentWorkspace());
360 this.jLabelBelong
.setEnabled(false);
361 this.jComboBoxExistingPackage
.setEnabled(false);
362 this.jLabelBaseName
.setEnabled(false);
363 this.jTextFieldBaseName
.setEditable(false);
364 this.jLabelGuid
.setEnabled(false);
365 this.jTextFieldGuid
.setEnabled(false);
366 this.jButtonGenerateGuid
.setEnabled(false);
367 this.jLabelVersion
.setEnabled(false);
368 this.jTextFieldVersion
.setEnabled(false);
369 this.jTextFieldFilePath
.setToolTipText("Input workspace path here. For example, C:\\MyWorkspace");
370 this.jLabelDestinationFile
.setText("New Workspace path");
375 * This method initializes jContentPane
377 * @return javax.swing.JPanel
379 private JPanel
getJContentPane() {
380 if (jContentPane
== null) {
381 jLabelBelong
= new JLabel();
382 jLabelBelong
.setBounds(new java
.awt
.Rectangle(15, 85, 140, 20));
383 jLabelBelong
.setText("Clone to Package");
384 jLabelVersion
= new JLabel();
385 jLabelVersion
.setBounds(new java
.awt
.Rectangle(15, 160, 140, 20));
386 jLabelVersion
.setText("Version");
387 jLabelGuid
= new JLabel();
388 jLabelGuid
.setBounds(new java
.awt
.Rectangle(15, 135, 140, 20));
389 jLabelGuid
.setText("Guid");
390 jLabelBaseName
= new JLabel();
391 jLabelBaseName
.setBounds(new java
.awt
.Rectangle(15, 110, 140, 20));
392 jLabelBaseName
.setText("Base Name");
393 jLabelDestinationFile
= new JLabel();
394 jLabelDestinationFile
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
395 jLabelDestinationFile
.setText("Destination File Name");
396 jLabelSource
= new JLabel();
397 jLabelSource
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
398 jLabelSource
.setText("Source");
399 jLabelType
= new JLabel();
400 jLabelType
.setBounds(new java
.awt
.Rectangle(15, 10, 140, 20));
401 jLabelType
.setText("Type");
402 jContentPane
= new JPanel();
403 jContentPane
.setLayout(null);
404 jContentPane
.setSize(new java
.awt
.Dimension(490, 227));
405 jContentPane
.add(jLabelType
, null);
406 jContentPane
.add(getJTextFieldType(), null);
407 jContentPane
.add(jLabelSource
, null);
408 jContentPane
.add(getJTextFieldSource(), null);
409 jContentPane
.add(jLabelDestinationFile
, null);
410 jContentPane
.add(getJTextFieldFilePath(), null);
411 jContentPane
.add(jLabelBaseName
, null);
412 jContentPane
.add(getJTextFieldBaseName(), null);
413 jContentPane
.add(jLabelGuid
, null);
414 jContentPane
.add(getJTextFieldGuid(), null);
415 jContentPane
.add(jLabelVersion
, null);
416 jContentPane
.add(getJTextFieldVersion(), null);
417 jContentPane
.add(getJButtonOk(), null);
418 jContentPane
.add(getJButtonCancel(), null);
419 jContentPane
.add(getJButtonBrowse(), null);
420 jContentPane
.add(getJButtonGenerateGuid(), null);
421 jContentPane
.add(jLabelBelong
, null);
422 jContentPane
.add(getJComboBoxExistingPackage(), null);
428 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
430 * Override actionPerformed to listen all actions
432 public void actionPerformed(ActionEvent arg0
) {
433 if (arg0
.getSource() == jButtonCancel
) {
434 this.setVisible(false);
435 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
438 if (arg0
.getSource() == jButtonOk
) {
442 } catch (IOException e
) {
443 Log
.err("Clone", e
.getMessage());
446 } catch (XmlException e
) {
447 Log
.err("Clone", e
.getMessage());
450 } catch (Exception e
) {
451 Log
.err("Clone", e
.getMessage());
458 this.setVisible(false);
461 if (arg0
.getSource() == this.jButtonGenerateGuid
) {
462 this.jTextFieldGuid
.setText(Tools
.generateUuidString());
466 // Use different file ext
468 if (arg0
.getSource() == this.jButtonBrowse
) {
469 JFileChooser fc
= new JFileChooser();
470 fc
.setAcceptAllFileFilterUsed(false);
472 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
473 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
474 fc
.setFileSelectionMode(JFileChooser
.DIRECTORIES_ONLY
);
476 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
477 fc
.setCurrentDirectory(new File(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())
479 fc
.addChoosableFileFilter(new IFileFilter(DataType
.MODULE_SURFACE_AREA_EXT
));
481 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
482 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
483 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PACKAGE_SURFACE_AREA_EXT
));
485 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
486 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
487 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PLATFORM_SURFACE_AREA_EXT
));
489 int result
= fc
.showSaveDialog(new JPanel());
490 if (result
== JFileChooser
.APPROVE_OPTION
) {
491 this.jTextFieldFilePath
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(), mode
));
497 // Check name, guid and version
499 private boolean checkId() {
503 if (isEmpty(this.jTextFieldBaseName
.getText())) {
504 Log
.err("Base Name couldn't be empty!");
507 if (!DataValidation
.isBaseName(this.jTextFieldBaseName
.getText())) {
508 Log
.err("Incorrect data type for Base Name");
515 if (isEmpty(this.jTextFieldGuid
.getText())) {
516 Log
.err("Guid couldn't be empty!");
519 if (!DataValidation
.isGuid(this.jTextFieldGuid
.getText())) {
520 Log
.err("Incorrect data type for Guid");
527 if (isEmpty(this.jTextFieldVersion
.getText())) {
528 Log
.err("Version couldn't be empty!");
531 if (!DataValidation
.isVersion(this.jTextFieldVersion
.getText())) {
532 Log
.err("Incorrect data type for Version");
537 // Save information to id
539 newId
.setName(this.jTextFieldBaseName
.getText());
540 newId
.setGuid(this.jTextFieldGuid
.getText());
541 newId
.setVersion(this.jTextFieldVersion
.getText());
542 newId
.setPath(this.jTextFieldFilePath
.getText());
553 private boolean check() {
554 String src
= this.jTextFieldSource
.getText();
555 String trg
= this.jTextFieldFilePath
.getText();
556 File srcFile
= new File(src
);
557 File trgFile
= new File(trg
);
562 if (!srcFile
.exists()) {
563 Log
.err("The source doesn't exist");
567 Log
.err("The destination file path couldn't be empty");
570 if (src
.equals(trg
)) {
571 Log
.err("The source and destination couldn't be same");
574 if (trgFile
.exists()) {
575 Log
.err("The destination already exists");
580 // Check for workspace
582 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
583 if (trg
.indexOf(src
+ DataType
.FILE_SEPARATOR
) == 0) {
584 Log
.err("The new workspace couldn't be in current workspace!");
592 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
593 // if (trg.indexOf(DataType.DOS_FILE_SEPARATOR) == -1 && trg.indexOf(DataType.UNIX_FILE_SEPARATOR) == -1) {
594 // Log.err("The module name must include a path");
597 trg
= this.getModulePath();
598 if (src
.equals(trg
)) {
599 Log
.err("The source and destination couldn't be same");
602 trgFile
= new File(trg
);
603 if (trgFile
.exists()) {
604 Log
.err("The target module already exists");
613 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
614 if (trg
.indexOf(DataType
.DOS_FILE_SEPARATOR
) == -1 && trg
.indexOf(DataType
.UNIX_FILE_SEPARATOR
) == -1) {
615 Log
.err("The package name must include a path");
618 trg
= this.getPackagePath();
619 if (Tools
.getFilePathOnly(src
).equals(Tools
.getFilePathOnly(trg
))) {
620 Log
.err("The source and destination couldn't be same");
623 trgFile
= new File(trg
);
624 if (trgFile
.exists()) {
625 Log
.err("The target package already exists");
632 // Check for Platform
634 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
635 if (trg
.indexOf(Workspace
.getCurrentWorkspace()) != 0) {
636 Log
.err("The target platform must be in current workspace");
639 trgFile
= new File(trg
);
640 if (trgFile
.exists()) {
641 Log
.err("The target platform already exists");
650 private void save() throws IOException
, XmlException
, Exception
{
651 String src
= this.jTextFieldSource
.getText();
652 String trg
= this.jTextFieldFilePath
.getText();
653 Vector
<String
> vFiles
= new Vector
<String
>();
658 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
660 FileOperation
.copyFolder(src
, trg
);
661 } catch (Exception e
) {
662 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
663 Log
.err("Clone Workspace", e
.getMessage());
666 this.returnType
= DataType
.RETURN_TYPE_WORKSPACE
;
670 // Clone Module Surface Area
672 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
674 // Get target path from source path
676 trg
= getModulePath();
678 vFiles
= wt
.getAllModuleFiles(src
);
681 // First copy all files to new directory
683 FileOperation
.copyFile(src
, trg
);
684 for (int index
= 1; index
< vFiles
.size(); index
++) {
685 String oldFile
= vFiles
.get(index
);
686 String newFile
= vFiles
.get(index
).replace(Tools
.getFilePathOnly(src
), Tools
.getFilePathOnly(trg
));
687 FileOperation
.copyFile(oldFile
, newFile
);
691 // Create new msa file
693 ModuleSurfaceArea msa
= null;
694 msa
= OpenFile
.openMsaFile(src
);
699 msa
.getMsaHeader().setModuleName(newId
.getName());
700 msa
.getMsaHeader().setGuidValue(newId
.getGuid());
701 msa
.getMsaHeader().setVersion(newId
.getVersion());
704 // Update Cloned From element
706 updateModuleClonedId(msa
, oldId
);
711 SaveFile
.saveMsaFile(trg
, msa
);
714 // Update to platformId
716 this.setMid(new ModuleIdentification(newId
, packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())));
719 // Open belonging package
721 PackageSurfaceArea psa
= PackageSurfaceArea
.Factory
.newInstance();
722 psa
= OpenFile
.openSpdFile(mid
.getPackageId().getPath());
725 // Update the db file
727 wt
.addModuleToPackage(mid
, psa
);
729 this.returnType
= DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
;
733 // Clone Package Surface Area
735 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
737 // Get target path from source path
739 trg
= this.getPackagePath();
741 vFiles
= wt
.getAllPakcageFiles(src
);
743 FileOperation
.copyFile(src
, trg
);
744 for (int index
= 1; index
< vFiles
.size(); index
++) {
745 String oldFile
= vFiles
.get(index
);
746 String newFile
= vFiles
.get(index
).replace(Tools
.getFilePathOnly(src
), Tools
.getFilePathOnly(trg
));
747 FileOperation
.copyFile(oldFile
, newFile
);
751 // First copy all files to new directory
753 //FileOperation.copyFolder(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));
756 // Delete old spd file
758 //FileOperation.delFile(Tools.getFilePathOnly(trg) + DataType.FILE_SEPARATOR + Tools.getFileNameOnly(src));
761 // Create new spd file
763 PackageSurfaceArea spd
= null;
764 spd
= OpenFile
.openSpdFile(src
);
769 spd
.getSpdHeader().setPackageName(newId
.getName());
770 spd
.getSpdHeader().setGuidValue(newId
.getGuid());
771 spd
.getSpdHeader().setVersion(newId
.getVersion());
774 // Update Cloned From element
776 updatePackageClonedId(spd
, oldId
);
781 SaveFile
.saveSpdFile(trg
, spd
);
784 // Update to platformId
786 this.setPid(new PackageIdentification(newId
));
789 // Update the db file
791 wt
.addPackageToDatabase(pid
);
793 this.returnType
= DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
;
797 // Clone Platform Surface Area
799 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
800 PlatformSurfaceArea fpd
= null;
801 fpd
= OpenFile
.openFpdFile(src
);
806 fpd
.getPlatformHeader().setPlatformName(newId
.getName());
807 fpd
.getPlatformHeader().setGuidValue(newId
.getGuid());
808 fpd
.getPlatformHeader().setVersion(newId
.getVersion());
811 // Update Cloned From element
813 updatePlatformClonedId(fpd
, oldId
);
818 SaveFile
.saveFpdFile(trg
, fpd
);
821 // Update to platformId
823 this.setFid(new PlatformIdentification(newId
));
826 // Update the db file
828 wt
.addPlatformToDatabase(fid
);
830 this.returnType
= DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
;
835 private String
getSelectPackagePath() {
836 return Tools
.getFilePathOnly(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()).getPath());
839 private String
getModulePath() {
840 String trg
= this.jTextFieldFilePath
.getText();
841 trg
= Tools
.addPathExt(trg
, mode
);
842 trg
= Tools
.addFileSeparator(getSelectPackagePath()) + trg
;
843 Tools
.convertPathToCurrentOsType(trg
);
847 private String
getPackagePath() {
848 String trg
= this.jTextFieldFilePath
.getText();
849 trg
= Tools
.addPathExt(trg
, mode
);
850 trg
= Tools
.addFileSeparator(Workspace
.getCurrentWorkspace()) + trg
;
851 trg
= Tools
.convertPathToCurrentOsType(trg
);
856 Set target item's Cloned From element
862 private void updateModuleClonedId(ModuleSurfaceArea msa
, Identification id
) {
864 // Get PlatformDefinitions First
866 ModuleDefinitions pd
= null;
867 if (msa
.getModuleDefinitions() == null) {
868 pd
= ModuleDefinitions
.Factory
.newInstance();
869 msa
.addNewModuleDefinitions();
871 pd
= msa
.getModuleDefinitions();
875 // Get ClonedFrom then
877 ModuleDefinitions
.ClonedFrom cf
= null;
878 BigInteger count
= new BigInteger("-1");
879 if (pd
.getClonedFrom() == null) {
880 cf
= ModuleDefinitions
.ClonedFrom
.Factory
.newInstance();
882 cf
= pd
.getClonedFrom();
884 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
885 if (cf
.getClonedList().get(index
).getId() != null) {
886 count
= count
.max(cf
.getClonedList().get(index
).getId());
893 // Set new Cloned item
895 ModuleDefinitions
.ClonedFrom
.Cloned c
= ModuleDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
896 c
.setModuleGuid(id
.getGuid());
897 c
.setModuleVersion(id
.getVersion());
898 c
.setPackageGuid(wt
.getPackageIdByModuleId(oldId
).getGuid());
899 c
.setPackageVersion(wt
.getPackageIdByModuleId(oldId
).getVersion());
900 c
.setId(count
.add(new BigInteger("1")));
903 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
904 pd
.addNewClonedFrom();
905 pd
.setClonedFrom(cf
);
906 msa
.setModuleDefinitions(pd
);
910 Set target item's Cloned From element
916 private void updatePackageClonedId(PackageSurfaceArea spd
, Identification id
) {
918 // Get PlatformDefinitions First
920 PackageDefinitions pd
= null;
921 if (spd
.getPackageDefinitions() == null) {
922 pd
= PackageDefinitions
.Factory
.newInstance();
923 spd
.addNewPackageDefinitions();
925 pd
= spd
.getPackageDefinitions();
929 // Get ClonedFrom then
931 PackageDefinitions
.ClonedFrom cf
= null;
932 BigInteger count
= new BigInteger("-1");
933 if (pd
.getClonedFrom() == null) {
934 cf
= PackageDefinitions
.ClonedFrom
.Factory
.newInstance();
936 cf
= pd
.getClonedFrom();
938 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
939 if (cf
.getClonedList().get(index
).getId() != null) {
940 count
= count
.max(cf
.getClonedList().get(index
).getId());
947 // Set new Cloned item
949 PackageDefinitions
.ClonedFrom
.Cloned c
= PackageDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
950 c
.setPackageGuid(id
.getGuid());
951 c
.setPackageVersion(id
.getVersion());
952 c
.setId(count
.add(new BigInteger("1")));
955 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
956 pd
.addNewClonedFrom();
957 pd
.setClonedFrom(cf
);
958 spd
.setPackageDefinitions(pd
);
962 Set target item's Cloned From element
968 private void updatePlatformClonedId(PlatformSurfaceArea fpd
, Identification id
) {
970 // Get PlatformDefinitions First
972 PlatformDefinitions pd
= null;
973 if (fpd
.getPlatformDefinitions() == null) {
974 pd
= PlatformDefinitions
.Factory
.newInstance();
975 fpd
.addNewPlatformDefinitions();
977 pd
= fpd
.getPlatformDefinitions();
981 // Get ClonedFrom then
983 PlatformDefinitions
.ClonedFrom cf
= null;
984 BigInteger count
= new BigInteger("-1");
985 if (pd
.getClonedFrom() == null) {
986 cf
= PlatformDefinitions
.ClonedFrom
.Factory
.newInstance();
988 cf
= pd
.getClonedFrom();
990 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
991 if (cf
.getClonedList().get(index
).getId() != null) {
992 count
= count
.max(cf
.getClonedList().get(index
).getId());
999 // Set new Cloned item
1001 PlatformDefinitions
.ClonedFrom
.Cloned c
= PlatformDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
1002 c
.setPlatformGuid(id
.getGuid());
1003 c
.setPlatformVersion(id
.getVersion());
1004 c
.setId(count
.add(new BigInteger("1")));
1007 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
1008 pd
.addNewClonedFrom();
1009 pd
.setClonedFrom(cf
);
1010 fpd
.setPlatformDefinitions(pd
);
1013 public PlatformIdentification
getFid() {
1017 public void setFid(PlatformIdentification fid
) {
1021 public ModuleIdentification
getMid() {
1025 public void setMid(ModuleIdentification mid
) {
1029 public PackageIdentification
getPid() {
1033 public void setPid(PackageIdentification pid
) {