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
;
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(210, 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(210, 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(445, 85, 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(210, 85, 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(210, 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(210, 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(210, 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(285, 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(405, 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(445, 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(210, 60, 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(550, 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 String s
= oldId
.getPath();
335 s
= Tools
.getRelativePath(s
, Tools
.getFilePathOnly(wt
.getPackageIdByModuleId(oldId
).getPath()));
336 this.jTextFieldSource
.setText(Tools
.convertPathToCurrentOsType(s
));
337 initExistingPackage();
338 this.jButtonBrowse
.setVisible(false);
339 this.jTextFieldFilePath
340 .setToolTipText("Input module name here. For example, Application\\HelloWorld\\HelloWorld.msa");
341 this.jTextFieldFilePath
.setSize(320, this.jTextFieldFilePath
.getSize().height
);
342 this.jLabelDestinationFile
.setText("New Module Path and Filename");
344 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
345 this.jTextFieldType
.setText(DataType
.PACKAGE_SURFACE_AREA
);
346 String s
= oldId
.getPath();
347 s
= Tools
.getRelativePath(oldId
.getPath(), Workspace
.getCurrentWorkspace());
348 this.jTextFieldSource
.setText(Tools
.convertPathToCurrentOsType(s
));
349 this.jLabelBelong
.setEnabled(false);
350 this.jComboBoxExistingPackage
.setEnabled(false);
351 this.jButtonBrowse
.setVisible(false);
352 this.jTextFieldFilePath
.setToolTipText("Input package name here. For example, MdePkg\\MdePkg.fpd");
353 this.jTextFieldFilePath
.setSize(320, this.jTextFieldFilePath
.getSize().height
);
354 this.jLabelDestinationFile
.setText("New Package Path and Filename");
356 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
357 this.jTextFieldType
.setText(DataType
.PLATFORM_SURFACE_AREA
);
358 this.jTextFieldSource
.setText(oldId
.getPath());
359 this.jLabelBelong
.setEnabled(false);
360 this.jComboBoxExistingPackage
.setEnabled(false);
361 this.jTextFieldFilePath
362 .setToolTipText("Select platform path here. For example, C:\\MyWorkspace\\EdkNt32Pkg\\Nt32.fpd");
363 this.jLabelDestinationFile
.setText("New Platform Path and Filename");
365 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
366 this.jTextFieldType
.setText(DataType
.WORKSPACE
);
367 this.jTextFieldSource
.setText(Workspace
.getCurrentWorkspace());
368 this.jLabelBelong
.setEnabled(false);
369 this.jComboBoxExistingPackage
.setEnabled(false);
370 this.jLabelBaseName
.setEnabled(false);
371 this.jTextFieldBaseName
.setEditable(false);
372 this.jLabelGuid
.setEnabled(false);
373 this.jTextFieldGuid
.setEnabled(false);
374 this.jButtonGenerateGuid
.setEnabled(false);
375 this.jLabelVersion
.setEnabled(false);
376 this.jTextFieldVersion
.setEnabled(false);
377 this.jTextFieldFilePath
.setToolTipText("Input workspace path here. For example, C:\\MyWorkspace");
378 this.jLabelDestinationFile
.setText("New Workspace Path");
383 * This method initializes jContentPane
385 * @return javax.swing.JPanel
387 private JPanel
getJContentPane() {
388 if (jContentPane
== null) {
389 jLabelBelong
= new JLabel();
390 jLabelBelong
.setBounds(new java
.awt
.Rectangle(15, 60, 190, 20));
391 jLabelBelong
.setText("Clone to Package");
392 jLabelVersion
= new JLabel();
393 jLabelVersion
.setBounds(new java
.awt
.Rectangle(15, 160, 190, 20));
394 jLabelVersion
.setText("Version");
395 jLabelGuid
= new JLabel();
396 jLabelGuid
.setBounds(new java
.awt
.Rectangle(15, 135, 190, 20));
397 jLabelGuid
.setText("Guid");
398 jLabelBaseName
= new JLabel();
399 jLabelBaseName
.setBounds(new java
.awt
.Rectangle(15, 110, 190, 20));
400 jLabelBaseName
.setText("Base Name");
401 jLabelDestinationFile
= new JLabel();
402 jLabelDestinationFile
.setBounds(new java
.awt
.Rectangle(15, 85, 190, 20));
403 jLabelDestinationFile
.setText("Destination File Name");
404 jLabelSource
= new JLabel();
405 jLabelSource
.setBounds(new java
.awt
.Rectangle(15, 35, 190, 20));
406 jLabelSource
.setText("Source");
407 jLabelType
= new JLabel();
408 jLabelType
.setBounds(new java
.awt
.Rectangle(15, 10, 190, 20));
409 jLabelType
.setText("Type");
410 jContentPane
= new JPanel();
411 jContentPane
.setLayout(null);
412 jContentPane
.setSize(new java
.awt
.Dimension(540, 227));
413 jContentPane
.add(jLabelType
, null);
414 jContentPane
.add(getJTextFieldType(), null);
415 jContentPane
.add(jLabelSource
, null);
416 jContentPane
.add(getJTextFieldSource(), null);
417 jContentPane
.add(jLabelDestinationFile
, null);
418 jContentPane
.add(getJTextFieldFilePath(), null);
419 jContentPane
.add(jLabelBaseName
, null);
420 jContentPane
.add(getJTextFieldBaseName(), null);
421 jContentPane
.add(jLabelGuid
, null);
422 jContentPane
.add(getJTextFieldGuid(), null);
423 jContentPane
.add(jLabelVersion
, null);
424 jContentPane
.add(getJTextFieldVersion(), null);
425 jContentPane
.add(getJButtonOk(), null);
426 jContentPane
.add(getJButtonCancel(), null);
427 jContentPane
.add(getJButtonBrowse(), null);
428 jContentPane
.add(getJButtonGenerateGuid(), null);
429 jContentPane
.add(jLabelBelong
, null);
430 jContentPane
.add(getJComboBoxExistingPackage(), null);
436 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
438 * Override actionPerformed to listen all actions
440 public void actionPerformed(ActionEvent arg0
) {
441 if (arg0
.getSource() == jButtonCancel
) {
442 this.setVisible(false);
443 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
446 if (arg0
.getSource() == jButtonOk
) {
450 } catch (IOException e
) {
451 Log
.wrn("Clone", e
.getMessage());
452 Log
.err("Clone", e
.getMessage());
454 } catch (XmlException e
) {
455 Log
.wrn("Clone", e
.getMessage());
456 Log
.err("Clone", e
.getMessage());
458 } catch (Exception e
) {
459 Log
.wrn("Clone", e
.getMessage());
460 Log
.err("Clone", e
.getMessage());
466 this.setVisible(false);
469 if (arg0
.getSource() == this.jButtonGenerateGuid
) {
470 this.jTextFieldGuid
.setText(Tools
.generateUuidString());
474 // Use different file ext
476 if (arg0
.getSource() == this.jButtonBrowse
) {
477 JFileChooser fc
= new JFileChooser();
478 fc
.setAcceptAllFileFilterUsed(false);
480 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
481 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
482 fc
.setFileSelectionMode(JFileChooser
.DIRECTORIES_ONLY
);
484 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
485 fc
.setCurrentDirectory(new File(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())
487 fc
.addChoosableFileFilter(new IFileFilter(DataType
.MODULE_SURFACE_AREA_EXT
));
489 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
490 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
491 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PACKAGE_SURFACE_AREA_EXT
));
493 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
494 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
495 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PLATFORM_SURFACE_AREA_EXT
));
497 int result
= fc
.showSaveDialog(new JPanel());
498 if (result
== JFileChooser
.APPROVE_OPTION
) {
499 this.jTextFieldFilePath
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(), mode
));
505 // Check name, guid and version
507 private boolean checkId() {
511 if (isEmpty(this.jTextFieldBaseName
.getText())) {
512 Log
.wrn("Clone", "Base Name couldn't be empty!");
515 if (!DataValidation
.isBaseName(this.jTextFieldBaseName
.getText())) {
516 Log
.wrn("Clone", "Incorrect data type for Base Name");
523 if (isEmpty(this.jTextFieldGuid
.getText())) {
524 Log
.wrn("Clone", "Guid couldn't be empty!");
527 if (!DataValidation
.isGuid(this.jTextFieldGuid
.getText())) {
528 Log
.wrn("Clone", "Incorrect data type for Guid");
535 if (isEmpty(this.jTextFieldVersion
.getText())) {
536 Log
.wrn("Clone", "Version couldn't be empty!");
539 if (!DataValidation
.isVersion(this.jTextFieldVersion
.getText())) {
540 Log
.wrn("Clone", "Incorrect data type for Version");
545 // Save information to id
547 newId
.setName(this.jTextFieldBaseName
.getText());
548 newId
.setGuid(this.jTextFieldGuid
.getText());
549 newId
.setVersion(this.jTextFieldVersion
.getText());
550 newId
.setPath(this.jTextFieldFilePath
.getText());
561 private boolean check() {
562 String src
= this.oldId
.getPath();
563 String trg
= this.jTextFieldFilePath
.getText();
564 File srcFile
= new File(src
);
565 File trgFile
= new File(trg
);
570 if (!srcFile
.exists()) {
571 Log
.wrn("Clone", "The source doesn't exist");
575 Log
.wrn("Clone", "The destination file path couldn't be empty");
578 if (src
.equals(trg
)) {
579 Log
.wrn("Clone", "The source and destination couldn't be same");
582 if (trgFile
.exists()) {
583 Log
.wrn("Clone", "The destination already exists");
588 // Check for workspace
590 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
591 if (trg
.indexOf(src
+ DataType
.FILE_SEPARATOR
) == 0) {
592 Log
.wrn("Clone", "The new workspace couldn't be in current workspace!");
600 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
601 // if (trg.indexOf(DataType.DOS_FILE_SEPARATOR) == -1 && trg.indexOf(DataType.UNIX_FILE_SEPARATOR) == -1) {
602 // Log.err("The module name must include a path");
605 trg
= this.getModulePath();
606 if (src
.equals(trg
)) {
607 Log
.wrn("Clone", "The source and destination couldn't be same");
610 trgFile
= new File(trg
);
611 if (trgFile
.exists()) {
612 Log
.wrn("Clone", "The target module already exists");
621 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
622 if (trg
.indexOf(DataType
.DOS_FILE_SEPARATOR
) == -1 && trg
.indexOf(DataType
.UNIX_FILE_SEPARATOR
) == -1) {
623 Log
.wrn("Clone", "The package name must include a path");
626 trg
= this.getPackagePath();
627 if (Tools
.getFilePathOnly(src
).equals(Tools
.getFilePathOnly(trg
))) {
628 Log
.wrn("Clone", "The source and destination couldn't be same");
631 trgFile
= new File(trg
);
632 if (trgFile
.exists()) {
633 Log
.wrn("Clone", "The target package already exists");
640 // Check for Platform
642 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
643 if (trg
.indexOf(Workspace
.getCurrentWorkspace()) != 0) {
644 Log
.wrn("Clone", "The target platform must be in current workspace");
647 trgFile
= new File(trg
);
648 if (trgFile
.exists()) {
649 Log
.wrn("Clone", "The target platform already exists");
658 private void save() throws IOException
, XmlException
, Exception
{
659 String src
= this.oldId
.getPath();
660 String trg
= this.jTextFieldFilePath
.getText();
661 Vector
<String
> vFiles
= new Vector
<String
>();
666 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
667 FileOperation
.copyFolder(src
, trg
);
668 this.returnType
= DataType
.RETURN_TYPE_WORKSPACE
;
672 // Clone Module Surface Area
674 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
676 // Get target path from source path
678 trg
= getModulePath();
680 vFiles
= wt
.getAllModuleFilesPath(src
);
683 // First copy all files to new directory
685 FileOperation
.copyFile(src
, trg
);
686 for (int index
= 1; index
< vFiles
.size(); index
++) {
687 String oldFile
= vFiles
.get(index
);
688 String newFile
= vFiles
.get(index
).replace(Tools
.getFilePathOnly(src
), Tools
.getFilePathOnly(trg
));
689 FileOperation
.copyFile(oldFile
, newFile
);
693 // Create new msa file
695 ModuleSurfaceArea msa
= null;
696 msa
= OpenFile
.openMsaFile(src
);
701 msa
.getMsaHeader().setModuleName(newId
.getName());
702 msa
.getMsaHeader().setGuidValue(newId
.getGuid());
703 msa
.getMsaHeader().setVersion(newId
.getVersion());
706 // Update Cloned From element
708 updateModuleClonedId(msa
, oldId
);
713 SaveFile
.saveMsaFile(trg
, msa
);
716 // Update to platformId
718 this.setMid(new ModuleIdentification(newId
,
719 packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())));
722 // Open belonging package
724 PackageSurfaceArea psa
= PackageSurfaceArea
.Factory
.newInstance();
725 psa
= OpenFile
.openSpdFile(mid
.getPackageId().getPath());
728 // Update the db file
730 wt
.addModuleToPackage(mid
, psa
);
732 this.returnType
= DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
;
736 // Clone Package Surface Area
738 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
740 // Get target path from source path
742 trg
= this.getPackagePath();
744 vFiles
= wt
.getAllPakcageFilesPath(src
);
746 FileOperation
.copyFile(src
, trg
);
747 for (int index
= 1; index
< vFiles
.size(); index
++) {
748 String oldFile
= vFiles
.get(index
);
749 String newFile
= vFiles
.get(index
).replace(Tools
.getFilePathOnly(src
), Tools
.getFilePathOnly(trg
));
750 FileOperation
.copyFile(oldFile
, newFile
);
754 // First copy all files to new directory
756 //FileOperation.copyFolder(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));
759 // Delete old spd file
761 //FileOperation.delFile(Tools.getFilePathOnly(trg) + DataType.FILE_SEPARATOR + Tools.getFileNameOnly(src));
764 // Create new spd file
766 PackageSurfaceArea spd
= null;
767 spd
= OpenFile
.openSpdFile(src
);
772 spd
.getSpdHeader().setPackageName(newId
.getName());
773 spd
.getSpdHeader().setGuidValue(newId
.getGuid());
774 spd
.getSpdHeader().setVersion(newId
.getVersion());
777 // Update Cloned From element
779 updatePackageClonedId(spd
, oldId
);
784 SaveFile
.saveSpdFile(trg
, spd
);
787 // Update to platformId
789 this.setPid(new PackageIdentification(newId
));
792 // Update the db file
794 wt
.addPackageToDatabase(pid
);
796 this.returnType
= DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
;
800 // Clone Platform Surface Area
802 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
803 PlatformSurfaceArea fpd
= null;
804 fpd
= OpenFile
.openFpdFile(src
);
809 fpd
.getPlatformHeader().setPlatformName(newId
.getName());
810 fpd
.getPlatformHeader().setGuidValue(newId
.getGuid());
811 fpd
.getPlatformHeader().setVersion(newId
.getVersion());
814 // Update Cloned From element
816 updatePlatformClonedId(fpd
, oldId
);
821 SaveFile
.saveFpdFile(trg
, fpd
);
824 // Update to platformId
826 this.setFid(new PlatformIdentification(newId
));
829 // Update the db file
831 wt
.addPlatformToDatabase(fid
);
833 this.returnType
= DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
;
838 private String
getSelectPackagePath() {
839 return Tools
.getFilePathOnly(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()).getPath());
842 private String
getModulePath() {
843 String trg
= this.jTextFieldFilePath
.getText();
844 trg
= Tools
.addPathExt(trg
, mode
);
845 trg
= Tools
.addFileSeparator(getSelectPackagePath()) + trg
;
846 Tools
.convertPathToCurrentOsType(trg
);
850 private String
getPackagePath() {
851 String trg
= this.jTextFieldFilePath
.getText();
852 trg
= Tools
.addPathExt(trg
, mode
);
853 trg
= Tools
.addFileSeparator(Workspace
.getCurrentWorkspace()) + trg
;
854 trg
= Tools
.convertPathToCurrentOsType(trg
);
859 Set target item's Cloned From element
865 private void updateModuleClonedId(ModuleSurfaceArea msa
, Identification id
) {
867 // Get PlatformDefinitions First
869 ModuleDefinitions pd
= null;
870 if (msa
.getModuleDefinitions() == null) {
871 pd
= ModuleDefinitions
.Factory
.newInstance();
872 msa
.addNewModuleDefinitions();
874 pd
= msa
.getModuleDefinitions();
878 // Get ClonedFrom then
880 ModuleDefinitions
.ClonedFrom cf
= null;
881 BigInteger count
= new BigInteger("-1");
882 if (pd
.getClonedFrom() == null) {
883 cf
= ModuleDefinitions
.ClonedFrom
.Factory
.newInstance();
885 cf
= pd
.getClonedFrom();
887 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
888 if (cf
.getClonedList().get(index
).getId() != null) {
889 count
= count
.max(cf
.getClonedList().get(index
).getId());
896 // Set new Cloned item
898 ModuleDefinitions
.ClonedFrom
.Cloned c
= ModuleDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
899 c
.setModuleGuid(id
.getGuid());
900 c
.setModuleVersion(id
.getVersion());
901 c
.setPackageGuid(wt
.getPackageIdByModuleId(oldId
).getGuid());
902 c
.setPackageVersion(wt
.getPackageIdByModuleId(oldId
).getVersion());
903 c
.setId(count
.add(new BigInteger("1")));
904 String guid
= wt
.getModuleFarGuid(oldId
);
905 if (guid
!= null && !guid
.equals("")) {
910 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
911 pd
.addNewClonedFrom();
912 pd
.setClonedFrom(cf
);
913 msa
.setModuleDefinitions(pd
);
917 Set target item's Cloned From element
923 private void updatePackageClonedId(PackageSurfaceArea spd
, Identification id
) {
925 // Get PlatformDefinitions First
927 PackageDefinitions pd
= null;
928 if (spd
.getPackageDefinitions() == null) {
929 pd
= PackageDefinitions
.Factory
.newInstance();
930 spd
.addNewPackageDefinitions();
932 pd
= spd
.getPackageDefinitions();
936 // Get ClonedFrom then
938 PackageDefinitions
.ClonedFrom cf
= null;
939 BigInteger count
= new BigInteger("-1");
940 if (pd
.getClonedFrom() == null) {
941 cf
= PackageDefinitions
.ClonedFrom
.Factory
.newInstance();
943 cf
= pd
.getClonedFrom();
945 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
946 if (cf
.getClonedList().get(index
).getId() != null) {
947 count
= count
.max(cf
.getClonedList().get(index
).getId());
954 // Set new Cloned item
956 PackageDefinitions
.ClonedFrom
.Cloned c
= PackageDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
957 c
.setPackageGuid(id
.getGuid());
958 c
.setPackageVersion(id
.getVersion());
959 c
.setId(count
.add(new BigInteger("1")));
960 String guid
= wt
.getModuleFarGuid(oldId
);
961 if (guid
!= null && !guid
.equals("")) {
966 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
967 pd
.addNewClonedFrom();
968 pd
.setClonedFrom(cf
);
969 spd
.setPackageDefinitions(pd
);
973 Set target item's Cloned From element
979 private void updatePlatformClonedId(PlatformSurfaceArea fpd
, Identification id
) {
981 // Get PlatformDefinitions First
983 PlatformDefinitions pd
= null;
984 if (fpd
.getPlatformDefinitions() == null) {
985 pd
= PlatformDefinitions
.Factory
.newInstance();
986 fpd
.addNewPlatformDefinitions();
988 pd
= fpd
.getPlatformDefinitions();
992 // Get ClonedFrom then
994 PlatformDefinitions
.ClonedFrom cf
= null;
995 BigInteger count
= new BigInteger("-1");
996 if (pd
.getClonedFrom() == null) {
997 cf
= PlatformDefinitions
.ClonedFrom
.Factory
.newInstance();
999 cf
= pd
.getClonedFrom();
1001 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
1002 if (cf
.getClonedList().get(index
).getId() != null) {
1003 count
= count
.max(cf
.getClonedList().get(index
).getId());
1010 // Set new Cloned item
1012 PlatformDefinitions
.ClonedFrom
.Cloned c
= PlatformDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
1013 c
.setPlatformGuid(id
.getGuid());
1014 c
.setPlatformVersion(id
.getVersion());
1015 c
.setId(count
.add(new BigInteger("1")));
1016 String guid
= wt
.getModuleFarGuid(oldId
);
1017 if (guid
!= null && !guid
.equals("")) {
1022 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
1023 pd
.addNewClonedFrom();
1024 pd
.setClonedFrom(cf
);
1025 fpd
.setPlatformDefinitions(pd
);
1028 public PlatformIdentification
getFid() {
1032 public void setFid(PlatformIdentification fid
) {
1036 public ModuleIdentification
getMid() {
1040 public void setMid(ModuleIdentification mid
) {
1044 public PackageIdentification
getPid() {
1048 public void setPid(PackageIdentification pid
) {