]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/Clone.java
Fixed a spelling error and changed the Package Headers Tab title to be Package Header...
[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(210, 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(210, 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(445, 85, 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(210, 85, 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(210, 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(210, 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(210, 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(285, 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(405, 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(445, 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(210, 60, 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(550, 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 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");
342 }
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");
354 }
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");
362 }
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");
377 }
378 }
379
380 /**
381 * This method initializes jContentPane
382 *
383 * @return javax.swing.JPanel
384 */
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);
429 }
430 return jContentPane;
431 }
432
433 /* (non-Javadoc)
434 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
435 *
436 * Override actionPerformed to listen all actions
437 */
438 public void actionPerformed(ActionEvent arg0) {
439 if (arg0.getSource() == jButtonCancel) {
440 this.setVisible(false);
441 this.returnType = DataType.RETURN_TYPE_CANCEL;
442 }
443
444 if (arg0.getSource() == jButtonOk) {
445 if (this.check()) {
446 try {
447 this.save();
448 } catch (IOException e) {
449 Log.err("Clone", e.getMessage());
450 e.printStackTrace();
451 return;
452 } catch (XmlException e) {
453 Log.err("Clone", e.getMessage());
454 e.printStackTrace();
455 return;
456 } catch (Exception e) {
457 Log.err("Clone", e.getMessage());
458 e.printStackTrace();
459 return;
460 }
461 } else {
462 return;
463 }
464 this.setVisible(false);
465 }
466
467 if (arg0.getSource() == this.jButtonGenerateGuid) {
468 this.jTextFieldGuid.setText(Tools.generateUuidString());
469 }
470
471 //
472 // Use different file ext
473 //
474 if (arg0.getSource() == this.jButtonBrowse) {
475 JFileChooser fc = new JFileChooser();
476 fc.setAcceptAllFileFilterUsed(false);
477
478 if (mode == DataType.RETURN_TYPE_WORKSPACE) {
479 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
480 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
481 }
482 if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {
483 fc.setCurrentDirectory(new File(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())
484 .getPath()));
485 fc.addChoosableFileFilter(new IFileFilter(DataType.MODULE_SURFACE_AREA_EXT));
486 }
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));
490 }
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));
494 }
495 int result = fc.showSaveDialog(new JPanel());
496 if (result == JFileChooser.APPROVE_OPTION) {
497 this.jTextFieldFilePath.setText(Tools.addPathExt(fc.getSelectedFile().getPath(), mode));
498 }
499 }
500 }
501
502 //
503 // Check name, guid and version
504 //
505 private boolean checkId() {
506 //
507 // Check Basename
508 //
509 if (isEmpty(this.jTextFieldBaseName.getText())) {
510 Log.err("Base Name couldn't be empty!");
511 return false;
512 }
513 if (!DataValidation.isBaseName(this.jTextFieldBaseName.getText())) {
514 Log.err("Incorrect data type for Base Name");
515 return false;
516 }
517
518 //
519 // Check Guid
520 //
521 if (isEmpty(this.jTextFieldGuid.getText())) {
522 Log.err("Guid couldn't be empty!");
523 return false;
524 }
525 if (!DataValidation.isGuid(this.jTextFieldGuid.getText())) {
526 Log.err("Incorrect data type for Guid");
527 return false;
528 }
529
530 //
531 // Check Version
532 //
533 if (isEmpty(this.jTextFieldVersion.getText())) {
534 Log.err("Version couldn't be empty!");
535 return false;
536 }
537 if (!DataValidation.isVersion(this.jTextFieldVersion.getText())) {
538 Log.err("Incorrect data type for Version");
539 return false;
540 }
541
542 //
543 // Save information to id
544 //
545 newId.setName(this.jTextFieldBaseName.getText());
546 newId.setGuid(this.jTextFieldGuid.getText());
547 newId.setVersion(this.jTextFieldVersion.getText());
548 newId.setPath(this.jTextFieldFilePath.getText());
549
550 return true;
551 }
552
553 /**
554 Check before save
555
556 @return
557
558 **/
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);
564
565 //
566 // Common Check
567 //
568 if (!srcFile.exists()) {
569 Log.err("The source doesn't exist");
570 return false;
571 }
572 if (isEmpty(trg)) {
573 Log.err("The destination file path couldn't be empty");
574 return false;
575 }
576 if (src.equals(trg)) {
577 Log.err("The source and destination couldn't be same");
578 return false;
579 }
580 if (trgFile.exists()) {
581 Log.err("The destination already exists");
582 return false;
583 }
584
585 //
586 // Check for workspace
587 //
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!");
591 return false;
592 }
593 }
594
595 //
596 // Check for Module
597 //
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");
601 // return false;
602 // }
603 trg = this.getModulePath();
604 if (src.equals(trg)) {
605 Log.err("The source and destination couldn't be same");
606 return false;
607 }
608 trgFile = new File(trg);
609 if (trgFile.exists()) {
610 Log.err("The target module already exists");
611 return false;
612 }
613 return checkId();
614 }
615
616 //
617 // Check for Package
618 //
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");
622 return false;
623 }
624 trg = this.getPackagePath();
625 if (Tools.getFilePathOnly(src).equals(Tools.getFilePathOnly(trg))) {
626 Log.err("The source and destination couldn't be same");
627 return false;
628 }
629 trgFile = new File(trg);
630 if (trgFile.exists()) {
631 Log.err("The target package already exists");
632 return false;
633 }
634 return checkId();
635 }
636
637 //
638 // Check for Platform
639 //
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");
643 return false;
644 }
645 trgFile = new File(trg);
646 if (trgFile.exists()) {
647 Log.err("The target platform already exists");
648 return false;
649 }
650 return checkId();
651 }
652
653 return true;
654 }
655
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>();
660
661 //
662 // Clone Workspace
663 //
664 if (mode == DataType.RETURN_TYPE_WORKSPACE) {
665 try {
666 FileOperation.copyFolder(src, trg);
667 } catch (Exception e) {
668 this.returnType = DataType.RETURN_TYPE_CANCEL;
669 Log.err("Clone Workspace", e.getMessage());
670 e.printStackTrace();
671 }
672 this.returnType = DataType.RETURN_TYPE_WORKSPACE;
673 }
674
675 //
676 // Clone Module Surface Area
677 //
678 if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {
679 //
680 // Get target path from source path
681 //
682 trg = getModulePath();
683 newId.setPath(trg);
684 vFiles = wt.getAllModuleFilesPath(src);
685
686 //
687 // First copy all files to new directory
688 //
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);
694 }
695
696 //
697 // Create new msa file
698 //
699 ModuleSurfaceArea msa = null;
700 msa = OpenFile.openMsaFile(src);
701
702 //
703 // Update to memory
704 //
705 msa.getMsaHeader().setModuleName(newId.getName());
706 msa.getMsaHeader().setGuidValue(newId.getGuid());
707 msa.getMsaHeader().setVersion(newId.getVersion());
708
709 //
710 // Update Cloned From element
711 //
712 updateModuleClonedId(msa, oldId);
713
714 //
715 // Save to file
716 //
717 SaveFile.saveMsaFile(trg, msa);
718
719 //
720 // Update to platformId
721 //
722 this.setMid(new ModuleIdentification(newId, packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())));
723
724 //
725 // Open belonging package
726 //
727 PackageSurfaceArea psa = PackageSurfaceArea.Factory.newInstance();
728 psa = OpenFile.openSpdFile(mid.getPackageId().getPath());
729
730 //
731 // Update the db file
732 //
733 wt.addModuleToPackage(mid, psa);
734
735 this.returnType = DataType.RETURN_TYPE_MODULE_SURFACE_AREA;
736 }
737
738 //
739 // Clone Package Surface Area
740 //
741 if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {
742 //
743 // Get target path from source path
744 //
745 trg = this.getPackagePath();
746 newId.setPath(trg);
747 vFiles = wt.getAllPakcageFilesPath(src);
748
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);
754 }
755
756 //
757 // First copy all files to new directory
758 //
759 //FileOperation.copyFolder(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));
760
761 //
762 // Delete old spd file
763 //
764 //FileOperation.delFile(Tools.getFilePathOnly(trg) + DataType.FILE_SEPARATOR + Tools.getFileNameOnly(src));
765
766 //
767 // Create new spd file
768 //
769 PackageSurfaceArea spd = null;
770 spd = OpenFile.openSpdFile(src);
771
772 //
773 // Update to memory
774 //
775 spd.getSpdHeader().setPackageName(newId.getName());
776 spd.getSpdHeader().setGuidValue(newId.getGuid());
777 spd.getSpdHeader().setVersion(newId.getVersion());
778
779 //
780 // Update Cloned From element
781 //
782 updatePackageClonedId(spd, oldId);
783
784 //
785 // Save to file
786 //
787 SaveFile.saveSpdFile(trg, spd);
788
789 //
790 // Update to platformId
791 //
792 this.setPid(new PackageIdentification(newId));
793
794 //
795 // Update the db file
796 //
797 wt.addPackageToDatabase(pid);
798
799 this.returnType = DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA;
800 }
801
802 //
803 // Clone Platform Surface Area
804 //
805 if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {
806 PlatformSurfaceArea fpd = null;
807 fpd = OpenFile.openFpdFile(src);
808
809 //
810 // Update to memory
811 //
812 fpd.getPlatformHeader().setPlatformName(newId.getName());
813 fpd.getPlatformHeader().setGuidValue(newId.getGuid());
814 fpd.getPlatformHeader().setVersion(newId.getVersion());
815
816 //
817 // Update Cloned From element
818 //
819 updatePlatformClonedId(fpd, oldId);
820
821 //
822 // Save to file
823 //
824 SaveFile.saveFpdFile(trg, fpd);
825
826 //
827 // Update to platformId
828 //
829 this.setFid(new PlatformIdentification(newId));
830
831 //
832 // Update the db file
833 //
834 wt.addPlatformToDatabase(fid);
835
836 this.returnType = DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA;
837 }
838 vFiles = null;
839 }
840
841 private String getSelectPackagePath() {
842 return Tools.getFilePathOnly(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getPath());
843 }
844
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);
850 return trg;
851 }
852
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);
858 return trg;
859 }
860
861 /**
862 Set target item's Cloned From element
863
864 @param id
865 @return
866
867 **/
868 private void updateModuleClonedId(ModuleSurfaceArea msa, Identification id) {
869 //
870 // Get PlatformDefinitions First
871 //
872 ModuleDefinitions pd = null;
873 if (msa.getModuleDefinitions() == null) {
874 pd = ModuleDefinitions.Factory.newInstance();
875 msa.addNewModuleDefinitions();
876 } else {
877 pd = msa.getModuleDefinitions();
878 }
879
880 //
881 // Get ClonedFrom then
882 //
883 ModuleDefinitions.ClonedFrom cf = null;
884 BigInteger count = new BigInteger("-1");
885 if (pd.getClonedFrom() == null) {
886 cf = ModuleDefinitions.ClonedFrom.Factory.newInstance();
887 } else {
888 cf = pd.getClonedFrom();
889 if (cf != null) {
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());
893 }
894 }
895 }
896 }
897
898 //
899 // Set new Cloned item
900 //
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("")) {
909 c.setFarGuid(guid);
910 }
911
912 cf.addNewCloned();
913 cf.setClonedArray(cf.getClonedList().size() - 1, c);
914 pd.addNewClonedFrom();
915 pd.setClonedFrom(cf);
916 msa.setModuleDefinitions(pd);
917 }
918
919 /**
920 Set target item's Cloned From element
921
922 @param id
923 @return
924
925 **/
926 private void updatePackageClonedId(PackageSurfaceArea spd, Identification id) {
927 //
928 // Get PlatformDefinitions First
929 //
930 PackageDefinitions pd = null;
931 if (spd.getPackageDefinitions() == null) {
932 pd = PackageDefinitions.Factory.newInstance();
933 spd.addNewPackageDefinitions();
934 } else {
935 pd = spd.getPackageDefinitions();
936 }
937
938 //
939 // Get ClonedFrom then
940 //
941 PackageDefinitions.ClonedFrom cf = null;
942 BigInteger count = new BigInteger("-1");
943 if (pd.getClonedFrom() == null) {
944 cf = PackageDefinitions.ClonedFrom.Factory.newInstance();
945 } else {
946 cf = pd.getClonedFrom();
947 if (cf != null) {
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());
951 }
952 }
953 }
954 }
955
956 //
957 // Set new Cloned item
958 //
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("")) {
965 c.setFarGuid(guid);
966 }
967
968 cf.addNewCloned();
969 cf.setClonedArray(cf.getClonedList().size() - 1, c);
970 pd.addNewClonedFrom();
971 pd.setClonedFrom(cf);
972 spd.setPackageDefinitions(pd);
973 }
974
975 /**
976 Set target item's Cloned From element
977
978 @param id
979 @return
980
981 **/
982 private void updatePlatformClonedId(PlatformSurfaceArea fpd, Identification id) {
983 //
984 // Get PlatformDefinitions First
985 //
986 PlatformDefinitions pd = null;
987 if (fpd.getPlatformDefinitions() == null) {
988 pd = PlatformDefinitions.Factory.newInstance();
989 fpd.addNewPlatformDefinitions();
990 } else {
991 pd = fpd.getPlatformDefinitions();
992 }
993
994 //
995 // Get ClonedFrom then
996 //
997 PlatformDefinitions.ClonedFrom cf = null;
998 BigInteger count = new BigInteger("-1");
999 if (pd.getClonedFrom() == null) {
1000 cf = PlatformDefinitions.ClonedFrom.Factory.newInstance();
1001 } else {
1002 cf = pd.getClonedFrom();
1003 if (cf != null) {
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());
1007 }
1008 }
1009 }
1010 }
1011
1012 //
1013 // Set new Cloned item
1014 //
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("")) {
1021 c.setFarGuid(guid);
1022 }
1023
1024 cf.addNewCloned();
1025 cf.setClonedArray(cf.getClonedList().size() - 1, c);
1026 pd.addNewClonedFrom();
1027 pd.setClonedFrom(cf);
1028 fpd.setPlatformDefinitions(pd);
1029 }
1030
1031 public PlatformIdentification getFid() {
1032 return fid;
1033 }
1034
1035 public void setFid(PlatformIdentification fid) {
1036 this.fid = fid;
1037 }
1038
1039 public ModuleIdentification getMid() {
1040 return mid;
1041 }
1042
1043 public void setMid(ModuleIdentification mid) {
1044 this.mid = mid;
1045 }
1046
1047 public PackageIdentification getPid() {
1048 return pid;
1049 }
1050
1051 public void setPid(PackageIdentification pid) {
1052 this.pid = pid;
1053 }
1054 }