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(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
.setToolTipText("Input module name here. For example, Application\\HelloWorld\\HelloWorld.msa");
340 this.jTextFieldFilePath
.setSize(320, this.jTextFieldFilePath
.getSize().height
);
341 this.jLabelDestinationFile
.setText("New Module Path and Filename");
343 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
344 this.jTextFieldType
.setText(DataType
.PACKAGE_SURFACE_AREA
);
345 String s
= oldId
.getPath();
346 s
= Tools
.getRelativePath(oldId
.getPath(), Workspace
.getCurrentWorkspace());
347 this.jTextFieldSource
.setText(Tools
.convertPathToCurrentOsType(s
));
348 this.jLabelBelong
.setEnabled(false);
349 this.jComboBoxExistingPackage
.setEnabled(false);
350 this.jButtonBrowse
.setVisible(false);
351 this.jTextFieldFilePath
.setToolTipText("Input package name here. For example, MdePkg\\MdePkg.fpd");
352 this.jTextFieldFilePath
.setSize(320, this.jTextFieldFilePath
.getSize().height
);
353 this.jLabelDestinationFile
.setText("New Package Path and Filename");
355 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
356 this.jTextFieldType
.setText(DataType
.PLATFORM_SURFACE_AREA
);
357 this.jTextFieldSource
.setText(oldId
.getPath());
358 this.jLabelBelong
.setEnabled(false);
359 this.jComboBoxExistingPackage
.setEnabled(false);
360 this.jTextFieldFilePath
.setToolTipText("Select platform path here. For example, C:\\MyWorkspace\\EdkNt32Pkg\\Nt32.fpd");
361 this.jLabelDestinationFile
.setText("New Platform Path and Filename");
363 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
364 this.jTextFieldType
.setText(DataType
.WORKSPACE
);
365 this.jTextFieldSource
.setText(Workspace
.getCurrentWorkspace());
366 this.jLabelBelong
.setEnabled(false);
367 this.jComboBoxExistingPackage
.setEnabled(false);
368 this.jLabelBaseName
.setEnabled(false);
369 this.jTextFieldBaseName
.setEditable(false);
370 this.jLabelGuid
.setEnabled(false);
371 this.jTextFieldGuid
.setEnabled(false);
372 this.jButtonGenerateGuid
.setEnabled(false);
373 this.jLabelVersion
.setEnabled(false);
374 this.jTextFieldVersion
.setEnabled(false);
375 this.jTextFieldFilePath
.setToolTipText("Input workspace path here. For example, C:\\MyWorkspace");
376 this.jLabelDestinationFile
.setText("New Workspace Path");
381 * This method initializes jContentPane
383 * @return javax.swing.JPanel
385 private JPanel
getJContentPane() {
386 if (jContentPane
== null) {
387 jLabelBelong
= new JLabel();
388 jLabelBelong
.setBounds(new java
.awt
.Rectangle(15, 60, 190, 20));
389 jLabelBelong
.setText("Clone to Package");
390 jLabelVersion
= new JLabel();
391 jLabelVersion
.setBounds(new java
.awt
.Rectangle(15, 160, 190, 20));
392 jLabelVersion
.setText("Version");
393 jLabelGuid
= new JLabel();
394 jLabelGuid
.setBounds(new java
.awt
.Rectangle(15, 135, 190, 20));
395 jLabelGuid
.setText("Guid");
396 jLabelBaseName
= new JLabel();
397 jLabelBaseName
.setBounds(new java
.awt
.Rectangle(15, 110, 190, 20));
398 jLabelBaseName
.setText("Base Name");
399 jLabelDestinationFile
= new JLabel();
400 jLabelDestinationFile
.setBounds(new java
.awt
.Rectangle(15, 85, 190, 20));
401 jLabelDestinationFile
.setText("Destination File Name");
402 jLabelSource
= new JLabel();
403 jLabelSource
.setBounds(new java
.awt
.Rectangle(15, 35, 190, 20));
404 jLabelSource
.setText("Source");
405 jLabelType
= new JLabel();
406 jLabelType
.setBounds(new java
.awt
.Rectangle(15, 10, 190, 20));
407 jLabelType
.setText("Type");
408 jContentPane
= new JPanel();
409 jContentPane
.setLayout(null);
410 jContentPane
.setSize(new java
.awt
.Dimension(540, 227));
411 jContentPane
.add(jLabelType
, null);
412 jContentPane
.add(getJTextFieldType(), null);
413 jContentPane
.add(jLabelSource
, null);
414 jContentPane
.add(getJTextFieldSource(), null);
415 jContentPane
.add(jLabelDestinationFile
, null);
416 jContentPane
.add(getJTextFieldFilePath(), null);
417 jContentPane
.add(jLabelBaseName
, null);
418 jContentPane
.add(getJTextFieldBaseName(), null);
419 jContentPane
.add(jLabelGuid
, null);
420 jContentPane
.add(getJTextFieldGuid(), null);
421 jContentPane
.add(jLabelVersion
, null);
422 jContentPane
.add(getJTextFieldVersion(), null);
423 jContentPane
.add(getJButtonOk(), null);
424 jContentPane
.add(getJButtonCancel(), null);
425 jContentPane
.add(getJButtonBrowse(), null);
426 jContentPane
.add(getJButtonGenerateGuid(), null);
427 jContentPane
.add(jLabelBelong
, null);
428 jContentPane
.add(getJComboBoxExistingPackage(), null);
434 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
436 * Override actionPerformed to listen all actions
438 public void actionPerformed(ActionEvent arg0
) {
439 if (arg0
.getSource() == jButtonCancel
) {
440 this.setVisible(false);
441 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
444 if (arg0
.getSource() == jButtonOk
) {
448 } catch (IOException e
) {
449 Log
.err("Clone", e
.getMessage());
452 } catch (XmlException e
) {
453 Log
.err("Clone", e
.getMessage());
456 } catch (Exception e
) {
457 Log
.err("Clone", e
.getMessage());
464 this.setVisible(false);
467 if (arg0
.getSource() == this.jButtonGenerateGuid
) {
468 this.jTextFieldGuid
.setText(Tools
.generateUuidString());
472 // Use different file ext
474 if (arg0
.getSource() == this.jButtonBrowse
) {
475 JFileChooser fc
= new JFileChooser();
476 fc
.setAcceptAllFileFilterUsed(false);
478 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
479 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
480 fc
.setFileSelectionMode(JFileChooser
.DIRECTORIES_ONLY
);
482 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
483 fc
.setCurrentDirectory(new File(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())
485 fc
.addChoosableFileFilter(new IFileFilter(DataType
.MODULE_SURFACE_AREA_EXT
));
487 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
488 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
489 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PACKAGE_SURFACE_AREA_EXT
));
491 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
492 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
493 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PLATFORM_SURFACE_AREA_EXT
));
495 int result
= fc
.showSaveDialog(new JPanel());
496 if (result
== JFileChooser
.APPROVE_OPTION
) {
497 this.jTextFieldFilePath
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(), mode
));
503 // Check name, guid and version
505 private boolean checkId() {
509 if (isEmpty(this.jTextFieldBaseName
.getText())) {
510 Log
.err("Base Name couldn't be empty!");
513 if (!DataValidation
.isBaseName(this.jTextFieldBaseName
.getText())) {
514 Log
.err("Incorrect data type for Base Name");
521 if (isEmpty(this.jTextFieldGuid
.getText())) {
522 Log
.err("Guid couldn't be empty!");
525 if (!DataValidation
.isGuid(this.jTextFieldGuid
.getText())) {
526 Log
.err("Incorrect data type for Guid");
533 if (isEmpty(this.jTextFieldVersion
.getText())) {
534 Log
.err("Version couldn't be empty!");
537 if (!DataValidation
.isVersion(this.jTextFieldVersion
.getText())) {
538 Log
.err("Incorrect data type for Version");
543 // Save information to id
545 newId
.setName(this.jTextFieldBaseName
.getText());
546 newId
.setGuid(this.jTextFieldGuid
.getText());
547 newId
.setVersion(this.jTextFieldVersion
.getText());
548 newId
.setPath(this.jTextFieldFilePath
.getText());
559 private boolean check() {
560 String src
= this.oldId
.getPath();
561 String trg
= this.jTextFieldFilePath
.getText();
562 File srcFile
= new File(src
);
563 File trgFile
= new File(trg
);
568 if (!srcFile
.exists()) {
569 Log
.err("The source doesn't exist");
573 Log
.err("The destination file path couldn't be empty");
576 if (src
.equals(trg
)) {
577 Log
.err("The source and destination couldn't be same");
580 if (trgFile
.exists()) {
581 Log
.err("The destination already exists");
586 // Check for workspace
588 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
589 if (trg
.indexOf(src
+ DataType
.FILE_SEPARATOR
) == 0) {
590 Log
.err("The new workspace couldn't be in current workspace!");
598 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
599 // if (trg.indexOf(DataType.DOS_FILE_SEPARATOR) == -1 && trg.indexOf(DataType.UNIX_FILE_SEPARATOR) == -1) {
600 // Log.err("The module name must include a path");
603 trg
= this.getModulePath();
604 if (src
.equals(trg
)) {
605 Log
.err("The source and destination couldn't be same");
608 trgFile
= new File(trg
);
609 if (trgFile
.exists()) {
610 Log
.err("The target module already exists");
619 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
620 if (trg
.indexOf(DataType
.DOS_FILE_SEPARATOR
) == -1 && trg
.indexOf(DataType
.UNIX_FILE_SEPARATOR
) == -1) {
621 Log
.err("The package name must include a path");
624 trg
= this.getPackagePath();
625 if (Tools
.getFilePathOnly(src
).equals(Tools
.getFilePathOnly(trg
))) {
626 Log
.err("The source and destination couldn't be same");
629 trgFile
= new File(trg
);
630 if (trgFile
.exists()) {
631 Log
.err("The target package already exists");
638 // Check for Platform
640 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
641 if (trg
.indexOf(Workspace
.getCurrentWorkspace()) != 0) {
642 Log
.err("The target platform must be in current workspace");
645 trgFile
= new File(trg
);
646 if (trgFile
.exists()) {
647 Log
.err("The target platform already exists");
656 private void save() throws IOException
, XmlException
, Exception
{
657 String src
= this.oldId
.getPath();
658 String trg
= this.jTextFieldFilePath
.getText();
659 Vector
<String
> vFiles
= new Vector
<String
>();
664 if (mode
== DataType
.RETURN_TYPE_WORKSPACE
) {
666 FileOperation
.copyFolder(src
, trg
);
667 } catch (Exception e
) {
668 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
669 Log
.err("Clone Workspace", e
.getMessage());
672 this.returnType
= DataType
.RETURN_TYPE_WORKSPACE
;
676 // Clone Module Surface Area
678 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
680 // Get target path from source path
682 trg
= getModulePath();
684 vFiles
= wt
.getAllModuleFilesPath(src
);
687 // First copy all files to new directory
689 FileOperation
.copyFile(src
, trg
);
690 for (int index
= 1; index
< vFiles
.size(); index
++) {
691 String oldFile
= vFiles
.get(index
);
692 String newFile
= vFiles
.get(index
).replace(Tools
.getFilePathOnly(src
), Tools
.getFilePathOnly(trg
));
693 FileOperation
.copyFile(oldFile
, newFile
);
697 // Create new msa file
699 ModuleSurfaceArea msa
= null;
700 msa
= OpenFile
.openMsaFile(src
);
705 msa
.getMsaHeader().setModuleName(newId
.getName());
706 msa
.getMsaHeader().setGuidValue(newId
.getGuid());
707 msa
.getMsaHeader().setVersion(newId
.getVersion());
710 // Update Cloned From element
712 updateModuleClonedId(msa
, oldId
);
717 SaveFile
.saveMsaFile(trg
, msa
);
720 // Update to platformId
722 this.setMid(new ModuleIdentification(newId
, packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())));
725 // Open belonging package
727 PackageSurfaceArea psa
= PackageSurfaceArea
.Factory
.newInstance();
728 psa
= OpenFile
.openSpdFile(mid
.getPackageId().getPath());
731 // Update the db file
733 wt
.addModuleToPackage(mid
, psa
);
735 this.returnType
= DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
;
739 // Clone Package Surface Area
741 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
743 // Get target path from source path
745 trg
= this.getPackagePath();
747 vFiles
= wt
.getAllPakcageFilesPath(src
);
749 FileOperation
.copyFile(src
, trg
);
750 for (int index
= 1; index
< vFiles
.size(); index
++) {
751 String oldFile
= vFiles
.get(index
);
752 String newFile
= vFiles
.get(index
).replace(Tools
.getFilePathOnly(src
), Tools
.getFilePathOnly(trg
));
753 FileOperation
.copyFile(oldFile
, newFile
);
757 // First copy all files to new directory
759 //FileOperation.copyFolder(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));
762 // Delete old spd file
764 //FileOperation.delFile(Tools.getFilePathOnly(trg) + DataType.FILE_SEPARATOR + Tools.getFileNameOnly(src));
767 // Create new spd file
769 PackageSurfaceArea spd
= null;
770 spd
= OpenFile
.openSpdFile(src
);
775 spd
.getSpdHeader().setPackageName(newId
.getName());
776 spd
.getSpdHeader().setGuidValue(newId
.getGuid());
777 spd
.getSpdHeader().setVersion(newId
.getVersion());
780 // Update Cloned From element
782 updatePackageClonedId(spd
, oldId
);
787 SaveFile
.saveSpdFile(trg
, spd
);
790 // Update to platformId
792 this.setPid(new PackageIdentification(newId
));
795 // Update the db file
797 wt
.addPackageToDatabase(pid
);
799 this.returnType
= DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
;
803 // Clone Platform Surface Area
805 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
806 PlatformSurfaceArea fpd
= null;
807 fpd
= OpenFile
.openFpdFile(src
);
812 fpd
.getPlatformHeader().setPlatformName(newId
.getName());
813 fpd
.getPlatformHeader().setGuidValue(newId
.getGuid());
814 fpd
.getPlatformHeader().setVersion(newId
.getVersion());
817 // Update Cloned From element
819 updatePlatformClonedId(fpd
, oldId
);
824 SaveFile
.saveFpdFile(trg
, fpd
);
827 // Update to platformId
829 this.setFid(new PlatformIdentification(newId
));
832 // Update the db file
834 wt
.addPlatformToDatabase(fid
);
836 this.returnType
= DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
;
841 private String
getSelectPackagePath() {
842 return Tools
.getFilePathOnly(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()).getPath());
845 private String
getModulePath() {
846 String trg
= this.jTextFieldFilePath
.getText();
847 trg
= Tools
.addPathExt(trg
, mode
);
848 trg
= Tools
.addFileSeparator(getSelectPackagePath()) + trg
;
849 Tools
.convertPathToCurrentOsType(trg
);
853 private String
getPackagePath() {
854 String trg
= this.jTextFieldFilePath
.getText();
855 trg
= Tools
.addPathExt(trg
, mode
);
856 trg
= Tools
.addFileSeparator(Workspace
.getCurrentWorkspace()) + trg
;
857 trg
= Tools
.convertPathToCurrentOsType(trg
);
862 Set target item's Cloned From element
868 private void updateModuleClonedId(ModuleSurfaceArea msa
, Identification id
) {
870 // Get PlatformDefinitions First
872 ModuleDefinitions pd
= null;
873 if (msa
.getModuleDefinitions() == null) {
874 pd
= ModuleDefinitions
.Factory
.newInstance();
875 msa
.addNewModuleDefinitions();
877 pd
= msa
.getModuleDefinitions();
881 // Get ClonedFrom then
883 ModuleDefinitions
.ClonedFrom cf
= null;
884 BigInteger count
= new BigInteger("-1");
885 if (pd
.getClonedFrom() == null) {
886 cf
= ModuleDefinitions
.ClonedFrom
.Factory
.newInstance();
888 cf
= pd
.getClonedFrom();
890 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
891 if (cf
.getClonedList().get(index
).getId() != null) {
892 count
= count
.max(cf
.getClonedList().get(index
).getId());
899 // Set new Cloned item
901 ModuleDefinitions
.ClonedFrom
.Cloned c
= ModuleDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
902 c
.setModuleGuid(id
.getGuid());
903 c
.setModuleVersion(id
.getVersion());
904 c
.setPackageGuid(wt
.getPackageIdByModuleId(oldId
).getGuid());
905 c
.setPackageVersion(wt
.getPackageIdByModuleId(oldId
).getVersion());
906 c
.setId(count
.add(new BigInteger("1")));
907 String guid
= wt
.getModuleFarGuid(oldId
);
908 if (guid
!= null && !guid
.equals("")) {
913 cf
.setClonedArray(cf
.getClonedList().size() - 1, c
);
914 pd
.addNewClonedFrom();
915 pd
.setClonedFrom(cf
);
916 msa
.setModuleDefinitions(pd
);
920 Set target item's Cloned From element
926 private void updatePackageClonedId(PackageSurfaceArea spd
, Identification id
) {
928 // Get PlatformDefinitions First
930 PackageDefinitions pd
= null;
931 if (spd
.getPackageDefinitions() == null) {
932 pd
= PackageDefinitions
.Factory
.newInstance();
933 spd
.addNewPackageDefinitions();
935 pd
= spd
.getPackageDefinitions();
939 // Get ClonedFrom then
941 PackageDefinitions
.ClonedFrom cf
= null;
942 BigInteger count
= new BigInteger("-1");
943 if (pd
.getClonedFrom() == null) {
944 cf
= PackageDefinitions
.ClonedFrom
.Factory
.newInstance();
946 cf
= pd
.getClonedFrom();
948 for (int index
= 0; index
< cf
.getClonedList().size(); index
++) {
949 if (cf
.getClonedList().get(index
).getId() != null) {
950 count
= count
.max(cf
.getClonedList().get(index
).getId());
957 // Set new Cloned item
959 PackageDefinitions
.ClonedFrom
.Cloned c
= PackageDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
960 c
.setPackageGuid(id
.getGuid());
961 c
.setPackageVersion(id
.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 spd
.setPackageDefinitions(pd
);
976 Set target item's Cloned From element
982 private void updatePlatformClonedId(PlatformSurfaceArea fpd
, Identification id
) {
984 // Get PlatformDefinitions First
986 PlatformDefinitions pd
= null;
987 if (fpd
.getPlatformDefinitions() == null) {
988 pd
= PlatformDefinitions
.Factory
.newInstance();
989 fpd
.addNewPlatformDefinitions();
991 pd
= fpd
.getPlatformDefinitions();
995 // Get ClonedFrom then
997 PlatformDefinitions
.ClonedFrom cf
= null;
998 BigInteger count
= new BigInteger("-1");
999 if (pd
.getClonedFrom() == null) {
1000 cf
= PlatformDefinitions
.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 PlatformDefinitions
.ClonedFrom
.Cloned c
= PlatformDefinitions
.ClonedFrom
.Cloned
.Factory
.newInstance();
1016 c
.setPlatformGuid(id
.getGuid());
1017 c
.setPlatformVersion(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 fpd
.setPlatformDefinitions(pd
);
1031 public PlatformIdentification
getFid() {
1035 public void setFid(PlatformIdentification fid
) {
1039 public ModuleIdentification
getMid() {
1043 public void setMid(ModuleIdentification mid
) {
1047 public PackageIdentification
getPid() {
1051 public void setPid(PackageIdentification pid
) {