]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/Clone.java
Adjusted sizes to accommodate Windows, iMac and Linux GUI
[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.OpenFile;
42 import org.tianocore.frameworkwizard.common.SaveFile;
43 import org.tianocore.frameworkwizard.common.Tools;
44 import org.tianocore.frameworkwizard.common.Identifications.Identification;
45 import org.tianocore.frameworkwizard.common.ui.IDialog;
46 import org.tianocore.frameworkwizard.common.ui.IFrame;
47 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
48 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
49 import org.tianocore.frameworkwizard.platform.PlatformIdentification;
50 import org.tianocore.frameworkwizard.workspace.Workspace;
51 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
52 import javax.swing.JComboBox;
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
340 .setToolTipText("Input module name here. For example, Application\\HelloWorld\\HelloWorld.msa");
341 this.jTextFieldFilePath.setSize(320, this.jTextFieldFilePath.getSize().height);
342 this.jLabelDestinationFile.setText("New Module Path and Filename");
343 }
344 if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {
345 this.jTextFieldType.setText(DataType.PACKAGE_SURFACE_AREA);
346 String s = oldId.getPath();
347 s = Tools.getRelativePath(oldId.getPath(), Workspace.getCurrentWorkspace());
348 this.jTextFieldSource.setText(Tools.convertPathToCurrentOsType(s));
349 this.jLabelBelong.setEnabled(false);
350 this.jComboBoxExistingPackage.setEnabled(false);
351 this.jButtonBrowse.setVisible(false);
352 this.jTextFieldFilePath.setToolTipText("Input package name here. For example, MdePkg\\MdePkg.fpd");
353 this.jTextFieldFilePath.setSize(320, this.jTextFieldFilePath.getSize().height);
354 this.jLabelDestinationFile.setText("New Package Path and Filename");
355 }
356 if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {
357 this.jTextFieldType.setText(DataType.PLATFORM_SURFACE_AREA);
358 this.jTextFieldSource.setText(oldId.getPath());
359 this.jLabelBelong.setEnabled(false);
360 this.jComboBoxExistingPackage.setEnabled(false);
361 this.jTextFieldFilePath
362 .setToolTipText("Select platform path here. For example, C:\\MyWorkspace\\EdkNt32Pkg\\Nt32.fpd");
363 this.jLabelDestinationFile.setText("New Platform Path and Filename");
364 }
365 if (mode == DataType.RETURN_TYPE_WORKSPACE) {
366 this.jTextFieldType.setText(DataType.WORKSPACE);
367 this.jTextFieldSource.setText(Workspace.getCurrentWorkspace());
368 this.jLabelBelong.setEnabled(false);
369 this.jComboBoxExistingPackage.setEnabled(false);
370 this.jLabelBaseName.setEnabled(false);
371 this.jTextFieldBaseName.setEditable(false);
372 this.jLabelGuid.setEnabled(false);
373 this.jTextFieldGuid.setEnabled(false);
374 this.jButtonGenerateGuid.setEnabled(false);
375 this.jLabelVersion.setEnabled(false);
376 this.jTextFieldVersion.setEnabled(false);
377 this.jTextFieldFilePath.setToolTipText("Input workspace path here. For example, C:\\MyWorkspace");
378 this.jLabelDestinationFile.setText("New Workspace Path");
379 }
380 }
381
382 /**
383 * This method initializes jContentPane
384 *
385 * @return javax.swing.JPanel
386 */
387 private JPanel getJContentPane() {
388 if (jContentPane == null) {
389 jLabelBelong = new JLabel();
390 jLabelBelong.setBounds(new java.awt.Rectangle(15, 60, 190, 20));
391 jLabelBelong.setText("Clone to Package");
392 jLabelVersion = new JLabel();
393 jLabelVersion.setBounds(new java.awt.Rectangle(15, 160, 190, 20));
394 jLabelVersion.setText("Version");
395 jLabelGuid = new JLabel();
396 jLabelGuid.setBounds(new java.awt.Rectangle(15, 135, 190, 20));
397 jLabelGuid.setText("Guid");
398 jLabelBaseName = new JLabel();
399 jLabelBaseName.setBounds(new java.awt.Rectangle(15, 110, 190, 20));
400 jLabelBaseName.setText("Base Name");
401 jLabelDestinationFile = new JLabel();
402 jLabelDestinationFile.setBounds(new java.awt.Rectangle(15, 85, 190, 20));
403 jLabelDestinationFile.setText("Destination File Name");
404 jLabelSource = new JLabel();
405 jLabelSource.setBounds(new java.awt.Rectangle(15, 35, 190, 20));
406 jLabelSource.setText("Source");
407 jLabelType = new JLabel();
408 jLabelType.setBounds(new java.awt.Rectangle(15, 10, 190, 20));
409 jLabelType.setText("Type");
410 jContentPane = new JPanel();
411 jContentPane.setLayout(null);
412 jContentPane.setSize(new java.awt.Dimension(540, 227));
413 jContentPane.add(jLabelType, null);
414 jContentPane.add(getJTextFieldType(), null);
415 jContentPane.add(jLabelSource, null);
416 jContentPane.add(getJTextFieldSource(), null);
417 jContentPane.add(jLabelDestinationFile, null);
418 jContentPane.add(getJTextFieldFilePath(), null);
419 jContentPane.add(jLabelBaseName, null);
420 jContentPane.add(getJTextFieldBaseName(), null);
421 jContentPane.add(jLabelGuid, null);
422 jContentPane.add(getJTextFieldGuid(), null);
423 jContentPane.add(jLabelVersion, null);
424 jContentPane.add(getJTextFieldVersion(), null);
425 jContentPane.add(getJButtonOk(), null);
426 jContentPane.add(getJButtonCancel(), null);
427 jContentPane.add(getJButtonBrowse(), null);
428 jContentPane.add(getJButtonGenerateGuid(), null);
429 jContentPane.add(jLabelBelong, null);
430 jContentPane.add(getJComboBoxExistingPackage(), null);
431 }
432 return jContentPane;
433 }
434
435 /* (non-Javadoc)
436 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
437 *
438 * Override actionPerformed to listen all actions
439 */
440 public void actionPerformed(ActionEvent arg0) {
441 if (arg0.getSource() == jButtonCancel) {
442 this.setVisible(false);
443 this.returnType = DataType.RETURN_TYPE_CANCEL;
444 }
445
446 if (arg0.getSource() == jButtonOk) {
447 if (this.check()) {
448 try {
449 this.save();
450 } catch (IOException e) {
451 Log.wrn("Clone", e.getMessage());
452 Log.err("Clone", e.getMessage());
453 return;
454 } catch (XmlException e) {
455 Log.wrn("Clone", e.getMessage());
456 Log.err("Clone", e.getMessage());
457 return;
458 } catch (Exception e) {
459 Log.wrn("Clone", e.getMessage());
460 Log.err("Clone", e.getMessage());
461 return;
462 }
463 } else {
464 return;
465 }
466 this.setVisible(false);
467 }
468
469 if (arg0.getSource() == this.jButtonGenerateGuid) {
470 this.jTextFieldGuid.setText(Tools.generateUuidString());
471 }
472
473 //
474 // Use different file ext
475 //
476 if (arg0.getSource() == this.jButtonBrowse) {
477 JFileChooser fc = new JFileChooser();
478 fc.setAcceptAllFileFilterUsed(false);
479
480 if (mode == DataType.RETURN_TYPE_WORKSPACE) {
481 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
482 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
483 }
484 if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {
485 fc.setCurrentDirectory(new File(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())
486 .getPath()));
487 fc.addChoosableFileFilter(new IFileFilter(DataType.MODULE_SURFACE_AREA_EXT));
488 }
489 if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {
490 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
491 fc.addChoosableFileFilter(new IFileFilter(DataType.PACKAGE_SURFACE_AREA_EXT));
492 }
493 if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {
494 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
495 fc.addChoosableFileFilter(new IFileFilter(DataType.PLATFORM_SURFACE_AREA_EXT));
496 }
497 int result = fc.showSaveDialog(new JPanel());
498 if (result == JFileChooser.APPROVE_OPTION) {
499 this.jTextFieldFilePath.setText(Tools.addPathExt(fc.getSelectedFile().getPath(), mode));
500 }
501 }
502 }
503
504 //
505 // Check name, guid and version
506 //
507 private boolean checkId() {
508 //
509 // Check Basename
510 //
511 if (isEmpty(this.jTextFieldBaseName.getText())) {
512 Log.wrn("Clone", "Base Name couldn't be empty!");
513 return false;
514 }
515 if (!DataValidation.isBaseName(this.jTextFieldBaseName.getText())) {
516 Log.wrn("Clone", "Incorrect data type for Base Name");
517 return false;
518 }
519
520 //
521 // Check Guid
522 //
523 if (isEmpty(this.jTextFieldGuid.getText())) {
524 Log.wrn("Clone", "Guid couldn't be empty!");
525 return false;
526 }
527 if (!DataValidation.isGuid(this.jTextFieldGuid.getText())) {
528 Log.wrn("Clone", "Incorrect data type for Guid");
529 return false;
530 }
531
532 //
533 // Check Version
534 //
535 if (isEmpty(this.jTextFieldVersion.getText())) {
536 Log.wrn("Clone", "Version couldn't be empty!");
537 return false;
538 }
539 if (!DataValidation.isVersion(this.jTextFieldVersion.getText())) {
540 Log.wrn("Clone", "Incorrect data type for Version");
541 return false;
542 }
543
544 //
545 // Save information to id
546 //
547 newId.setName(this.jTextFieldBaseName.getText());
548 newId.setGuid(this.jTextFieldGuid.getText());
549 newId.setVersion(this.jTextFieldVersion.getText());
550 newId.setPath(this.jTextFieldFilePath.getText());
551
552 return true;
553 }
554
555 /**
556 Check before save
557
558 @return
559
560 **/
561 private boolean check() {
562 String src = this.oldId.getPath();
563 String trg = this.jTextFieldFilePath.getText();
564 File srcFile = new File(src);
565 File trgFile = new File(trg);
566
567 //
568 // Common Check
569 //
570 if (!srcFile.exists()) {
571 Log.wrn("Clone", "The source doesn't exist");
572 return false;
573 }
574 if (isEmpty(trg)) {
575 Log.wrn("Clone", "The destination file path couldn't be empty");
576 return false;
577 }
578 if (src.equals(trg)) {
579 Log.wrn("Clone", "The source and destination couldn't be same");
580 return false;
581 }
582 if (trgFile.exists()) {
583 Log.wrn("Clone", "The destination already exists");
584 return false;
585 }
586
587 //
588 // Check for workspace
589 //
590 if (mode == DataType.RETURN_TYPE_WORKSPACE) {
591 if (trg.indexOf(src + DataType.FILE_SEPARATOR) == 0) {
592 Log.wrn("Clone", "The new workspace couldn't be in current workspace!");
593 return false;
594 }
595 }
596
597 //
598 // Check for Module
599 //
600 if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {
601 // if (trg.indexOf(DataType.DOS_FILE_SEPARATOR) == -1 && trg.indexOf(DataType.UNIX_FILE_SEPARATOR) == -1) {
602 // Log.err("The module name must include a path");
603 // return false;
604 // }
605 trg = this.getModulePath();
606 if (src.equals(trg)) {
607 Log.wrn("Clone", "The source and destination couldn't be same");
608 return false;
609 }
610 trgFile = new File(trg);
611 if (trgFile.exists()) {
612 Log.wrn("Clone", "The target module already exists");
613 return false;
614 }
615 return checkId();
616 }
617
618 //
619 // Check for Package
620 //
621 if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {
622 if (trg.indexOf(DataType.DOS_FILE_SEPARATOR) == -1 && trg.indexOf(DataType.UNIX_FILE_SEPARATOR) == -1) {
623 Log.wrn("Clone", "The package name must include a path");
624 return false;
625 }
626 trg = this.getPackagePath();
627 if (Tools.getFilePathOnly(src).equals(Tools.getFilePathOnly(trg))) {
628 Log.wrn("Clone", "The source and destination couldn't be same");
629 return false;
630 }
631 trgFile = new File(trg);
632 if (trgFile.exists()) {
633 Log.wrn("Clone", "The target package already exists");
634 return false;
635 }
636 return checkId();
637 }
638
639 //
640 // Check for Platform
641 //
642 if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {
643 if (trg.indexOf(Workspace.getCurrentWorkspace()) != 0) {
644 Log.wrn("Clone", "The target platform must be in current workspace");
645 return false;
646 }
647 trgFile = new File(trg);
648 if (trgFile.exists()) {
649 Log.wrn("Clone", "The target platform already exists");
650 return false;
651 }
652 return checkId();
653 }
654
655 return true;
656 }
657
658 private void save() throws IOException, XmlException, Exception {
659 String src = this.oldId.getPath();
660 String trg = this.jTextFieldFilePath.getText();
661 Vector<String> vFiles = new Vector<String>();
662
663 //
664 // Clone Workspace
665 //
666 if (mode == DataType.RETURN_TYPE_WORKSPACE) {
667 FileOperation.copyFolder(src, trg);
668 this.returnType = DataType.RETURN_TYPE_WORKSPACE;
669 }
670
671 //
672 // Clone Module Surface Area
673 //
674 if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {
675 //
676 // Get target path from source path
677 //
678 trg = getModulePath();
679 newId.setPath(trg);
680 vFiles = wt.getAllModuleFilesPath(src);
681
682 //
683 // First copy all files to new directory
684 //
685 FileOperation.copyFile(src, trg);
686 for (int index = 1; index < vFiles.size(); index++) {
687 String oldFile = vFiles.get(index);
688 String newFile = vFiles.get(index).replace(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));
689 FileOperation.copyFile(oldFile, newFile);
690 }
691
692 //
693 // Create new msa file
694 //
695 ModuleSurfaceArea msa = null;
696 msa = OpenFile.openMsaFile(src);
697
698 //
699 // Update to memory
700 //
701 msa.getMsaHeader().setModuleName(newId.getName());
702 msa.getMsaHeader().setGuidValue(newId.getGuid());
703 msa.getMsaHeader().setVersion(newId.getVersion());
704
705 //
706 // Update Cloned From element
707 //
708 updateModuleClonedId(msa, oldId);
709
710 //
711 // Save to file
712 //
713 SaveFile.saveMsaFile(trg, msa);
714
715 //
716 // Update to platformId
717 //
718 this.setMid(new ModuleIdentification(newId,
719 packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())));
720
721 //
722 // Open belonging package
723 //
724 PackageSurfaceArea psa = PackageSurfaceArea.Factory.newInstance();
725 psa = OpenFile.openSpdFile(mid.getPackageId().getPath());
726
727 //
728 // Update the db file
729 //
730 wt.addModuleToPackage(mid, psa);
731
732 this.returnType = DataType.RETURN_TYPE_MODULE_SURFACE_AREA;
733 }
734
735 //
736 // Clone Package Surface Area
737 //
738 if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {
739 //
740 // Get target path from source path
741 //
742 trg = this.getPackagePath();
743 newId.setPath(trg);
744 vFiles = wt.getAllPakcageFilesPath(src);
745
746 FileOperation.copyFile(src, trg);
747 for (int index = 1; index < vFiles.size(); index++) {
748 String oldFile = vFiles.get(index);
749 String newFile = vFiles.get(index).replace(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));
750 FileOperation.copyFile(oldFile, newFile);
751 }
752
753 //
754 // First copy all files to new directory
755 //
756 //FileOperation.copyFolder(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));
757
758 //
759 // Delete old spd file
760 //
761 //FileOperation.delFile(Tools.getFilePathOnly(trg) + DataType.FILE_SEPARATOR + Tools.getFileNameOnly(src));
762
763 //
764 // Create new spd file
765 //
766 PackageSurfaceArea spd = null;
767 spd = OpenFile.openSpdFile(src);
768
769 //
770 // Update to memory
771 //
772 spd.getSpdHeader().setPackageName(newId.getName());
773 spd.getSpdHeader().setGuidValue(newId.getGuid());
774 spd.getSpdHeader().setVersion(newId.getVersion());
775
776 //
777 // Update Cloned From element
778 //
779 updatePackageClonedId(spd, oldId);
780
781 //
782 // Save to file
783 //
784 SaveFile.saveSpdFile(trg, spd);
785
786 //
787 // Update to platformId
788 //
789 this.setPid(new PackageIdentification(newId));
790
791 //
792 // Update the db file
793 //
794 wt.addPackageToDatabase(pid);
795
796 this.returnType = DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA;
797 }
798
799 //
800 // Clone Platform Surface Area
801 //
802 if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {
803 PlatformSurfaceArea fpd = null;
804 fpd = OpenFile.openFpdFile(src);
805
806 //
807 // Update to memory
808 //
809 fpd.getPlatformHeader().setPlatformName(newId.getName());
810 fpd.getPlatformHeader().setGuidValue(newId.getGuid());
811 fpd.getPlatformHeader().setVersion(newId.getVersion());
812
813 //
814 // Update Cloned From element
815 //
816 updatePlatformClonedId(fpd, oldId);
817
818 //
819 // Save to file
820 //
821 SaveFile.saveFpdFile(trg, fpd);
822
823 //
824 // Update to platformId
825 //
826 this.setFid(new PlatformIdentification(newId));
827
828 //
829 // Update the db file
830 //
831 wt.addPlatformToDatabase(fid);
832
833 this.returnType = DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA;
834 }
835 vFiles = null;
836 }
837
838 private String getSelectPackagePath() {
839 return Tools.getFilePathOnly(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getPath());
840 }
841
842 private String getModulePath() {
843 String trg = this.jTextFieldFilePath.getText();
844 trg = Tools.addPathExt(trg, mode);
845 trg = Tools.addFileSeparator(getSelectPackagePath()) + trg;
846 Tools.convertPathToCurrentOsType(trg);
847 return trg;
848 }
849
850 private String getPackagePath() {
851 String trg = this.jTextFieldFilePath.getText();
852 trg = Tools.addPathExt(trg, mode);
853 trg = Tools.addFileSeparator(Workspace.getCurrentWorkspace()) + trg;
854 trg = Tools.convertPathToCurrentOsType(trg);
855 return trg;
856 }
857
858 /**
859 Set target item's Cloned From element
860
861 @param id
862 @return
863
864 **/
865 private void updateModuleClonedId(ModuleSurfaceArea msa, Identification id) {
866 //
867 // Get PlatformDefinitions First
868 //
869 ModuleDefinitions pd = null;
870 if (msa.getModuleDefinitions() == null) {
871 pd = ModuleDefinitions.Factory.newInstance();
872 msa.addNewModuleDefinitions();
873 } else {
874 pd = msa.getModuleDefinitions();
875 }
876
877 //
878 // Get ClonedFrom then
879 //
880 ModuleDefinitions.ClonedFrom cf = null;
881 BigInteger count = new BigInteger("-1");
882 if (pd.getClonedFrom() == null) {
883 cf = ModuleDefinitions.ClonedFrom.Factory.newInstance();
884 } else {
885 cf = pd.getClonedFrom();
886 if (cf != null) {
887 for (int index = 0; index < cf.getClonedList().size(); index++) {
888 if (cf.getClonedList().get(index).getId() != null) {
889 count = count.max(cf.getClonedList().get(index).getId());
890 }
891 }
892 }
893 }
894
895 //
896 // Set new Cloned item
897 //
898 ModuleDefinitions.ClonedFrom.Cloned c = ModuleDefinitions.ClonedFrom.Cloned.Factory.newInstance();
899 c.setModuleGuid(id.getGuid());
900 c.setModuleVersion(id.getVersion());
901 c.setPackageGuid(wt.getPackageIdByModuleId(oldId).getGuid());
902 c.setPackageVersion(wt.getPackageIdByModuleId(oldId).getVersion());
903 c.setId(count.add(new BigInteger("1")));
904 String guid = wt.getModuleFarGuid(oldId);
905 if (guid != null && !guid.equals("")) {
906 c.setFarGuid(guid);
907 }
908
909 cf.addNewCloned();
910 cf.setClonedArray(cf.getClonedList().size() - 1, c);
911 pd.addNewClonedFrom();
912 pd.setClonedFrom(cf);
913 msa.setModuleDefinitions(pd);
914 }
915
916 /**
917 Set target item's Cloned From element
918
919 @param id
920 @return
921
922 **/
923 private void updatePackageClonedId(PackageSurfaceArea spd, Identification id) {
924 //
925 // Get PlatformDefinitions First
926 //
927 PackageDefinitions pd = null;
928 if (spd.getPackageDefinitions() == null) {
929 pd = PackageDefinitions.Factory.newInstance();
930 spd.addNewPackageDefinitions();
931 } else {
932 pd = spd.getPackageDefinitions();
933 }
934
935 //
936 // Get ClonedFrom then
937 //
938 PackageDefinitions.ClonedFrom cf = null;
939 BigInteger count = new BigInteger("-1");
940 if (pd.getClonedFrom() == null) {
941 cf = PackageDefinitions.ClonedFrom.Factory.newInstance();
942 } else {
943 cf = pd.getClonedFrom();
944 if (cf != null) {
945 for (int index = 0; index < cf.getClonedList().size(); index++) {
946 if (cf.getClonedList().get(index).getId() != null) {
947 count = count.max(cf.getClonedList().get(index).getId());
948 }
949 }
950 }
951 }
952
953 //
954 // Set new Cloned item
955 //
956 PackageDefinitions.ClonedFrom.Cloned c = PackageDefinitions.ClonedFrom.Cloned.Factory.newInstance();
957 c.setPackageGuid(id.getGuid());
958 c.setPackageVersion(id.getVersion());
959 c.setId(count.add(new BigInteger("1")));
960 String guid = wt.getModuleFarGuid(oldId);
961 if (guid != null && !guid.equals("")) {
962 c.setFarGuid(guid);
963 }
964
965 cf.addNewCloned();
966 cf.setClonedArray(cf.getClonedList().size() - 1, c);
967 pd.addNewClonedFrom();
968 pd.setClonedFrom(cf);
969 spd.setPackageDefinitions(pd);
970 }
971
972 /**
973 Set target item's Cloned From element
974
975 @param id
976 @return
977
978 **/
979 private void updatePlatformClonedId(PlatformSurfaceArea fpd, Identification id) {
980 //
981 // Get PlatformDefinitions First
982 //
983 PlatformDefinitions pd = null;
984 if (fpd.getPlatformDefinitions() == null) {
985 pd = PlatformDefinitions.Factory.newInstance();
986 fpd.addNewPlatformDefinitions();
987 } else {
988 pd = fpd.getPlatformDefinitions();
989 }
990
991 //
992 // Get ClonedFrom then
993 //
994 PlatformDefinitions.ClonedFrom cf = null;
995 BigInteger count = new BigInteger("-1");
996 if (pd.getClonedFrom() == null) {
997 cf = PlatformDefinitions.ClonedFrom.Factory.newInstance();
998 } else {
999 cf = pd.getClonedFrom();
1000 if (cf != null) {
1001 for (int index = 0; index < cf.getClonedList().size(); index++) {
1002 if (cf.getClonedList().get(index).getId() != null) {
1003 count = count.max(cf.getClonedList().get(index).getId());
1004 }
1005 }
1006 }
1007 }
1008
1009 //
1010 // Set new Cloned item
1011 //
1012 PlatformDefinitions.ClonedFrom.Cloned c = PlatformDefinitions.ClonedFrom.Cloned.Factory.newInstance();
1013 c.setPlatformGuid(id.getGuid());
1014 c.setPlatformVersion(id.getVersion());
1015 c.setId(count.add(new BigInteger("1")));
1016 String guid = wt.getModuleFarGuid(oldId);
1017 if (guid != null && !guid.equals("")) {
1018 c.setFarGuid(guid);
1019 }
1020
1021 cf.addNewCloned();
1022 cf.setClonedArray(cf.getClonedList().size() - 1, c);
1023 pd.addNewClonedFrom();
1024 pd.setClonedFrom(cf);
1025 fpd.setPlatformDefinitions(pd);
1026 }
1027
1028 public PlatformIdentification getFid() {
1029 return fid;
1030 }
1031
1032 public void setFid(PlatformIdentification fid) {
1033 this.fid = fid;
1034 }
1035
1036 public ModuleIdentification getMid() {
1037 return mid;
1038 }
1039
1040 public void setMid(ModuleIdentification mid) {
1041 this.mid = mid;
1042 }
1043
1044 public PackageIdentification getPid() {
1045 return pid;
1046 }
1047
1048 public void setPid(PackageIdentification pid) {
1049 this.pid = pid;
1050 }
1051 }