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