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