]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/Clone.java
Added "/FI", "-include" and/or "/nologo" options to PP (CC) command option to fpd...
[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.util.Vector;
21
22 import javax.swing.JFileChooser;
23 import javax.swing.JPanel;
24 import javax.swing.JLabel;
25 import javax.swing.JTextField;
26 import javax.swing.JButton;
27
28 import org.apache.xmlbeans.XmlException;
29 import org.tianocore.ModuleDefinitionsDocument.ModuleDefinitions;
30 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
31 import org.tianocore.PackageDefinitionsDocument.PackageDefinitions;
32 import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;
33 import org.tianocore.PlatformDefinitionsDocument.PlatformDefinitions;
34 import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;
35 import org.tianocore.frameworkwizard.common.DataType;
36 import org.tianocore.frameworkwizard.common.DataValidation;
37 import org.tianocore.frameworkwizard.common.FileOperation;
38 import org.tianocore.frameworkwizard.common.IFileFilter;
39 import org.tianocore.frameworkwizard.common.Identification;
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.ui.IDialog;
45 import org.tianocore.frameworkwizard.common.ui.IFrame;
46 import org.tianocore.frameworkwizard.module.Identification.ModuleIdentification;
47 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
48 import org.tianocore.frameworkwizard.platform.PlatformIdentification;
49 import org.tianocore.frameworkwizard.workspace.Workspace;
50 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
51 import javax.swing.JComboBox;
52
53 public class Clone extends IDialog {
54
55 /**
56 Define class members
57
58 **/
59 private static final long serialVersionUID = -5469299324965727137L;
60
61 private JPanel jContentPane = null;
62
63 private JLabel jLabelType = null;
64
65 private JTextField jTextFieldType = null;
66
67 private JLabel jLabelSource = null;
68
69 private JTextField jTextFieldSource = null;
70
71 private JButton jButtonBrowse = null;
72
73 private JLabel jLabelDestinationFile = null;
74
75 private JTextField jTextFieldFilePath = null;
76
77 private JLabel jLabelBaseName = null;
78
79 private JTextField jTextFieldBaseName = null;
80
81 private JLabel jLabelGuid = null;
82
83 private JTextField jTextFieldGuid = null;
84
85 private JLabel jLabelVersion = null;
86
87 private JTextField jTextFieldVersion = null;
88
89 private JButton jButtonOk = null;
90
91 private JButton jButtonCancel = null;
92
93 private JButton jButtonGenerateGuid = null;
94
95 private int mode = -1;
96
97 private Vector<PackageIdentification> packages = null;
98
99 private WorkspaceTools wt = new WorkspaceTools();
100
101 private JLabel jLabelBelong = null;
102
103 private JComboBox jComboBoxExistingPackage = null;
104
105 private Identification oldId = null;
106
107 private Identification newId = null;
108
109 private ModuleIdentification mid = null;
110
111 private PackageIdentification pid = null;
112
113 private PlatformIdentification fid = null;
114
115 /**
116 * This method initializes jTextFieldType
117 *
118 * @return javax.swing.JTextField
119 */
120 private JTextField getJTextFieldType() {
121 if (jTextFieldType == null) {
122 jTextFieldType = new JTextField();
123 jTextFieldType.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
124 jTextFieldType.setEditable(false);
125 }
126 return jTextFieldType;
127 }
128
129 /**
130 * This method initializes jTextFieldSource
131 *
132 * @return javax.swing.JTextField
133 */
134 private JTextField getJTextFieldSource() {
135 if (jTextFieldSource == null) {
136 jTextFieldSource = new JTextField();
137 jTextFieldSource.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
138 jTextFieldSource.setEditable(false);
139 }
140 return jTextFieldSource;
141 }
142
143 /**
144 * This method initializes jButtonBrowse
145 *
146 * @return javax.swing.JButton
147 */
148 private JButton getJButtonBrowse() {
149 if (jButtonBrowse == null) {
150 jButtonBrowse = new JButton();
151 jButtonBrowse.setBounds(new java.awt.Rectangle(395, 60, 85, 20));
152 jButtonBrowse.setText("Browse");
153 jButtonBrowse.addActionListener(this);
154 }
155 return jButtonBrowse;
156 }
157
158 /**
159 * This method initializes jTextFieldDestinationFile
160 *
161 * @return javax.swing.JTextField
162 */
163 private JTextField getJTextFieldFilePath() {
164 if (jTextFieldFilePath == null) {
165 jTextFieldFilePath = new JTextField();
166 jTextFieldFilePath.setBounds(new java.awt.Rectangle(160, 60, 230, 20));
167 }
168 return jTextFieldFilePath;
169 }
170
171 /**
172 * This method initializes jTextFieldBaseName
173 *
174 * @return javax.swing.JTextField
175 */
176 private JTextField getJTextFieldBaseName() {
177 if (jTextFieldBaseName == null) {
178 jTextFieldBaseName = new JTextField();
179 jTextFieldBaseName.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
180 }
181 return jTextFieldBaseName;
182 }
183
184 /**
185 * This method initializes jTextFieldGuid
186 *
187 * @return javax.swing.JTextField
188 */
189 private JTextField getJTextFieldGuid() {
190 if (jTextFieldGuid == null) {
191 jTextFieldGuid = new JTextField();
192 jTextFieldGuid.setBounds(new java.awt.Rectangle(160, 135, 230, 20));
193 }
194 return jTextFieldGuid;
195 }
196
197 /**
198 * This method initializes jTextFieldVersion
199 *
200 * @return javax.swing.JTextField
201 */
202 private JTextField getJTextFieldVersion() {
203 if (jTextFieldVersion == null) {
204 jTextFieldVersion = new JTextField();
205 jTextFieldVersion.setBounds(new java.awt.Rectangle(160, 160, 320, 20));
206 }
207 return jTextFieldVersion;
208 }
209
210 /**
211 * This method initializes jButtonOk
212 *
213 * @return javax.swing.JButton
214 */
215 private JButton getJButtonOk() {
216 if (jButtonOk == null) {
217 jButtonOk = new JButton();
218 jButtonOk.setBounds(new java.awt.Rectangle(235, 200, 90, 20));
219 jButtonOk.setText("Ok");
220 jButtonOk.addActionListener(this);
221 }
222 return jButtonOk;
223 }
224
225 /**
226 * This method initializes jButtonCancel
227 *
228 * @return javax.swing.JButton
229 */
230 private JButton getJButtonCancel() {
231 if (jButtonCancel == null) {
232 jButtonCancel = new JButton();
233 jButtonCancel.setBounds(new java.awt.Rectangle(355, 200, 90, 20));
234 jButtonCancel.setText("Cancel");
235 jButtonCancel.addActionListener(this);
236 }
237 return jButtonCancel;
238 }
239
240 /**
241 * This method initializes jButtonGenerateGuid
242 *
243 * @return javax.swing.JButton
244 */
245 private JButton getJButtonGenerateGuid() {
246 if (jButtonGenerateGuid == null) {
247 jButtonGenerateGuid = new JButton();
248 jButtonGenerateGuid.setBounds(new java.awt.Rectangle(395, 135, 85, 20));
249 jButtonGenerateGuid.setText("Gen");
250 jButtonGenerateGuid.addActionListener(this);
251 }
252 return jButtonGenerateGuid;
253 }
254
255 /**
256 * This method initializes jComboBoxExistingPackage
257 *
258 * @return javax.swing.JComboBox
259 */
260 private JComboBox getJComboBoxExistingPackage() {
261 if (jComboBoxExistingPackage == null) {
262 jComboBoxExistingPackage = new JComboBox();
263 jComboBoxExistingPackage.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
264 }
265 return jComboBoxExistingPackage;
266 }
267
268 /**
269
270 @param args
271
272 **/
273 public static void main(String[] args) {
274
275 }
276
277 /**
278 * This is the default constructor
279 */
280 public Clone() {
281 super();
282 init();
283 }
284
285 /**
286 This is the default constructor
287
288 **/
289 public Clone(IFrame parentFrame, boolean modal, int fileType, Identification identification) {
290 super(parentFrame, modal);
291 this.mode = fileType;
292 if (identification != null) {
293 this.oldId = new Identification(identification.getName(), identification.getGuid(),
294 identification.getVersion(), identification.getPath());
295 this.newId = new Identification(identification.getName(), identification.getGuid(),
296 identification.getVersion(), identification.getPath());
297 }
298 init(mode);
299 }
300
301 /**
302 Query all existing packages and fill them into combox
303
304 **/
305 private void initExistingPackage() {
306 packages = wt.getAllPackages();
307 for (int index = 0; index < packages.size(); index++) {
308 this.jComboBoxExistingPackage.addItem(packages.elementAt(index).getName());
309 }
310 }
311
312 /**
313 * This method initializes this
314 *
315 * @return void
316 */
317 private void init() {
318 this.setSize(493, 260);
319 this.setContentPane(getJContentPane());
320 this.setTitle("Clone");
321 this.centerWindow();
322 }
323
324 /**
325 * This method initializes this
326 *
327 * @return void
328 */
329 private void init(int mode) {
330 init();
331 if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {
332 this.jTextFieldType.setText(DataType.MODULE_SURFACE_AREA);
333 this.jTextFieldSource.setText(oldId.getPath());
334 initExistingPackage();
335 this.jButtonBrowse.setEnabled(false);
336 this.jTextFieldFilePath.setToolTipText("Input module name here. For example, Application\\HelloWorld\\HelloWorld.msa");
337 this.jLabelDestinationFile.setText("Module Path\\Name");
338 }
339 if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {
340 this.jTextFieldType.setText(DataType.PACKAGE_SURFACE_AREA);
341 this.jTextFieldSource.setText(oldId.getPath());
342 this.jLabelBelong.setEnabled(false);
343 this.jComboBoxExistingPackage.setEnabled(false);
344 this.jButtonBrowse.setEnabled(false);
345 this.jTextFieldFilePath.setToolTipText("Input package name here. For example, MdePkg\\MdePkg.fpd");
346 this.jLabelDestinationFile.setText("Package Path\\Name");
347 }
348 if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {
349 this.jTextFieldType.setText(DataType.PLATFORM_SURFACE_AREA);
350 this.jTextFieldSource.setText(oldId.getPath());
351 this.jLabelBelong.setEnabled(false);
352 this.jComboBoxExistingPackage.setEnabled(false);
353 this.jTextFieldFilePath.setToolTipText("Select platform path here. For example, C:\\MyWorkspace\\EdkNt32Pkg\\Nt32.fpd");
354 this.jLabelDestinationFile.setText("New Platform path");
355 }
356 if (mode == DataType.RETURN_TYPE_WORKSPACE) {
357 this.jTextFieldType.setText(DataType.WORKSPACE);
358 this.jTextFieldSource.setText(Workspace.getCurrentWorkspace());
359 this.jLabelBelong.setEnabled(false);
360 this.jComboBoxExistingPackage.setEnabled(false);
361 this.jLabelBaseName.setEnabled(false);
362 this.jTextFieldBaseName.setEditable(false);
363 this.jLabelGuid.setEnabled(false);
364 this.jTextFieldGuid.setEnabled(false);
365 this.jButtonGenerateGuid.setEnabled(false);
366 this.jLabelVersion.setEnabled(false);
367 this.jTextFieldVersion.setEnabled(false);
368 this.jTextFieldFilePath.setToolTipText("Input workspace path here. For example, C:\\MyWorkspace");
369 this.jLabelDestinationFile.setText("New Workspace path");
370 }
371 }
372
373 /**
374 * This method initializes jContentPane
375 *
376 * @return javax.swing.JPanel
377 */
378 private JPanel getJContentPane() {
379 if (jContentPane == null) {
380 jLabelBelong = new JLabel();
381 jLabelBelong.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
382 jLabelBelong.setText("Clone to Package");
383 jLabelVersion = new JLabel();
384 jLabelVersion.setBounds(new java.awt.Rectangle(15, 160, 140, 20));
385 jLabelVersion.setText("Version");
386 jLabelGuid = new JLabel();
387 jLabelGuid.setBounds(new java.awt.Rectangle(15, 135, 140, 20));
388 jLabelGuid.setText("Guid");
389 jLabelBaseName = new JLabel();
390 jLabelBaseName.setBounds(new java.awt.Rectangle(15, 110, 140, 20));
391 jLabelBaseName.setText("Base Name");
392 jLabelDestinationFile = new JLabel();
393 jLabelDestinationFile.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
394 jLabelDestinationFile.setText("Destination File Name");
395 jLabelSource = new JLabel();
396 jLabelSource.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
397 jLabelSource.setText("Source");
398 jLabelType = new JLabel();
399 jLabelType.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
400 jLabelType.setText("Type");
401 jContentPane = new JPanel();
402 jContentPane.setLayout(null);
403 jContentPane.setSize(new java.awt.Dimension(490, 227));
404 jContentPane.add(jLabelType, null);
405 jContentPane.add(getJTextFieldType(), null);
406 jContentPane.add(jLabelSource, null);
407 jContentPane.add(getJTextFieldSource(), null);
408 jContentPane.add(jLabelDestinationFile, null);
409 jContentPane.add(getJTextFieldFilePath(), null);
410 jContentPane.add(jLabelBaseName, null);
411 jContentPane.add(getJTextFieldBaseName(), null);
412 jContentPane.add(jLabelGuid, null);
413 jContentPane.add(getJTextFieldGuid(), null);
414 jContentPane.add(jLabelVersion, null);
415 jContentPane.add(getJTextFieldVersion(), null);
416 jContentPane.add(getJButtonOk(), null);
417 jContentPane.add(getJButtonCancel(), null);
418 jContentPane.add(getJButtonBrowse(), null);
419 jContentPane.add(getJButtonGenerateGuid(), null);
420 jContentPane.add(jLabelBelong, null);
421 jContentPane.add(getJComboBoxExistingPackage(), null);
422 }
423 return jContentPane;
424 }
425
426 /* (non-Javadoc)
427 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
428 *
429 * Override actionPerformed to listen all actions
430 */
431 public void actionPerformed(ActionEvent arg0) {
432 if (arg0.getSource() == jButtonCancel) {
433 this.setVisible(false);
434 this.returnType = DataType.RETURN_TYPE_CANCEL;
435 }
436
437 if (arg0.getSource() == jButtonOk) {
438 if (this.check()) {
439 try {
440 this.save();
441 } catch (IOException e) {
442 Log.err("Clone", e.getMessage());
443 e.printStackTrace();
444 return;
445 } catch (XmlException e) {
446 Log.err("Clone", e.getMessage());
447 e.printStackTrace();
448 return;
449 } catch (Exception e) {
450 Log.err("Clone", e.getMessage());
451 e.printStackTrace();
452 return;
453 }
454 } else {
455 return;
456 }
457 this.setVisible(false);
458 }
459
460 if (arg0.getSource() == this.jButtonGenerateGuid) {
461 this.jTextFieldGuid.setText(Tools.generateUuidString());
462 }
463
464 //
465 // Use different file ext
466 //
467 if (arg0.getSource() == this.jButtonBrowse) {
468 JFileChooser fc = new JFileChooser();
469 fc.setAcceptAllFileFilterUsed(false);
470
471 if (mode == DataType.RETURN_TYPE_WORKSPACE) {
472 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
473 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
474 }
475 if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {
476 fc.setCurrentDirectory(new File(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())
477 .getPath()));
478 fc.addChoosableFileFilter(new IFileFilter(DataType.MODULE_SURFACE_AREA_EXT));
479 }
480 if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {
481 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
482 fc.addChoosableFileFilter(new IFileFilter(DataType.PACKAGE_SURFACE_AREA_EXT));
483 }
484 if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {
485 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
486 fc.addChoosableFileFilter(new IFileFilter(DataType.PLATFORM_SURFACE_AREA_EXT));
487 }
488 int result = fc.showSaveDialog(new JPanel());
489 if (result == JFileChooser.APPROVE_OPTION) {
490 this.jTextFieldFilePath.setText(Tools.addPathExt(fc.getSelectedFile().getPath(), mode));
491 }
492 }
493 }
494
495 //
496 // Check name, guid and version
497 //
498 private boolean checkId() {
499 //
500 // Check Basename
501 //
502 if (isEmpty(this.jTextFieldBaseName.getText())) {
503 Log.err("Base Name couldn't be empty!");
504 return false;
505 }
506 if (!DataValidation.isBaseName(this.jTextFieldBaseName.getText())) {
507 Log.err("Incorrect data type for Base Name");
508 return false;
509 }
510
511 //
512 // Check Guid
513 //
514 if (isEmpty(this.jTextFieldGuid.getText())) {
515 Log.err("Guid couldn't be empty!");
516 return false;
517 }
518 if (!DataValidation.isGuid(this.jTextFieldGuid.getText())) {
519 Log.err("Incorrect data type for Guid");
520 return false;
521 }
522
523 //
524 // Check Version
525 //
526 if (isEmpty(this.jTextFieldVersion.getText())) {
527 Log.err("Version couldn't be empty!");
528 return false;
529 }
530 if (!DataValidation.isVersion(this.jTextFieldVersion.getText())) {
531 Log.err("Incorrect data type for Version");
532 return false;
533 }
534
535 //
536 // Save information to id
537 //
538 newId.setName(this.jTextFieldBaseName.getText());
539 newId.setGuid(this.jTextFieldGuid.getText());
540 newId.setVersion(this.jTextFieldVersion.getText());
541 newId.setPath(this.jTextFieldFilePath.getText());
542
543 return true;
544 }
545
546 /**
547 Check before save
548
549 @return
550
551 **/
552 private boolean check() {
553 String src = this.jTextFieldSource.getText();
554 String trg = this.jTextFieldFilePath.getText();
555 File srcFile = new File(src);
556 File trgFile = new File(trg);
557
558 //
559 // Common Check
560 //
561 if (!srcFile.exists()) {
562 Log.err("The source doesn't exist");
563 return false;
564 }
565 if (isEmpty(trg)) {
566 Log.err("The destination file path couldn't be empty");
567 return false;
568 }
569 if (src.equals(trg)) {
570 Log.err("The source and destination couldn't be same");
571 return false;
572 }
573 if (trgFile.exists()) {
574 Log.err("The destination already exists");
575 return false;
576 }
577
578 //
579 // Check for workspace
580 //
581 if (mode == DataType.RETURN_TYPE_WORKSPACE) {
582 if (trg.indexOf(src + DataType.FILE_SEPARATOR) == 0) {
583 Log.err("The new workspace couldn't be in current workspace!");
584 return false;
585 }
586 }
587
588 //
589 // Check for Module
590 //
591 if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {
592 return checkId();
593 }
594
595 //
596 // Check for Package
597 //
598 if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {
599 if (trg.indexOf(DataType.DOS_FILE_SEPARATOR) == -1 && trg.indexOf(DataType.UNIX_FILE_SEPARATOR) == -1) {
600 Log.err("The package name must include a path");
601 return false;
602 }
603 trg = this.getPackagePath();
604 if (Tools.getFilePathOnly(src).equals(Tools.getFilePathOnly(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 package already exists");
611 return false;
612 }
613 return checkId();
614 }
615
616 //
617 // Check for Platform
618 //
619 if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {
620 if (trg.indexOf(Workspace.getCurrentWorkspace()) != 0) {
621 Log.err("The target platform must be in current workspace");
622 return false;
623 }
624 trgFile = new File(trg);
625 if (trgFile.exists()) {
626 Log.err("The target platform already exists");
627 return false;
628 }
629 return checkId();
630 }
631
632 return true;
633 }
634
635 private void save() throws IOException, XmlException, Exception {
636 String src = this.jTextFieldSource.getText();
637 String trg = this.jTextFieldFilePath.getText();
638
639 //
640 // Clone Workspace
641 //
642 if (mode == DataType.RETURN_TYPE_WORKSPACE) {
643 try {
644 FileOperation.copyFolder(src, trg);
645 } catch (Exception e) {
646 this.returnType = DataType.RETURN_TYPE_CANCEL;
647 Log.err("Clone Workspace", e.getMessage());
648 e.printStackTrace();
649 }
650 this.returnType = DataType.RETURN_TYPE_WORKSPACE;
651 }
652
653 //
654 // Clone Module Surface Area
655 //
656 if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {
657 //
658 // Get target path from source path
659 //
660 trg = getModulePath();
661 newId.setPath(trg);
662
663 //
664 // First copy all files to new directory
665 //
666 FileOperation.copyFolder(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));
667
668 //
669 // Delete old spd file
670 //
671 FileOperation.delFile(Tools.getFilePathOnly(trg) + DataType.FILE_SEPARATOR + Tools.getFileNameOnly(src));
672
673 //
674 // Create new msa file
675 //
676 ModuleSurfaceArea msa = null;
677 msa = OpenFile.openMsaFile(src);
678
679 //
680 // Update to memory
681 //
682 msa.getMsaHeader().setModuleName(newId.getName());
683 msa.getMsaHeader().setGuidValue(newId.getGuid());
684 msa.getMsaHeader().setVersion(newId.getVersion());
685
686 //
687 // Update Cloned From element
688 //
689 updateModuleClonedId(msa, oldId);
690
691 //
692 // Save to file
693 //
694 SaveFile.saveMsaFile(trg, msa);
695
696 //
697 // Update to platformId
698 //
699 this.setMid(new ModuleIdentification(newId, packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())));
700
701 //
702 // Open belonging package
703 //
704 PackageSurfaceArea psa = PackageSurfaceArea.Factory.newInstance();
705 psa = OpenFile.openSpdFile(mid.getPackageId().getPath());
706
707 //
708 // Update the db file
709 //
710 wt.addModuleToPackage(mid, psa);
711
712 this.returnType = DataType.RETURN_TYPE_MODULE_SURFACE_AREA;
713 }
714
715 //
716 // Clone Package Surface Area
717 //
718 if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {
719 //
720 // Get target path from source path
721 //
722 trg = this.getPackagePath();
723 newId.setPath(trg);
724
725 //
726 // First copy all files to new directory
727 //
728 FileOperation.copyFolder(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));
729
730 //
731 // Delete old spd file
732 //
733 FileOperation.delFile(Tools.getFilePathOnly(trg) + DataType.FILE_SEPARATOR + Tools.getFileNameOnly(src));
734
735 //
736 // Create new spd file
737 //
738 PackageSurfaceArea spd = null;
739 spd = OpenFile.openSpdFile(src);
740
741 //
742 // Update to memory
743 //
744 spd.getSpdHeader().setPackageName(newId.getName());
745 spd.getSpdHeader().setGuidValue(newId.getGuid());
746 spd.getSpdHeader().setVersion(newId.getVersion());
747
748 //
749 // Update Cloned From element
750 //
751 updatePackageClonedId(spd, oldId);
752
753 //
754 // Save to file
755 //
756 SaveFile.saveSpdFile(trg, spd);
757
758 //
759 // Update to platformId
760 //
761 this.setPid(new PackageIdentification(newId));
762
763 //
764 // Update the db file
765 //
766 wt.addPackageToDatabase(pid);
767
768 this.returnType = DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA;
769 }
770
771 //
772 // Clone Platform Surface Area
773 //
774 if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {
775 PlatformSurfaceArea fpd = null;
776 fpd = OpenFile.openFpdFile(src);
777
778 //
779 // Update to memory
780 //
781 fpd.getPlatformHeader().setPlatformName(newId.getName());
782 fpd.getPlatformHeader().setGuidValue(newId.getGuid());
783 fpd.getPlatformHeader().setVersion(newId.getVersion());
784
785 //
786 // Update Cloned From element
787 //
788 updatePlatformClonedId(fpd, oldId);
789
790 //
791 // Save to file
792 //
793 SaveFile.saveFpdFile(trg, fpd);
794
795 //
796 // Update to platformId
797 //
798 this.setFid(new PlatformIdentification(newId));
799
800 //
801 // Update the db file
802 //
803 wt.addPlatformToDatabase(fid);
804
805 this.returnType = DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA;
806 }
807 }
808
809 private String getSelectPackagePath() {
810 return Tools.getFilePathOnly(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getPath());
811 }
812
813 private String getModulePath() {
814 String trg = this.jTextFieldFilePath.getText();
815 trg = Tools.addPathExt(trg, mode);
816 trg = getSelectPackagePath() + DataType.FILE_SEPARATOR + trg;
817 Tools.convertPathToCurrentOsType(trg);
818 return trg;
819 }
820
821 private String getPackagePath() {
822 String trg = this.jTextFieldFilePath.getText();
823 trg = Tools.addPathExt(trg, mode);
824 trg = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + trg;
825 trg = Tools.convertPathToCurrentOsType(trg);
826 return trg;
827 }
828
829 /**
830 Set target item's Cloned From element
831
832 @param id
833 @return
834
835 **/
836 private void updateModuleClonedId(ModuleSurfaceArea msa, Identification id) {
837 //
838 // Get PlatformDefinitions First
839 //
840 ModuleDefinitions pd = null;
841 if (msa.getModuleDefinitions() == null) {
842 pd = ModuleDefinitions.Factory.newInstance();
843 msa.addNewModuleDefinitions();
844 } else {
845 pd = msa.getModuleDefinitions();
846 }
847
848 //
849 // Get ClonedFrom then
850 //
851 ModuleDefinitions.ClonedFrom cf = null;
852 if (pd.getClonedFrom() == null) {
853 cf = ModuleDefinitions.ClonedFrom.Factory.newInstance();
854 } else {
855 cf = pd.getClonedFrom();
856 }
857
858 //
859 // Set new Cloned item
860 //
861 ModuleDefinitions.ClonedFrom.Cloned c = ModuleDefinitions.ClonedFrom.Cloned.Factory.newInstance();
862 c.setModuleGuid(id.getGuid());
863 c.setModuleVersion(id.getVersion());
864
865 cf.addNewCloned();
866 cf.setClonedArray(cf.getClonedList().size() - 1, c);
867 pd.addNewClonedFrom();
868 pd.setClonedFrom(cf);
869 msa.setModuleDefinitions(pd);
870 }
871
872 /**
873 Set target item's Cloned From element
874
875 @param id
876 @return
877
878 **/
879 private void updatePackageClonedId(PackageSurfaceArea spd, Identification id) {
880 //
881 // Get PlatformDefinitions First
882 //
883 PackageDefinitions pd = null;
884 if (spd.getPackageDefinitions() == null) {
885 pd = PackageDefinitions.Factory.newInstance();
886 spd.addNewPackageDefinitions();
887 } else {
888 pd = spd.getPackageDefinitions();
889 }
890
891 //
892 // Get ClonedFrom then
893 //
894 PackageDefinitions.ClonedFrom cf = null;
895 if (pd.getClonedFrom() == null) {
896 cf = PackageDefinitions.ClonedFrom.Factory.newInstance();
897 } else {
898 cf = pd.getClonedFrom();
899 }
900
901 //
902 // Set new Cloned item
903 //
904 PackageDefinitions.ClonedFrom.Cloned c = PackageDefinitions.ClonedFrom.Cloned.Factory.newInstance();
905 c.setPackageGuid(id.getGuid());
906 c.setPackageVersion(id.getVersion());
907
908 cf.addNewCloned();
909 cf.setClonedArray(cf.getClonedList().size() - 1, c);
910 pd.addNewClonedFrom();
911 pd.setClonedFrom(cf);
912 spd.setPackageDefinitions(pd);
913 }
914
915 /**
916 Set target item's Cloned From element
917
918 @param id
919 @return
920
921 **/
922 private void updatePlatformClonedId(PlatformSurfaceArea fpd, Identification id) {
923 //
924 // Get PlatformDefinitions First
925 //
926 PlatformDefinitions pd = null;
927 if (fpd.getPlatformDefinitions() == null) {
928 pd = PlatformDefinitions.Factory.newInstance();
929 fpd.addNewPlatformDefinitions();
930 } else {
931 pd = fpd.getPlatformDefinitions();
932 }
933
934 //
935 // Get ClonedFrom then
936 //
937 PlatformDefinitions.ClonedFrom cf = null;
938 if (pd.getClonedFrom() == null) {
939 cf = PlatformDefinitions.ClonedFrom.Factory.newInstance();
940 } else {
941 cf = pd.getClonedFrom();
942 }
943
944 //
945 // Set new Cloned item
946 //
947 PlatformDefinitions.ClonedFrom.Cloned c = PlatformDefinitions.ClonedFrom.Cloned.Factory.newInstance();
948 c.setPlatformGuid(id.getGuid());
949 c.setPlatformVersion(id.getVersion());
950
951 cf.addNewCloned();
952 cf.setClonedArray(cf.getClonedList().size() - 1, c);
953 pd.addNewClonedFrom();
954 pd.setClonedFrom(cf);
955 fpd.setPlatformDefinitions(pd);
956 }
957
958 public PlatformIdentification getFid() {
959 return fid;
960 }
961
962 public void setFid(PlatformIdentification fid) {
963 this.fid = fid;
964 }
965
966 public ModuleIdentification getMid() {
967 return mid;
968 }
969
970 public void setMid(ModuleIdentification mid) {
971 this.mid = mid;
972 }
973
974 public PackageIdentification getPid() {
975 return pid;
976 }
977
978 public void setPid(PackageIdentification pid) {
979 this.pid = pid;
980 }
981 }