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