]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/Clone.java
8f1ec6c6bab4e9ab0257256769cc3a00bdb9af4a
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / Clone.java
1 /** @file
2
3 The file is used to clone workspace, module, package and platform
4
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
10
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.
13
14 **/
15 package org.tianocore.frameworkwizard;
16
17 import java.awt.event.ActionEvent;
18 import java.io.File;
19 import java.io.IOException;
20 import java.math.BigInteger;
21 import java.util.Vector;
22
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;
28
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;
53
54 public class Clone extends IDialog {
55
56 /**
57 Define class members
58
59 **/
60 private static final long serialVersionUID = -5469299324965727137L;
61
62 private JPanel jContentPane = null;
63
64 private JLabel jLabelType = null;
65
66 private JTextField jTextFieldType = null;
67
68 private JLabel jLabelSource = null;
69
70 private JTextField jTextFieldSource = null;
71
72 private JButton jButtonBrowse = null;
73
74 private JLabel jLabelDestinationFile = null;
75
76 private JTextField jTextFieldFilePath = null;
77
78 private JLabel jLabelBaseName = null;
79
80 private JTextField jTextFieldBaseName = null;
81
82 private JLabel jLabelGuid = null;
83
84 private JTextField jTextFieldGuid = null;
85
86 private JLabel jLabelVersion = null;
87
88 private JTextField jTextFieldVersion = null;
89
90 private JButton jButtonOk = null;
91
92 private JButton jButtonCancel = null;
93
94 private JButton jButtonGenerateGuid = null;
95
96 private int mode = -1;
97
98 private Vector<PackageIdentification> packages = null;
99
100 private WorkspaceTools wt = new WorkspaceTools();
101
102 private JLabel jLabelBelong = null;
103
104 private JComboBox jComboBoxExistingPackage = null;
105
106 private Identification oldId = null;
107
108 private Identification newId = null;
109
110 private ModuleIdentification mid = null;
111
112 private PackageIdentification pid = null;
113
114 private PlatformIdentification fid = null;
115
116 /**
117 * This method initializes jTextFieldType
118 *
119 * @return javax.swing.JTextField
120 */
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);
126 }
127 return jTextFieldType;
128 }
129
130 /**
131 * This method initializes jTextFieldSource
132 *
133 * @return javax.swing.JTextField
134 */
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);
140 }
141 return jTextFieldSource;
142 }
143
144 /**
145 * This method initializes jButtonBrowse
146 *
147 * @return javax.swing.JButton
148 */
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);
155 }
156 return jButtonBrowse;
157 }
158
159 /**
160 * This method initializes jTextFieldDestinationFile
161 *
162 * @return javax.swing.JTextField
163 */
164 private JTextField getJTextFieldFilePath() {
165 if (jTextFieldFilePath == null) {
166 jTextFieldFilePath = new JTextField();
167 jTextFieldFilePath.setBounds(new java.awt.Rectangle(160, 60, 230, 20));
168 }
169 return jTextFieldFilePath;
170 }
171
172 /**
173 * This method initializes jTextFieldBaseName
174 *
175 * @return javax.swing.JTextField
176 */
177 private JTextField getJTextFieldBaseName() {
178 if (jTextFieldBaseName == null) {
179 jTextFieldBaseName = new JTextField();
180 jTextFieldBaseName.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
181 }
182 return jTextFieldBaseName;
183 }
184
185 /**
186 * This method initializes jTextFieldGuid
187 *
188 * @return javax.swing.JTextField
189 */
190 private JTextField getJTextFieldGuid() {
191 if (jTextFieldGuid == null) {
192 jTextFieldGuid = new JTextField();
193 jTextFieldGuid.setBounds(new java.awt.Rectangle(160, 135, 230, 20));
194 }
195 return jTextFieldGuid;
196 }
197
198 /**
199 * This method initializes jTextFieldVersion
200 *
201 * @return javax.swing.JTextField
202 */
203 private JTextField getJTextFieldVersion() {
204 if (jTextFieldVersion == null) {
205 jTextFieldVersion = new JTextField();
206 jTextFieldVersion.setBounds(new java.awt.Rectangle(160, 160, 320, 20));
207 }
208 return jTextFieldVersion;
209 }
210
211 /**
212 * This method initializes jButtonOk
213 *
214 * @return javax.swing.JButton
215 */
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);
222 }
223 return jButtonOk;
224 }
225
226 /**
227 * This method initializes jButtonCancel
228 *
229 * @return javax.swing.JButton
230 */
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);
237 }
238 return jButtonCancel;
239 }
240
241 /**
242 * This method initializes jButtonGenerateGuid
243 *
244 * @return javax.swing.JButton
245 */
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);
252 }
253 return jButtonGenerateGuid;
254 }
255
256 /**
257 * This method initializes jComboBoxExistingPackage
258 *
259 * @return javax.swing.JComboBox
260 */
261 private JComboBox getJComboBoxExistingPackage() {
262 if (jComboBoxExistingPackage == null) {
263 jComboBoxExistingPackage = new JComboBox();
264 jComboBoxExistingPackage.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
265 }
266 return jComboBoxExistingPackage;
267 }
268
269 /**
270
271 @param args
272
273 **/
274 public static void main(String[] args) {
275
276 }
277
278 /**
279 * This is the default constructor
280 */
281 public Clone() {
282 super();
283 init();
284 }
285
286 /**
287 This is the default constructor
288
289 **/
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());
298 }
299 init(mode);
300 }
301
302 /**
303 Query all existing packages and fill them into combox
304
305 **/
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());
310 }
311 }
312
313 /**
314 * This method initializes this
315 *
316 * @return void
317 */
318 private void init() {
319 this.setSize(493, 260);
320 this.setContentPane(getJContentPane());
321 this.setTitle("Clone");
322 this.centerWindow();
323 }
324
325 /**
326 * This method initializes this
327 *
328 * @return void
329 */
330 private void init(int mode) {
331 init();
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");
339 }
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");
348 }
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");
356 }
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");
371 }
372 }
373
374 /**
375 * This method initializes jContentPane
376 *
377 * @return javax.swing.JPanel
378 */
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);
423 }
424 return jContentPane;
425 }
426
427 /* (non-Javadoc)
428 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
429 *
430 * Override actionPerformed to listen all actions
431 */
432 public void actionPerformed(ActionEvent arg0) {
433 if (arg0.getSource() == jButtonCancel) {
434 this.setVisible(false);
435 this.returnType = DataType.RETURN_TYPE_CANCEL;
436 }
437
438 if (arg0.getSource() == jButtonOk) {
439 if (this.check()) {
440 try {
441 this.save();
442 } catch (IOException e) {
443 Log.err("Clone", e.getMessage());
444 e.printStackTrace();
445 return;
446 } catch (XmlException e) {
447 Log.err("Clone", e.getMessage());
448 e.printStackTrace();
449 return;
450 } catch (Exception e) {
451 Log.err("Clone", e.getMessage());
452 e.printStackTrace();
453 return;
454 }
455 } else {
456 return;
457 }
458 this.setVisible(false);
459 }
460
461 if (arg0.getSource() == this.jButtonGenerateGuid) {
462 this.jTextFieldGuid.setText(Tools.generateUuidString());
463 }
464
465 //
466 // Use different file ext
467 //
468 if (arg0.getSource() == this.jButtonBrowse) {
469 JFileChooser fc = new JFileChooser();
470 fc.setAcceptAllFileFilterUsed(false);
471
472 if (mode == DataType.RETURN_TYPE_WORKSPACE) {
473 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
474 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
475 }
476 if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {
477 fc.setCurrentDirectory(new File(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())
478 .getPath()));
479 fc.addChoosableFileFilter(new IFileFilter(DataType.MODULE_SURFACE_AREA_EXT));
480 }
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));
484 }
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));
488 }
489 int result = fc.showSaveDialog(new JPanel());
490 if (result == JFileChooser.APPROVE_OPTION) {
491 this.jTextFieldFilePath.setText(Tools.addPathExt(fc.getSelectedFile().getPath(), mode));
492 }
493 }
494 }
495
496 //
497 // Check name, guid and version
498 //
499 private boolean checkId() {
500 //
501 // Check Basename
502 //
503 if (isEmpty(this.jTextFieldBaseName.getText())) {
504 Log.err("Base Name couldn't be empty!");
505 return false;
506 }
507 if (!DataValidation.isBaseName(this.jTextFieldBaseName.getText())) {
508 Log.err("Incorrect data type for Base Name");
509 return false;
510 }
511
512 //
513 // Check Guid
514 //
515 if (isEmpty(this.jTextFieldGuid.getText())) {
516 Log.err("Guid couldn't be empty!");
517 return false;
518 }
519 if (!DataValidation.isGuid(this.jTextFieldGuid.getText())) {
520 Log.err("Incorrect data type for Guid");
521 return false;
522 }
523
524 //
525 // Check Version
526 //
527 if (isEmpty(this.jTextFieldVersion.getText())) {
528 Log.err("Version couldn't be empty!");
529 return false;
530 }
531 if (!DataValidation.isVersion(this.jTextFieldVersion.getText())) {
532 Log.err("Incorrect data type for Version");
533 return false;
534 }
535
536 //
537 // Save information to id
538 //
539 newId.setName(this.jTextFieldBaseName.getText());
540 newId.setGuid(this.jTextFieldGuid.getText());
541 newId.setVersion(this.jTextFieldVersion.getText());
542 newId.setPath(this.jTextFieldFilePath.getText());
543
544 return true;
545 }
546
547 /**
548 Check before save
549
550 @return
551
552 **/
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);
558
559 //
560 // Common Check
561 //
562 if (!srcFile.exists()) {
563 Log.err("The source doesn't exist");
564 return false;
565 }
566 if (isEmpty(trg)) {
567 Log.err("The destination file path couldn't be empty");
568 return false;
569 }
570 if (src.equals(trg)) {
571 Log.err("The source and destination couldn't be same");
572 return false;
573 }
574 if (trgFile.exists()) {
575 Log.err("The destination already exists");
576 return false;
577 }
578
579 //
580 // Check for workspace
581 //
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!");
585 return false;
586 }
587 }
588
589 //
590 // Check for Module
591 //
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");
595 // return false;
596 // }
597 trg = this.getModulePath();
598 if (src.equals(trg)) {
599 Log.err("The source and destination couldn't be same");
600 return false;
601 }
602 trgFile = new File(trg);
603 if (trgFile.exists()) {
604 Log.err("The target module already exists");
605 return false;
606 }
607 return checkId();
608 }
609
610 //
611 // Check for Package
612 //
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");
616 return false;
617 }
618 trg = this.getPackagePath();
619 if (Tools.getFilePathOnly(src).equals(Tools.getFilePathOnly(trg))) {
620 Log.err("The source and destination couldn't be same");
621 return false;
622 }
623 trgFile = new File(trg);
624 if (trgFile.exists()) {
625 Log.err("The target package already exists");
626 return false;
627 }
628 return checkId();
629 }
630
631 //
632 // Check for Platform
633 //
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");
637 return false;
638 }
639 trgFile = new File(trg);
640 if (trgFile.exists()) {
641 Log.err("The target platform already exists");
642 return false;
643 }
644 return checkId();
645 }
646
647 return true;
648 }
649
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>();
654
655 //
656 // Clone Workspace
657 //
658 if (mode == DataType.RETURN_TYPE_WORKSPACE) {
659 try {
660 FileOperation.copyFolder(src, trg);
661 } catch (Exception e) {
662 this.returnType = DataType.RETURN_TYPE_CANCEL;
663 Log.err("Clone Workspace", e.getMessage());
664 e.printStackTrace();
665 }
666 this.returnType = DataType.RETURN_TYPE_WORKSPACE;
667 }
668
669 //
670 // Clone Module Surface Area
671 //
672 if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {
673 //
674 // Get target path from source path
675 //
676 trg = getModulePath();
677 newId.setPath(trg);
678 vFiles = wt.getAllModuleFilesPath(src);
679
680 //
681 // First copy all files to new directory
682 //
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);
688 }
689
690 //
691 // Create new msa file
692 //
693 ModuleSurfaceArea msa = null;
694 msa = OpenFile.openMsaFile(src);
695
696 //
697 // Update to memory
698 //
699 msa.getMsaHeader().setModuleName(newId.getName());
700 msa.getMsaHeader().setGuidValue(newId.getGuid());
701 msa.getMsaHeader().setVersion(newId.getVersion());
702
703 //
704 // Update Cloned From element
705 //
706 updateModuleClonedId(msa, oldId);
707
708 //
709 // Save to file
710 //
711 SaveFile.saveMsaFile(trg, msa);
712
713 //
714 // Update to platformId
715 //
716 this.setMid(new ModuleIdentification(newId, packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())));
717
718 //
719 // Open belonging package
720 //
721 PackageSurfaceArea psa = PackageSurfaceArea.Factory.newInstance();
722 psa = OpenFile.openSpdFile(mid.getPackageId().getPath());
723
724 //
725 // Update the db file
726 //
727 wt.addModuleToPackage(mid, psa);
728
729 this.returnType = DataType.RETURN_TYPE_MODULE_SURFACE_AREA;
730 }
731
732 //
733 // Clone Package Surface Area
734 //
735 if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {
736 //
737 // Get target path from source path
738 //
739 trg = this.getPackagePath();
740 newId.setPath(trg);
741 vFiles = wt.getAllPakcageFilesPath(src);
742
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);
748 }
749
750 //
751 // First copy all files to new directory
752 //
753 //FileOperation.copyFolder(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));
754
755 //
756 // Delete old spd file
757 //
758 //FileOperation.delFile(Tools.getFilePathOnly(trg) + DataType.FILE_SEPARATOR + Tools.getFileNameOnly(src));
759
760 //
761 // Create new spd file
762 //
763 PackageSurfaceArea spd = null;
764 spd = OpenFile.openSpdFile(src);
765
766 //
767 // Update to memory
768 //
769 spd.getSpdHeader().setPackageName(newId.getName());
770 spd.getSpdHeader().setGuidValue(newId.getGuid());
771 spd.getSpdHeader().setVersion(newId.getVersion());
772
773 //
774 // Update Cloned From element
775 //
776 updatePackageClonedId(spd, oldId);
777
778 //
779 // Save to file
780 //
781 SaveFile.saveSpdFile(trg, spd);
782
783 //
784 // Update to platformId
785 //
786 this.setPid(new PackageIdentification(newId));
787
788 //
789 // Update the db file
790 //
791 wt.addPackageToDatabase(pid);
792
793 this.returnType = DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA;
794 }
795
796 //
797 // Clone Platform Surface Area
798 //
799 if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {
800 PlatformSurfaceArea fpd = null;
801 fpd = OpenFile.openFpdFile(src);
802
803 //
804 // Update to memory
805 //
806 fpd.getPlatformHeader().setPlatformName(newId.getName());
807 fpd.getPlatformHeader().setGuidValue(newId.getGuid());
808 fpd.getPlatformHeader().setVersion(newId.getVersion());
809
810 //
811 // Update Cloned From element
812 //
813 updatePlatformClonedId(fpd, oldId);
814
815 //
816 // Save to file
817 //
818 SaveFile.saveFpdFile(trg, fpd);
819
820 //
821 // Update to platformId
822 //
823 this.setFid(new PlatformIdentification(newId));
824
825 //
826 // Update the db file
827 //
828 wt.addPlatformToDatabase(fid);
829
830 this.returnType = DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA;
831 }
832 vFiles = null;
833 }
834
835 private String getSelectPackagePath() {
836 return Tools.getFilePathOnly(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getPath());
837 }
838
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);
844 return trg;
845 }
846
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);
852 return trg;
853 }
854
855 /**
856 Set target item's Cloned From element
857
858 @param id
859 @return
860
861 **/
862 private void updateModuleClonedId(ModuleSurfaceArea msa, Identification id) {
863 //
864 // Get PlatformDefinitions First
865 //
866 ModuleDefinitions pd = null;
867 if (msa.getModuleDefinitions() == null) {
868 pd = ModuleDefinitions.Factory.newInstance();
869 msa.addNewModuleDefinitions();
870 } else {
871 pd = msa.getModuleDefinitions();
872 }
873
874 //
875 // Get ClonedFrom then
876 //
877 ModuleDefinitions.ClonedFrom cf = null;
878 BigInteger count = new BigInteger("-1");
879 if (pd.getClonedFrom() == null) {
880 cf = ModuleDefinitions.ClonedFrom.Factory.newInstance();
881 } else {
882 cf = pd.getClonedFrom();
883 if (cf != null) {
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());
887 }
888 }
889 }
890 }
891
892 //
893 // Set new Cloned item
894 //
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")));
901
902 cf.addNewCloned();
903 cf.setClonedArray(cf.getClonedList().size() - 1, c);
904 pd.addNewClonedFrom();
905 pd.setClonedFrom(cf);
906 msa.setModuleDefinitions(pd);
907 }
908
909 /**
910 Set target item's Cloned From element
911
912 @param id
913 @return
914
915 **/
916 private void updatePackageClonedId(PackageSurfaceArea spd, Identification id) {
917 //
918 // Get PlatformDefinitions First
919 //
920 PackageDefinitions pd = null;
921 if (spd.getPackageDefinitions() == null) {
922 pd = PackageDefinitions.Factory.newInstance();
923 spd.addNewPackageDefinitions();
924 } else {
925 pd = spd.getPackageDefinitions();
926 }
927
928 //
929 // Get ClonedFrom then
930 //
931 PackageDefinitions.ClonedFrom cf = null;
932 BigInteger count = new BigInteger("-1");
933 if (pd.getClonedFrom() == null) {
934 cf = PackageDefinitions.ClonedFrom.Factory.newInstance();
935 } else {
936 cf = pd.getClonedFrom();
937 if (cf != null) {
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());
941 }
942 }
943 }
944 }
945
946 //
947 // Set new Cloned item
948 //
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")));
953
954 cf.addNewCloned();
955 cf.setClonedArray(cf.getClonedList().size() - 1, c);
956 pd.addNewClonedFrom();
957 pd.setClonedFrom(cf);
958 spd.setPackageDefinitions(pd);
959 }
960
961 /**
962 Set target item's Cloned From element
963
964 @param id
965 @return
966
967 **/
968 private void updatePlatformClonedId(PlatformSurfaceArea fpd, Identification id) {
969 //
970 // Get PlatformDefinitions First
971 //
972 PlatformDefinitions pd = null;
973 if (fpd.getPlatformDefinitions() == null) {
974 pd = PlatformDefinitions.Factory.newInstance();
975 fpd.addNewPlatformDefinitions();
976 } else {
977 pd = fpd.getPlatformDefinitions();
978 }
979
980 //
981 // Get ClonedFrom then
982 //
983 PlatformDefinitions.ClonedFrom cf = null;
984 BigInteger count = new BigInteger("-1");
985 if (pd.getClonedFrom() == null) {
986 cf = PlatformDefinitions.ClonedFrom.Factory.newInstance();
987 } else {
988 cf = pd.getClonedFrom();
989 if (cf != null) {
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());
993 }
994 }
995 }
996 }
997
998 //
999 // Set new Cloned item
1000 //
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")));
1005
1006 cf.addNewCloned();
1007 cf.setClonedArray(cf.getClonedList().size() - 1, c);
1008 pd.addNewClonedFrom();
1009 pd.setClonedFrom(cf);
1010 fpd.setPlatformDefinitions(pd);
1011 }
1012
1013 public PlatformIdentification getFid() {
1014 return fid;
1015 }
1016
1017 public void setFid(PlatformIdentification fid) {
1018 this.fid = fid;
1019 }
1020
1021 public ModuleIdentification getMid() {
1022 return mid;
1023 }
1024
1025 public void setMid(ModuleIdentification mid) {
1026 this.mid = mid;
1027 }
1028
1029 public PackageIdentification getPid() {
1030 return pid;
1031 }
1032
1033 public void setPid(PackageIdentification pid) {
1034 this.pid = pid;
1035 }
1036 }