]>
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 | |
79cb6fdb | 20 | import java.math.BigInteger;\r |
a13899c5 | 21 | import java.util.Vector;\r |
22 | \r | |
23 | import javax.swing.JFileChooser;\r | |
24 | import javax.swing.JPanel;\r | |
25 | import javax.swing.JLabel;\r | |
26 | import javax.swing.JTextField;\r | |
27 | import javax.swing.JButton;\r | |
28 | \r | |
29 | import org.apache.xmlbeans.XmlException;\r | |
30 | import org.tianocore.ModuleDefinitionsDocument.ModuleDefinitions;\r | |
31 | import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r | |
32 | import org.tianocore.PackageDefinitionsDocument.PackageDefinitions;\r | |
33 | import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r | |
34 | import org.tianocore.PlatformDefinitionsDocument.PlatformDefinitions;\r | |
35 | import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;\r | |
36 | import org.tianocore.frameworkwizard.common.DataType;\r | |
37 | import org.tianocore.frameworkwizard.common.DataValidation;\r | |
38 | import org.tianocore.frameworkwizard.common.FileOperation;\r | |
09ef9242 | 39 | import org.tianocore.frameworkwizard.common.GlobalData;\r |
a13899c5 | 40 | import org.tianocore.frameworkwizard.common.IFileFilter;\r |
a13899c5 | 41 | import org.tianocore.frameworkwizard.common.Log;\r |
f9d0ab92 | 42 | import org.tianocore.frameworkwizard.common.OpenFile;\r |
a13899c5 | 43 | import org.tianocore.frameworkwizard.common.SaveFile;\r |
44 | import org.tianocore.frameworkwizard.common.Tools;\r | |
79cb6fdb | 45 | import org.tianocore.frameworkwizard.common.Identifications.Identification;\r |
a13899c5 | 46 | import org.tianocore.frameworkwizard.common.ui.IDialog;\r |
47 | import org.tianocore.frameworkwizard.common.ui.IFrame;\r | |
79cb6fdb | 48 | import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r |
a13899c5 | 49 | import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r |
50 | import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r | |
51 | import org.tianocore.frameworkwizard.workspace.Workspace;\r | |
52 | import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r | |
53 | import javax.swing.JComboBox;\r | |
54 | \r | |
43dc3851 | 55 | /**\r |
56 | The class is used to provide functions to clone workspace, module, package and platform\r | |
57 | It extends IDialog\r | |
58 | \r | |
59 | **/\r | |
a13899c5 | 60 | public class Clone extends IDialog {\r |
61 | \r | |
43dc3851 | 62 | ///\r |
63 | /// Define Class Serial Version UID\r | |
64 | ///\r | |
a13899c5 | 65 | private static final long serialVersionUID = -5469299324965727137L;\r |
66 | \r | |
43dc3851 | 67 | ///\r |
68 | /// Define Class Members\r | |
69 | ///\r | |
a13899c5 | 70 | private JPanel jContentPane = null;\r |
71 | \r | |
72 | private JLabel jLabelType = null;\r | |
73 | \r | |
74 | private JTextField jTextFieldType = null;\r | |
75 | \r | |
76 | private JLabel jLabelSource = null;\r | |
77 | \r | |
78 | private JTextField jTextFieldSource = null;\r | |
79 | \r | |
80 | private JButton jButtonBrowse = null;\r | |
81 | \r | |
82 | private JLabel jLabelDestinationFile = null;\r | |
83 | \r | |
84 | private JTextField jTextFieldFilePath = null;\r | |
85 | \r | |
86 | private JLabel jLabelBaseName = null;\r | |
87 | \r | |
88 | private JTextField jTextFieldBaseName = null;\r | |
89 | \r | |
90 | private JLabel jLabelGuid = null;\r | |
91 | \r | |
92 | private JTextField jTextFieldGuid = null;\r | |
93 | \r | |
94 | private JLabel jLabelVersion = null;\r | |
95 | \r | |
96 | private JTextField jTextFieldVersion = null;\r | |
97 | \r | |
98 | private JButton jButtonOk = null;\r | |
99 | \r | |
100 | private JButton jButtonCancel = null;\r | |
101 | \r | |
102 | private JButton jButtonGenerateGuid = null;\r | |
103 | \r | |
43dc3851 | 104 | private JLabel jLabelBelong = null;\r |
105 | \r | |
106 | private JComboBox jComboBoxExistingPackage = null;\r | |
107 | \r | |
108 | ///\r | |
109 | /// Define members not for UI\r | |
110 | ///\r | |
111 | \r | |
a13899c5 | 112 | private int mode = -1;\r |
113 | \r | |
114 | private Vector<PackageIdentification> packages = null;\r | |
115 | \r | |
116 | private WorkspaceTools wt = new WorkspaceTools();\r | |
117 | \r | |
a13899c5 | 118 | private Identification oldId = null;\r |
119 | \r | |
120 | private Identification newId = null;\r | |
121 | \r | |
122 | private ModuleIdentification mid = null;\r | |
123 | \r | |
124 | private PackageIdentification pid = null;\r | |
125 | \r | |
126 | private PlatformIdentification fid = null;\r | |
127 | \r | |
128 | /**\r | |
43dc3851 | 129 | This method initializes jTextFieldType \r |
130 | \r | |
131 | @return javax.swing.JTextField\r | |
132 | \r | |
133 | **/\r | |
a13899c5 | 134 | private JTextField getJTextFieldType() {\r |
135 | if (jTextFieldType == null) {\r | |
136 | jTextFieldType = new JTextField();\r | |
55a2762d | 137 | jTextFieldType.setBounds(new java.awt.Rectangle(210, 10, 320, 20));\r |
a13899c5 | 138 | jTextFieldType.setEditable(false);\r |
139 | }\r | |
140 | return jTextFieldType;\r | |
141 | }\r | |
142 | \r | |
143 | /**\r | |
43dc3851 | 144 | This method initializes jTextFieldSource \r |
145 | \r | |
146 | @return javax.swing.JTextField \r | |
147 | \r | |
148 | **/\r | |
a13899c5 | 149 | private JTextField getJTextFieldSource() {\r |
150 | if (jTextFieldSource == null) {\r | |
151 | jTextFieldSource = new JTextField();\r | |
55a2762d | 152 | jTextFieldSource.setBounds(new java.awt.Rectangle(210, 35, 320, 20));\r |
a13899c5 | 153 | jTextFieldSource.setEditable(false);\r |
154 | }\r | |
155 | return jTextFieldSource;\r | |
156 | }\r | |
157 | \r | |
158 | /**\r | |
43dc3851 | 159 | This method initializes jButtonBrowse \r |
160 | \r | |
161 | @return javax.swing.JButton \r | |
162 | \r | |
163 | **/\r | |
a13899c5 | 164 | private JButton getJButtonBrowse() {\r |
165 | if (jButtonBrowse == null) {\r | |
166 | jButtonBrowse = new JButton();\r | |
55a2762d | 167 | jButtonBrowse.setBounds(new java.awt.Rectangle(445, 85, 85, 20));\r |
a13899c5 | 168 | jButtonBrowse.setText("Browse");\r |
169 | jButtonBrowse.addActionListener(this);\r | |
170 | }\r | |
171 | return jButtonBrowse;\r | |
172 | }\r | |
173 | \r | |
174 | /**\r | |
43dc3851 | 175 | This method initializes jTextFieldDestinationFile \r |
176 | \r | |
177 | @return javax.swing.JTextField \r | |
178 | \r | |
179 | **/\r | |
a13899c5 | 180 | private JTextField getJTextFieldFilePath() {\r |
181 | if (jTextFieldFilePath == null) {\r | |
182 | jTextFieldFilePath = new JTextField();\r | |
55a2762d | 183 | jTextFieldFilePath.setBounds(new java.awt.Rectangle(210, 85, 230, 20));\r |
a13899c5 | 184 | }\r |
185 | return jTextFieldFilePath;\r | |
186 | }\r | |
187 | \r | |
188 | /**\r | |
43dc3851 | 189 | This method initializes jTextFieldBaseName \r |
190 | \r | |
191 | @return javax.swing.JTextField \r | |
192 | \r | |
193 | **/\r | |
a13899c5 | 194 | private JTextField getJTextFieldBaseName() {\r |
195 | if (jTextFieldBaseName == null) {\r | |
196 | jTextFieldBaseName = new JTextField();\r | |
55a2762d | 197 | jTextFieldBaseName.setBounds(new java.awt.Rectangle(210, 110, 320, 20));\r |
a13899c5 | 198 | }\r |
199 | return jTextFieldBaseName;\r | |
200 | }\r | |
201 | \r | |
202 | /**\r | |
43dc3851 | 203 | This method initializes jTextFieldGuid \r |
204 | \r | |
205 | @return javax.swing.JTextField \r | |
206 | \r | |
207 | **/\r | |
a13899c5 | 208 | private JTextField getJTextFieldGuid() {\r |
209 | if (jTextFieldGuid == null) {\r | |
210 | jTextFieldGuid = new JTextField();\r | |
55a2762d | 211 | jTextFieldGuid.setBounds(new java.awt.Rectangle(210, 135, 230, 20));\r |
a13899c5 | 212 | }\r |
213 | return jTextFieldGuid;\r | |
214 | }\r | |
215 | \r | |
216 | /**\r | |
43dc3851 | 217 | This method initializes jTextFieldVersion \r |
218 | \r | |
219 | @return javax.swing.JTextField \r | |
220 | \r | |
221 | **/\r | |
a13899c5 | 222 | private JTextField getJTextFieldVersion() {\r |
223 | if (jTextFieldVersion == null) {\r | |
224 | jTextFieldVersion = new JTextField();\r | |
55a2762d | 225 | jTextFieldVersion.setBounds(new java.awt.Rectangle(210, 160, 320, 20));\r |
a13899c5 | 226 | }\r |
227 | return jTextFieldVersion;\r | |
228 | }\r | |
229 | \r | |
230 | /**\r | |
43dc3851 | 231 | This method initializes jButtonOk \r |
232 | \r | |
233 | @return javax.swing.JButton \r | |
234 | \r | |
235 | **/\r | |
a13899c5 | 236 | private JButton getJButtonOk() {\r |
237 | if (jButtonOk == null) {\r | |
238 | jButtonOk = new JButton();\r | |
55a2762d | 239 | jButtonOk.setBounds(new java.awt.Rectangle(285, 200, 90, 20));\r |
a13899c5 | 240 | jButtonOk.setText("Ok");\r |
241 | jButtonOk.addActionListener(this);\r | |
242 | }\r | |
243 | return jButtonOk;\r | |
244 | }\r | |
245 | \r | |
246 | /**\r | |
43dc3851 | 247 | This method initializes jButtonCancel \r |
248 | \r | |
249 | @return javax.swing.JButton \r | |
250 | \r | |
251 | **/\r | |
a13899c5 | 252 | private JButton getJButtonCancel() {\r |
253 | if (jButtonCancel == null) {\r | |
254 | jButtonCancel = new JButton();\r | |
55a2762d | 255 | jButtonCancel.setBounds(new java.awt.Rectangle(405, 200, 90, 20));\r |
a13899c5 | 256 | jButtonCancel.setText("Cancel");\r |
257 | jButtonCancel.addActionListener(this);\r | |
258 | }\r | |
259 | return jButtonCancel;\r | |
260 | }\r | |
261 | \r | |
262 | /**\r | |
43dc3851 | 263 | This method initializes jButtonGenerateGuid \r |
264 | \r | |
265 | @return javax.swing.JButton \r | |
266 | \r | |
267 | **/\r | |
a13899c5 | 268 | private JButton getJButtonGenerateGuid() {\r |
269 | if (jButtonGenerateGuid == null) {\r | |
270 | jButtonGenerateGuid = new JButton();\r | |
55a2762d | 271 | jButtonGenerateGuid.setBounds(new java.awt.Rectangle(445, 135, 85, 20));\r |
a13899c5 | 272 | jButtonGenerateGuid.setText("Gen");\r |
273 | jButtonGenerateGuid.addActionListener(this);\r | |
274 | }\r | |
275 | return jButtonGenerateGuid;\r | |
276 | }\r | |
277 | \r | |
278 | /**\r | |
43dc3851 | 279 | This method initializes jComboBoxExistingPackage \r |
280 | \r | |
281 | @return javax.swing.JComboBox \r | |
282 | \r | |
283 | **/\r | |
a13899c5 | 284 | private JComboBox getJComboBoxExistingPackage() {\r |
285 | if (jComboBoxExistingPackage == null) {\r | |
286 | jComboBoxExistingPackage = new JComboBox();\r | |
55a2762d | 287 | jComboBoxExistingPackage.setBounds(new java.awt.Rectangle(210, 60, 320, 20));\r |
a13899c5 | 288 | }\r |
289 | return jComboBoxExistingPackage;\r | |
290 | }\r | |
291 | \r | |
292 | /**\r | |
43dc3851 | 293 | This is the default constructor\r |
a13899c5 | 294 | \r |
295 | **/\r | |
a13899c5 | 296 | public Clone() {\r |
297 | super();\r | |
298 | init();\r | |
299 | }\r | |
300 | \r | |
301 | /**\r | |
43dc3851 | 302 | This is the override constructor\r |
303 | \r | |
304 | @param parentFrame The parent frame which starts this frame\r | |
305 | @param modal To identify the frame's modal\r | |
306 | @param fileType To identify the clone target type\r | |
307 | @param identification The clone target's identification\r | |
a13899c5 | 308 | \r |
309 | **/\r | |
310 | public Clone(IFrame parentFrame, boolean modal, int fileType, Identification identification) {\r | |
311 | super(parentFrame, modal);\r | |
312 | this.mode = fileType;\r | |
313 | if (identification != null) {\r | |
314 | this.oldId = new Identification(identification.getName(), identification.getGuid(),\r | |
315 | identification.getVersion(), identification.getPath());\r | |
316 | this.newId = new Identification(identification.getName(), identification.getGuid(),\r | |
317 | identification.getVersion(), identification.getPath());\r | |
318 | }\r | |
319 | init(mode);\r | |
320 | }\r | |
321 | \r | |
322 | /**\r | |
323 | Query all existing packages and fill them into combox\r | |
324 | \r | |
325 | **/\r | |
326 | private void initExistingPackage() {\r | |
327 | packages = wt.getAllPackages();\r | |
328 | for (int index = 0; index < packages.size(); index++) {\r | |
329 | this.jComboBoxExistingPackage.addItem(packages.elementAt(index).getName());\r | |
330 | }\r | |
331 | }\r | |
332 | \r | |
333 | /**\r | |
43dc3851 | 334 | This method initializes this\r |
335 | \r | |
336 | **/\r | |
a13899c5 | 337 | private void init() {\r |
55a2762d | 338 | this.setSize(550, 260);\r |
a13899c5 | 339 | this.setContentPane(getJContentPane());\r |
340 | this.setTitle("Clone");\r | |
341 | this.centerWindow();\r | |
342 | }\r | |
343 | \r | |
344 | /**\r | |
43dc3851 | 345 | This method initializes this with given clone target type.\r |
346 | Customize the frame interface via different clone target type.\r | |
347 | \r | |
348 | @param mode To identify the clone target type\r | |
349 | \r | |
350 | **/\r | |
a13899c5 | 351 | private void init(int mode) {\r |
352 | init();\r | |
43dc3851 | 353 | //\r |
354 | // For MODULE_SURFACE_AREA\r | |
355 | //\r | |
a13899c5 | 356 | if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r |
357 | this.jTextFieldType.setText(DataType.MODULE_SURFACE_AREA);\r | |
55a2762d | 358 | String s = oldId.getPath();\r |
359 | s = Tools.getRelativePath(s, Tools.getFilePathOnly(wt.getPackageIdByModuleId(oldId).getPath()));\r | |
360 | this.jTextFieldSource.setText(Tools.convertPathToCurrentOsType(s));\r | |
a13899c5 | 361 | initExistingPackage();\r |
55a2762d | 362 | this.jButtonBrowse.setVisible(false);\r |
ed1665f2 | 363 | this.jTextFieldFilePath\r |
72a0d8e6 | 364 | .setToolTipText("<html>Input the module's relative path and filename, for example:<br>Application\\HelloWorld\\HelloWorld.msa</html>");\r |
55a2762d | 365 | this.jTextFieldFilePath.setSize(320, this.jTextFieldFilePath.getSize().height);\r |
366 | this.jLabelDestinationFile.setText("New Module Path and Filename");\r | |
a13899c5 | 367 | }\r |
43dc3851 | 368 | //\r |
369 | // For PACKAGE_SURFACE_AREA\r | |
370 | //\r | |
a13899c5 | 371 | if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r |
372 | this.jTextFieldType.setText(DataType.PACKAGE_SURFACE_AREA);\r | |
55a2762d | 373 | String s = oldId.getPath();\r |
374 | s = Tools.getRelativePath(oldId.getPath(), Workspace.getCurrentWorkspace());\r | |
375 | this.jTextFieldSource.setText(Tools.convertPathToCurrentOsType(s));\r | |
a13899c5 | 376 | this.jLabelBelong.setEnabled(false);\r |
377 | this.jComboBoxExistingPackage.setEnabled(false);\r | |
55a2762d | 378 | this.jButtonBrowse.setVisible(false);\r |
37bd8fbb | 379 | this.jTextFieldFilePath\r |
380 | .setToolTipText("<html>Input the package's relative path and file name, for example:<br>MdePkg\\MdePkg.spd</html>");\r | |
55a2762d | 381 | this.jTextFieldFilePath.setSize(320, this.jTextFieldFilePath.getSize().height);\r |
382 | this.jLabelDestinationFile.setText("New Package Path and Filename");\r | |
01022d98 | 383 | \r |
384 | //\r | |
385 | // Check if the package can be cloned\r | |
386 | //\r | |
387 | PackageSurfaceArea spd = GlobalData.openingPackageList\r | |
388 | .getPackageSurfaceAreaFromId(GlobalData.openingPackageList\r | |
389 | .getIdByPath(this.oldId\r | |
390 | .getPath()));\r | |
391 | if (spd != null) {\r | |
392 | if (spd.getPackageDefinitions() != null) {\r | |
393 | if (!spd.getPackageDefinitions().getRePackage()) {\r | |
394 | Log.wrn("Clone Package", "This package can't repackaged and cloned");\r | |
395 | this.jTextFieldBaseName.setEnabled(false);\r | |
396 | this.jTextFieldFilePath.setEnabled(false);\r | |
397 | this.jTextFieldGuid.setEnabled(false);\r | |
398 | this.jTextFieldVersion.setEnabled(false);\r | |
399 | this.jButtonGenerateGuid.setEnabled(false);\r | |
400 | this.jButtonOk.setEnabled(false);\r | |
401 | }\r | |
402 | }\r | |
403 | }\r | |
a13899c5 | 404 | }\r |
43dc3851 | 405 | //\r |
406 | // For PLATFORM_SURFACE_AREA\r | |
407 | //\r | |
a13899c5 | 408 | if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r |
409 | this.jTextFieldType.setText(DataType.PLATFORM_SURFACE_AREA);\r | |
410 | this.jTextFieldSource.setText(oldId.getPath());\r | |
411 | this.jLabelBelong.setEnabled(false);\r | |
412 | this.jComboBoxExistingPackage.setEnabled(false);\r | |
ed1665f2 | 413 | this.jTextFieldFilePath\r |
72a0d8e6 | 414 | .setToolTipText("<html>Select the platform's relative path and filename. For example:<br>C:\\MyWorkspace\\EdkNt32Pkg\\Nt32.fpd</html>");\r |
55a2762d | 415 | this.jLabelDestinationFile.setText("New Platform Path and Filename");\r |
a13899c5 | 416 | }\r |
43dc3851 | 417 | //\r |
418 | // For WORKSPACE\r | |
419 | //\r | |
a13899c5 | 420 | if (mode == DataType.RETURN_TYPE_WORKSPACE) {\r |
421 | this.jTextFieldType.setText(DataType.WORKSPACE);\r | |
422 | this.jTextFieldSource.setText(Workspace.getCurrentWorkspace());\r | |
423 | this.jLabelBelong.setEnabled(false);\r | |
424 | this.jComboBoxExistingPackage.setEnabled(false);\r | |
425 | this.jLabelBaseName.setEnabled(false);\r | |
426 | this.jTextFieldBaseName.setEditable(false);\r | |
427 | this.jLabelGuid.setEnabled(false);\r | |
428 | this.jTextFieldGuid.setEnabled(false);\r | |
429 | this.jButtonGenerateGuid.setEnabled(false);\r | |
430 | this.jLabelVersion.setEnabled(false);\r | |
431 | this.jTextFieldVersion.setEnabled(false);\r | |
37bd8fbb | 432 | this.jTextFieldFilePath\r |
433 | .setToolTipText("<html>Input the workspace path, for example:<br>C:\\MyWorkspace</html>");\r | |
55a2762d | 434 | this.jLabelDestinationFile.setText("New Workspace Path");\r |
a13899c5 | 435 | }\r |
436 | }\r | |
437 | \r | |
438 | /**\r | |
43dc3851 | 439 | This method initializes jContentPane\r |
440 | \r | |
441 | @return javax.swing.JPanel\r | |
442 | \r | |
443 | **/\r | |
a13899c5 | 444 | private JPanel getJContentPane() {\r |
445 | if (jContentPane == null) {\r | |
446 | jLabelBelong = new JLabel();\r | |
55a2762d | 447 | jLabelBelong.setBounds(new java.awt.Rectangle(15, 60, 190, 20));\r |
72a0d8e6 | 448 | jLabelBelong.setText("Clone Package");\r |
a13899c5 | 449 | jLabelVersion = new JLabel();\r |
55a2762d | 450 | jLabelVersion.setBounds(new java.awt.Rectangle(15, 160, 190, 20));\r |
a13899c5 | 451 | jLabelVersion.setText("Version");\r |
452 | jLabelGuid = new JLabel();\r | |
55a2762d | 453 | jLabelGuid.setBounds(new java.awt.Rectangle(15, 135, 190, 20));\r |
a13899c5 | 454 | jLabelGuid.setText("Guid");\r |
455 | jLabelBaseName = new JLabel();\r | |
55a2762d | 456 | jLabelBaseName.setBounds(new java.awt.Rectangle(15, 110, 190, 20));\r |
a13899c5 | 457 | jLabelBaseName.setText("Base Name");\r |
458 | jLabelDestinationFile = new JLabel();\r | |
55a2762d | 459 | jLabelDestinationFile.setBounds(new java.awt.Rectangle(15, 85, 190, 20));\r |
a13899c5 | 460 | jLabelDestinationFile.setText("Destination File Name");\r |
461 | jLabelSource = new JLabel();\r | |
55a2762d | 462 | jLabelSource.setBounds(new java.awt.Rectangle(15, 35, 190, 20));\r |
a13899c5 | 463 | jLabelSource.setText("Source");\r |
464 | jLabelType = new JLabel();\r | |
55a2762d | 465 | jLabelType.setBounds(new java.awt.Rectangle(15, 10, 190, 20));\r |
a13899c5 | 466 | jLabelType.setText("Type");\r |
467 | jContentPane = new JPanel();\r | |
468 | jContentPane.setLayout(null);\r | |
55a2762d | 469 | jContentPane.setSize(new java.awt.Dimension(540, 227));\r |
a13899c5 | 470 | jContentPane.add(jLabelType, null);\r |
471 | jContentPane.add(getJTextFieldType(), null);\r | |
472 | jContentPane.add(jLabelSource, null);\r | |
473 | jContentPane.add(getJTextFieldSource(), null);\r | |
474 | jContentPane.add(jLabelDestinationFile, null);\r | |
475 | jContentPane.add(getJTextFieldFilePath(), null);\r | |
476 | jContentPane.add(jLabelBaseName, null);\r | |
477 | jContentPane.add(getJTextFieldBaseName(), null);\r | |
478 | jContentPane.add(jLabelGuid, null);\r | |
479 | jContentPane.add(getJTextFieldGuid(), null);\r | |
480 | jContentPane.add(jLabelVersion, null);\r | |
481 | jContentPane.add(getJTextFieldVersion(), null);\r | |
482 | jContentPane.add(getJButtonOk(), null);\r | |
483 | jContentPane.add(getJButtonCancel(), null);\r | |
484 | jContentPane.add(getJButtonBrowse(), null);\r | |
485 | jContentPane.add(getJButtonGenerateGuid(), null);\r | |
486 | jContentPane.add(jLabelBelong, null);\r | |
487 | jContentPane.add(getJComboBoxExistingPackage(), null);\r | |
488 | }\r | |
489 | return jContentPane;\r | |
490 | }\r | |
491 | \r | |
492 | /* (non-Javadoc)\r | |
493 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r | |
494 | * \r | |
495 | * Override actionPerformed to listen all actions\r | |
496 | */\r | |
497 | public void actionPerformed(ActionEvent arg0) {\r | |
498 | if (arg0.getSource() == jButtonCancel) {\r | |
499 | this.setVisible(false);\r | |
500 | this.returnType = DataType.RETURN_TYPE_CANCEL;\r | |
501 | }\r | |
502 | \r | |
503 | if (arg0.getSource() == jButtonOk) {\r | |
504 | if (this.check()) {\r | |
505 | try {\r | |
43dc3851 | 506 | //\r |
507 | // Save to file\r | |
508 | //\r | |
a13899c5 | 509 | this.save();\r |
510 | } catch (IOException e) {\r | |
ed1665f2 | 511 | Log.wrn("Clone", e.getMessage());\r |
a13899c5 | 512 | Log.err("Clone", e.getMessage());\r |
a13899c5 | 513 | return;\r |
514 | } catch (XmlException e) {\r | |
ed1665f2 | 515 | Log.wrn("Clone", e.getMessage());\r |
a13899c5 | 516 | Log.err("Clone", e.getMessage());\r |
a13899c5 | 517 | return;\r |
518 | } catch (Exception e) {\r | |
ed1665f2 | 519 | Log.wrn("Clone", e.getMessage());\r |
a13899c5 | 520 | Log.err("Clone", e.getMessage());\r |
a13899c5 | 521 | return;\r |
522 | }\r | |
523 | } else {\r | |
524 | return;\r | |
525 | }\r | |
526 | this.setVisible(false);\r | |
527 | }\r | |
528 | \r | |
529 | if (arg0.getSource() == this.jButtonGenerateGuid) {\r | |
530 | this.jTextFieldGuid.setText(Tools.generateUuidString());\r | |
531 | }\r | |
532 | \r | |
533 | //\r | |
43dc3851 | 534 | // Use different file ext for different clone target type\r |
a13899c5 | 535 | //\r |
536 | if (arg0.getSource() == this.jButtonBrowse) {\r | |
537 | JFileChooser fc = new JFileChooser();\r | |
538 | fc.setAcceptAllFileFilterUsed(false);\r | |
539 | \r | |
540 | if (mode == DataType.RETURN_TYPE_WORKSPACE) {\r | |
541 | fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));\r | |
542 | fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);\r | |
543 | }\r | |
544 | if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r | |
545 | fc.setCurrentDirectory(new File(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())\r | |
546 | .getPath()));\r | |
547 | fc.addChoosableFileFilter(new IFileFilter(DataType.MODULE_SURFACE_AREA_EXT));\r | |
548 | }\r | |
549 | if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r | |
550 | fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));\r | |
551 | fc.addChoosableFileFilter(new IFileFilter(DataType.PACKAGE_SURFACE_AREA_EXT));\r | |
552 | }\r | |
553 | if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r | |
554 | fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));\r | |
555 | fc.addChoosableFileFilter(new IFileFilter(DataType.PLATFORM_SURFACE_AREA_EXT));\r | |
556 | }\r | |
557 | int result = fc.showSaveDialog(new JPanel());\r | |
558 | if (result == JFileChooser.APPROVE_OPTION) {\r | |
559 | this.jTextFieldFilePath.setText(Tools.addPathExt(fc.getSelectedFile().getPath(), mode));\r | |
560 | }\r | |
561 | }\r | |
562 | }\r | |
563 | \r | |
43dc3851 | 564 | /**\r |
565 | Check name, guid and version.\r | |
566 | If all of them are valid, save information to new id\r | |
567 | \r | |
568 | @retval true All name, guid and version are valid\r | |
569 | @retval false Any one of name, guid and version is invalid\r | |
570 | \r | |
571 | **/\r | |
d8be5b14 | 572 | private boolean checkId(int mode) {\r |
573 | String name = this.jTextFieldBaseName.getText();\r | |
574 | String guid = this.jTextFieldGuid.getText();\r | |
575 | String version = this.jTextFieldVersion.getText();\r | |
576 | \r | |
a13899c5 | 577 | //\r |
578 | // Check Basename\r | |
579 | //\r | |
d8be5b14 | 580 | if (isEmpty(name)) {\r |
72a0d8e6 | 581 | Log.wrn("Clone", "The Name is required!");\r |
a13899c5 | 582 | return false;\r |
583 | }\r | |
d8be5b14 | 584 | if (!DataValidation.isBaseName(name)) {\r |
37bd8fbb | 585 | Log\r |
586 | .wrn("Clone",\r | |
587 | "<html>Incorrect data type for the Name, it must<br>be a single word, starting with an alpha character.</html>");\r | |
a13899c5 | 588 | return false;\r |
589 | }\r | |
590 | \r | |
591 | //\r | |
592 | // Check Guid\r | |
593 | //\r | |
d8be5b14 | 594 | if (isEmpty(guid)) {\r |
72a0d8e6 | 595 | Log.wrn("Clone", "A Guid is required!!");\r |
a13899c5 | 596 | return false;\r |
597 | }\r | |
d8be5b14 | 598 | if (!DataValidation.isGuid(guid)) {\r |
37bd8fbb | 599 | Log\r |
600 | .wrn(\r | |
601 | "Clone",\r | |
602 | "<html>Incorrect data type for Guid, which must<br>be in registry format (8-4-4-4-12) for example:<br>d3adb123-eef1-466d-39ac-02febcaf5997</html>");\r | |
a13899c5 | 603 | return false;\r |
604 | }\r | |
605 | \r | |
606 | //\r | |
607 | // Check Version\r | |
608 | //\r | |
d8be5b14 | 609 | if (isEmpty(version)) {\r |
72a0d8e6 | 610 | Log.wrn("Clone", "A Version must be entered!");\r |
a13899c5 | 611 | return false;\r |
612 | }\r | |
d8be5b14 | 613 | if (!DataValidation.isVersion(version)) {\r |
37bd8fbb | 614 | Log\r |
615 | .wrn(\r | |
616 | "Clone",\r | |
617 | "<html>Incorrect data type for Version, which must<br>be one or more digits, optionally followed by sequence<br>of one or more dot, one or more digits; examples:<br>1.0 1.0.1 12.25.256</html>");\r | |
a13899c5 | 618 | return false;\r |
619 | }\r | |
d8be5b14 | 620 | \r |
621 | if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r | |
622 | String packageGuid = packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getGuid();\r | |
623 | String packageVersion = packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getVersion();\r | |
fc87d0ba | 624 | if (GlobalData.findModuleId(guid, version, packageGuid, packageVersion) != null) {\r |
d8be5b14 | 625 | Log.wrn("Clone", "A module with same Guid and same Version already exists, please selece a new Guid or Version!");\r |
626 | return false;\r | |
627 | }\r | |
628 | }\r | |
629 | \r | |
630 | if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r | |
fc87d0ba | 631 | if (GlobalData.findPackageId(guid, version) != null) {\r |
d8be5b14 | 632 | Log.wrn("Clone", "A package with same Guid and same Version already exists, please selece a new Guid or Version!");\r |
633 | return false;\r | |
634 | }\r | |
635 | }\r | |
636 | \r | |
637 | if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r | |
fc87d0ba | 638 | if (GlobalData.findPlatformId(guid, version) != null) {\r |
d8be5b14 | 639 | Log.wrn("Clone", "A platform with same Guid and same Version already exists, please selece a new Guid or Version!");\r |
640 | return false;\r | |
641 | }\r | |
642 | }\r | |
a13899c5 | 643 | \r |
644 | //\r | |
645 | // Save information to id\r | |
646 | //\r | |
647 | newId.setName(this.jTextFieldBaseName.getText());\r | |
648 | newId.setGuid(this.jTextFieldGuid.getText());\r | |
649 | newId.setVersion(this.jTextFieldVersion.getText());\r | |
650 | newId.setPath(this.jTextFieldFilePath.getText());\r | |
651 | \r | |
652 | return true;\r | |
653 | }\r | |
654 | \r | |
655 | /**\r | |
656 | Check before save\r | |
657 | \r | |
43dc3851 | 658 | @retval true All check points are passed\r |
659 | @retval false Any one of check points is failed\r | |
a13899c5 | 660 | \r |
661 | **/\r | |
662 | private boolean check() {\r | |
55a2762d | 663 | String src = this.oldId.getPath();\r |
a13899c5 | 664 | String trg = this.jTextFieldFilePath.getText();\r |
665 | File srcFile = new File(src);\r | |
666 | File trgFile = new File(trg);\r | |
667 | \r | |
668 | //\r | |
669 | // Common Check\r | |
670 | //\r | |
671 | if (!srcFile.exists()) {\r | |
72a0d8e6 | 672 | Log.wrn("Clone", "The source file does not exist!");\r |
a13899c5 | 673 | return false;\r |
674 | }\r | |
675 | if (isEmpty(trg)) {\r | |
72a0d8e6 | 676 | Log.wrn("Clone", "The destination file path must be entered!");\r |
a13899c5 | 677 | return false;\r |
678 | }\r | |
679 | if (src.equals(trg)) {\r | |
72a0d8e6 | 680 | Log.wrn("Clone", "The source and destination can not be same!");\r |
a13899c5 | 681 | return false;\r |
682 | }\r | |
683 | if (trgFile.exists()) {\r | |
72a0d8e6 | 684 | Log.wrn("Clone", "The destination already exists!");\r |
a13899c5 | 685 | return false;\r |
686 | }\r | |
687 | \r | |
688 | //\r | |
689 | // Check for workspace\r | |
690 | //\r | |
691 | if (mode == DataType.RETURN_TYPE_WORKSPACE) {\r | |
692 | if (trg.indexOf(src + DataType.FILE_SEPARATOR) == 0) {\r | |
72a0d8e6 | 693 | Log.wrn("Clone", "The new workspace can not be located within the current workspace!");\r |
a13899c5 | 694 | return false;\r |
695 | }\r | |
696 | }\r | |
697 | \r | |
698 | //\r | |
699 | // Check for Module\r | |
700 | //\r | |
701 | if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r | |
79cb6fdb | 702 | trg = this.getModulePath();\r |
d8be5b14 | 703 | if (Tools.getFilePathOnly(src).equals(Tools.getFilePathOnly(trg))) {\r |
72a0d8e6 | 704 | Log.wrn("Clone", "The source and destination paths for cloning a module must be different!");\r |
79cb6fdb | 705 | return false;\r |
706 | }\r | |
707 | trgFile = new File(trg);\r | |
708 | if (trgFile.exists()) {\r | |
72a0d8e6 | 709 | Log.wrn("Clone", "The target module already exists!");\r |
79cb6fdb | 710 | return false;\r |
711 | }\r | |
3cbeeeb8 | 712 | \r |
713 | //\r | |
714 | // Check if path already exists\r | |
715 | // Currently we allow user to add multiple msa files in one same directory\r | |
716 | // Remove this checkpoint\r | |
717 | //\r | |
718 | // if (GlobalData.isDuplicateRelativePath(Tools.getFilePathOnly(trg), mode)) {\r | |
719 | // Log.wrn("Clone", "There already exists a same directory with a module");\r | |
720 | // return false;\r | |
721 | // }\r | |
fc87d0ba | 722 | \r |
d8be5b14 | 723 | return checkId(mode);\r |
a13899c5 | 724 | }\r |
725 | \r | |
726 | //\r | |
727 | // Check for Package\r | |
728 | //\r | |
729 | if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r | |
730 | if (trg.indexOf(DataType.DOS_FILE_SEPARATOR) == -1 && trg.indexOf(DataType.UNIX_FILE_SEPARATOR) == -1) {\r | |
72a0d8e6 | 731 | Log.wrn("Clone", "The package name must include a path!");\r |
a13899c5 | 732 | return false;\r |
733 | }\r | |
734 | trg = this.getPackagePath();\r | |
735 | if (Tools.getFilePathOnly(src).equals(Tools.getFilePathOnly(trg))) {\r | |
72a0d8e6 | 736 | Log.wrn("Clone", "The source and destination paths for cloning a package must be different!");\r |
a13899c5 | 737 | return false;\r |
738 | }\r | |
739 | trgFile = new File(trg);\r | |
740 | if (trgFile.exists()) {\r | |
72a0d8e6 | 741 | Log.wrn("Clone", "The target package already exists!");\r |
a13899c5 | 742 | return false;\r |
743 | }\r | |
fc87d0ba | 744 | if (GlobalData.isDuplicateRelativePath(Tools.getFilePathOnly(trg), mode)) {\r |
745 | Log.wrn("Clone", "There already exists a same directory with a package");\r | |
746 | return false;\r | |
747 | }\r | |
748 | \r | |
d8be5b14 | 749 | return checkId(mode);\r |
a13899c5 | 750 | }\r |
751 | \r | |
752 | //\r | |
753 | // Check for Platform\r | |
754 | //\r | |
755 | if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r | |
756 | if (trg.indexOf(Workspace.getCurrentWorkspace()) != 0) {\r | |
72a0d8e6 | 757 | Log.wrn("Clone", "The platform clone must be located in the current workspace!");\r |
a13899c5 | 758 | return false;\r |
759 | }\r | |
d8be5b14 | 760 | if (Tools.getFilePathOnly(src).equals(Tools.getFilePathOnly(trg))) {\r |
761 | Log.wrn("Clone", "The source and destination paths for cloning a platform must be different!");\r | |
762 | return false;\r | |
763 | }\r | |
a13899c5 | 764 | trgFile = new File(trg);\r |
765 | if (trgFile.exists()) {\r | |
72a0d8e6 | 766 | Log.wrn("Clone", "The target platform already exists.");\r |
a13899c5 | 767 | return false;\r |
768 | }\r | |
fc87d0ba | 769 | if (GlobalData.isDuplicateRelativePath(Tools.getFilePathOnly(trg), mode)) {\r |
770 | Log.wrn("Clone", "There already exists a same directory with a platform");\r | |
771 | return false;\r | |
772 | }\r | |
773 | \r | |
d8be5b14 | 774 | return checkId(mode);\r |
a13899c5 | 775 | }\r |
776 | \r | |
777 | return true;\r | |
778 | }\r | |
779 | \r | |
43dc3851 | 780 | /**\r |
781 | Save clone target to new location\r | |
782 | \r | |
783 | @throws IOException\r | |
784 | @throws XmlException\r | |
785 | @throws Exception\r | |
786 | \r | |
787 | **/\r | |
a13899c5 | 788 | private void save() throws IOException, XmlException, Exception {\r |
55a2762d | 789 | String src = this.oldId.getPath();\r |
a13899c5 | 790 | String trg = this.jTextFieldFilePath.getText();\r |
79cb6fdb | 791 | Vector<String> vFiles = new Vector<String>();\r |
ed1665f2 | 792 | \r |
a13899c5 | 793 | //\r |
794 | // Clone Workspace\r | |
795 | //\r | |
796 | if (mode == DataType.RETURN_TYPE_WORKSPACE) {\r | |
ed1665f2 | 797 | FileOperation.copyFolder(src, trg);\r |
a13899c5 | 798 | this.returnType = DataType.RETURN_TYPE_WORKSPACE;\r |
799 | }\r | |
800 | \r | |
801 | //\r | |
802 | // Clone Module Surface Area\r | |
803 | //\r | |
804 | if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r | |
805 | //\r | |
806 | // Get target path from source path\r | |
807 | //\r | |
808 | trg = getModulePath();\r | |
809 | newId.setPath(trg);\r | |
739c6b04 | 810 | vFiles = wt.getAllFilesPathOfModule(src);\r |
ed1665f2 | 811 | \r |
37bd8fbb | 812 | String oldPackagePath = GlobalData.openingModuleList.getIdByPath(src).getPackageId().getPath();\r |
813 | String newPackagePath = packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getPath();\r | |
814 | \r | |
a13899c5 | 815 | //\r |
816 | // First copy all files to new directory\r | |
817 | //\r | |
79cb6fdb | 818 | FileOperation.copyFile(src, trg);\r |
819 | for (int index = 1; index < vFiles.size(); index++) {\r | |
820 | String oldFile = vFiles.get(index);\r | |
37bd8fbb | 821 | String newFile = "";\r |
822 | if (oldFile.indexOf(Tools.getFilePathOnly(src)) > -1) {\r | |
823 | //\r | |
824 | // The file is not include header\r | |
825 | //\r | |
826 | newFile = oldFile.replace(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));\r | |
827 | } else if (oldFile.indexOf(Tools.getFilePathOnly(oldPackagePath)) > -1) {\r | |
828 | //\r | |
829 | // The file is include header\r | |
830 | //\r | |
831 | newFile = oldFile.replace(Tools.getFilePathOnly(oldPackagePath),\r | |
832 | Tools.getFilePathOnly(newPackagePath));\r | |
833 | }\r | |
834 | \r | |
79cb6fdb | 835 | FileOperation.copyFile(oldFile, newFile);\r |
836 | }\r | |
a13899c5 | 837 | \r |
838 | //\r | |
839 | // Create new msa file\r | |
840 | //\r | |
841 | ModuleSurfaceArea msa = null;\r | |
842 | msa = OpenFile.openMsaFile(src);\r | |
843 | \r | |
844 | //\r | |
845 | // Update to memory\r | |
846 | //\r | |
847 | msa.getMsaHeader().setModuleName(newId.getName());\r | |
848 | msa.getMsaHeader().setGuidValue(newId.getGuid());\r | |
849 | msa.getMsaHeader().setVersion(newId.getVersion());\r | |
850 | \r | |
851 | //\r | |
43dc3851 | 852 | // Update <Cloned> Section\r |
a13899c5 | 853 | //\r |
854 | updateModuleClonedId(msa, oldId);\r | |
37bd8fbb | 855 | \r |
a13899c5 | 856 | //\r |
857 | // Save to file\r | |
858 | //\r | |
859 | SaveFile.saveMsaFile(trg, msa);\r | |
860 | \r | |
861 | //\r | |
862 | // Update to platformId\r | |
863 | //\r | |
ed1665f2 | 864 | this.setMid(new ModuleIdentification(newId,\r |
865 | packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())));\r | |
a13899c5 | 866 | \r |
867 | //\r | |
868 | // Open belonging package\r | |
869 | //\r | |
870 | PackageSurfaceArea psa = PackageSurfaceArea.Factory.newInstance();\r | |
871 | psa = OpenFile.openSpdFile(mid.getPackageId().getPath());\r | |
ed1665f2 | 872 | \r |
a13899c5 | 873 | //\r |
874 | // Update the db file\r | |
875 | //\r | |
876 | wt.addModuleToPackage(mid, psa);\r | |
37bd8fbb | 877 | \r |
09ef9242 | 878 | //\r |
879 | // Update GlobalData\r | |
880 | //\r | |
881 | GlobalData.vModuleList.addElement(mid);\r | |
882 | GlobalData.openingModuleList.insertToOpeningModuleList(mid, msa);\r | |
a13899c5 | 883 | \r |
884 | this.returnType = DataType.RETURN_TYPE_MODULE_SURFACE_AREA;\r | |
885 | }\r | |
886 | \r | |
887 | //\r | |
888 | // Clone Package Surface Area\r | |
889 | //\r | |
890 | if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r | |
891 | //\r | |
892 | // Get target path from source path\r | |
893 | //\r | |
894 | trg = this.getPackagePath();\r | |
895 | newId.setPath(trg);\r | |
739c6b04 | 896 | vFiles = wt.getAllFilesPathOfPakcage(src);\r |
ed1665f2 | 897 | \r |
43dc3851 | 898 | //\r |
899 | // First copy all files to new directory\r | |
900 | //\r | |
79cb6fdb | 901 | FileOperation.copyFile(src, trg);\r |
902 | for (int index = 1; index < vFiles.size(); index++) {\r | |
903 | String oldFile = vFiles.get(index);\r | |
904 | String newFile = vFiles.get(index).replace(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));\r | |
905 | FileOperation.copyFile(oldFile, newFile);\r | |
906 | }\r | |
ed1665f2 | 907 | \r |
a13899c5 | 908 | //\r |
909 | // Create new spd file\r | |
910 | //\r | |
911 | PackageSurfaceArea spd = null;\r | |
912 | spd = OpenFile.openSpdFile(src);\r | |
913 | \r | |
914 | //\r | |
915 | // Update to memory\r | |
916 | //\r | |
917 | spd.getSpdHeader().setPackageName(newId.getName());\r | |
918 | spd.getSpdHeader().setGuidValue(newId.getGuid());\r | |
919 | spd.getSpdHeader().setVersion(newId.getVersion());\r | |
920 | \r | |
921 | //\r | |
43dc3851 | 922 | // Update <Cloned> Section\r |
a13899c5 | 923 | //\r |
924 | updatePackageClonedId(spd, oldId);\r | |
ed1665f2 | 925 | \r |
a13899c5 | 926 | //\r |
927 | // Save to file\r | |
928 | //\r | |
929 | SaveFile.saveSpdFile(trg, spd);\r | |
930 | \r | |
931 | //\r | |
932 | // Update to platformId\r | |
933 | //\r | |
934 | this.setPid(new PackageIdentification(newId));\r | |
935 | \r | |
936 | //\r | |
937 | // Update the db file\r | |
938 | //\r | |
939 | wt.addPackageToDatabase(pid);\r | |
37bd8fbb | 940 | \r |
09ef9242 | 941 | //\r |
942 | // Update GlobalData\r | |
943 | //\r | |
944 | GlobalData.vPackageList.addElement(pid);\r | |
945 | GlobalData.openingPackageList.insertToOpeningPackageList(pid, spd);\r | |
37bd8fbb | 946 | \r |
4917d9dd | 947 | //\r |
948 | // Add all cloned modules\r | |
949 | //\r | |
950 | Vector<String> modulePaths = GlobalData.getAllModulesOfPackage(pid.getPath());\r | |
951 | String modulePath = null;\r | |
952 | ModuleSurfaceArea msa = null;\r | |
37bd8fbb | 953 | \r |
4917d9dd | 954 | for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {\r |
955 | try {\r | |
956 | modulePath = modulePaths.get(indexJ);\r | |
957 | msa = OpenFile.openMsaFile(modulePath);\r | |
958 | } catch (IOException e) {\r | |
959 | Log.err("Open Module Surface Area " + modulePath, e.getMessage());\r | |
960 | continue;\r | |
961 | } catch (XmlException e) {\r | |
962 | Log.err("Open Module Surface Area " + modulePath, e.getMessage());\r | |
963 | continue;\r | |
964 | } catch (Exception e) {\r | |
965 | Log.err("Open Module Surface Area " + modulePath, "Invalid file type");\r | |
966 | continue;\r | |
967 | }\r | |
968 | Identification id = Tools.getId(modulePath, msa);\r | |
969 | mid = new ModuleIdentification(id, pid);\r | |
970 | GlobalData.vModuleList.addElement(mid);\r | |
971 | GlobalData.openingModuleList.insertToOpeningModuleList(mid, msa);\r | |
972 | }\r | |
37bd8fbb | 973 | \r |
a13899c5 | 974 | this.returnType = DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA;\r |
975 | }\r | |
976 | \r | |
977 | //\r | |
978 | // Clone Platform Surface Area\r | |
979 | //\r | |
980 | if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r | |
981 | PlatformSurfaceArea fpd = null;\r | |
982 | fpd = OpenFile.openFpdFile(src);\r | |
983 | \r | |
984 | //\r | |
985 | // Update to memory\r | |
986 | //\r | |
987 | fpd.getPlatformHeader().setPlatformName(newId.getName());\r | |
988 | fpd.getPlatformHeader().setGuidValue(newId.getGuid());\r | |
989 | fpd.getPlatformHeader().setVersion(newId.getVersion());\r | |
990 | \r | |
991 | //\r | |
992 | // Update Cloned From element\r | |
993 | //\r | |
994 | updatePlatformClonedId(fpd, oldId);\r | |
995 | \r | |
996 | //\r | |
997 | // Save to file\r | |
998 | //\r | |
999 | SaveFile.saveFpdFile(trg, fpd);\r | |
1000 | \r | |
1001 | //\r | |
1002 | // Update to platformId\r | |
1003 | //\r | |
1004 | this.setFid(new PlatformIdentification(newId));\r | |
1005 | \r | |
1006 | //\r | |
1007 | // Update the db file\r | |
1008 | //\r | |
1009 | wt.addPlatformToDatabase(fid);\r | |
37bd8fbb | 1010 | \r |
09ef9242 | 1011 | //\r |
1012 | // Update GlobalData\r | |
1013 | //\r | |
1014 | GlobalData.vPlatformList.addElement(fid);\r | |
1015 | GlobalData.openingPlatformList.insertToOpeningPlatformList(fid, fpd);\r | |
a13899c5 | 1016 | \r |
1017 | this.returnType = DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA;\r | |
1018 | }\r | |
79cb6fdb | 1019 | vFiles = null;\r |
a13899c5 | 1020 | }\r |
ed1665f2 | 1021 | \r |
43dc3851 | 1022 | /**\r |
1023 | Get the path of selected package\r | |
1024 | \r | |
1025 | @return String The path of selected package\r | |
1026 | \r | |
1027 | **/\r | |
a13899c5 | 1028 | private String getSelectPackagePath() {\r |
1029 | return Tools.getFilePathOnly(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getPath());\r | |
1030 | }\r | |
1031 | \r | |
43dc3851 | 1032 | /**\r |
1033 | Get the path of source module\r | |
1034 | Since the path of source module is relative, make it up to full path.\r | |
1035 | \r | |
1036 | @return String The full path of source module\r | |
1037 | \r | |
1038 | **/\r | |
a13899c5 | 1039 | private String getModulePath() {\r |
1040 | String trg = this.jTextFieldFilePath.getText();\r | |
1041 | trg = Tools.addPathExt(trg, mode);\r | |
79cb6fdb | 1042 | trg = Tools.addFileSeparator(getSelectPackagePath()) + trg;\r |
a13899c5 | 1043 | Tools.convertPathToCurrentOsType(trg);\r |
1044 | return trg;\r | |
1045 | }\r | |
ed1665f2 | 1046 | \r |
43dc3851 | 1047 | /**\r |
1048 | Get the path of source package\r | |
1049 | Since the path of source package is relative, make it up to full path.\r | |
1050 | \r | |
1051 | @return String The full path of source package\r | |
1052 | \r | |
1053 | **/\r | |
a13899c5 | 1054 | private String getPackagePath() {\r |
1055 | String trg = this.jTextFieldFilePath.getText();\r | |
1056 | trg = Tools.addPathExt(trg, mode);\r | |
79cb6fdb | 1057 | trg = Tools.addFileSeparator(Workspace.getCurrentWorkspace()) + trg;\r |
a13899c5 | 1058 | trg = Tools.convertPathToCurrentOsType(trg);\r |
1059 | return trg;\r | |
1060 | }\r | |
ed1665f2 | 1061 | \r |
a13899c5 | 1062 | /**\r |
43dc3851 | 1063 | Set msa file's <Cloned> section via given identification\r |
1064 | \r | |
1065 | @param msa ModuleSurfaceArea for clone target\r | |
1066 | @param id Identification of clone source\r | |
1067 | \r | |
a13899c5 | 1068 | **/\r |
1069 | private void updateModuleClonedId(ModuleSurfaceArea msa, Identification id) {\r | |
1070 | //\r | |
1071 | // Get PlatformDefinitions First\r | |
1072 | //\r | |
1073 | ModuleDefinitions pd = null;\r | |
1074 | if (msa.getModuleDefinitions() == null) {\r | |
1075 | pd = ModuleDefinitions.Factory.newInstance();\r | |
1076 | msa.addNewModuleDefinitions();\r | |
1077 | } else {\r | |
1078 | pd = msa.getModuleDefinitions();\r | |
1079 | }\r | |
1080 | \r | |
1081 | //\r | |
1082 | // Get ClonedFrom then\r | |
1083 | //\r | |
1084 | ModuleDefinitions.ClonedFrom cf = null;\r | |
79cb6fdb | 1085 | BigInteger count = new BigInteger("-1");\r |
a13899c5 | 1086 | if (pd.getClonedFrom() == null) {\r |
1087 | cf = ModuleDefinitions.ClonedFrom.Factory.newInstance();\r | |
1088 | } else {\r | |
1089 | cf = pd.getClonedFrom();\r | |
79cb6fdb | 1090 | if (cf != null) {\r |
1091 | for (int index = 0; index < cf.getClonedList().size(); index++) {\r | |
1092 | if (cf.getClonedList().get(index).getId() != null) {\r | |
1093 | count = count.max(cf.getClonedList().get(index).getId());\r | |
1094 | }\r | |
1095 | }\r | |
1096 | }\r | |
a13899c5 | 1097 | }\r |
1098 | \r | |
1099 | //\r | |
1100 | // Set new Cloned item\r | |
1101 | //\r | |
1102 | ModuleDefinitions.ClonedFrom.Cloned c = ModuleDefinitions.ClonedFrom.Cloned.Factory.newInstance();\r | |
1103 | c.setModuleGuid(id.getGuid());\r | |
1104 | c.setModuleVersion(id.getVersion());\r | |
79cb6fdb | 1105 | c.setPackageGuid(wt.getPackageIdByModuleId(oldId).getGuid());\r |
1106 | c.setPackageVersion(wt.getPackageIdByModuleId(oldId).getVersion());\r | |
1107 | c.setId(count.add(new BigInteger("1")));\r | |
55a2762d | 1108 | String guid = wt.getModuleFarGuid(oldId);\r |
1109 | if (guid != null && !guid.equals("")) {\r | |
ed1665f2 | 1110 | c.setFarGuid(guid);\r |
55a2762d | 1111 | }\r |
a13899c5 | 1112 | \r |
1113 | cf.addNewCloned();\r | |
1114 | cf.setClonedArray(cf.getClonedList().size() - 1, c);\r | |
1115 | pd.addNewClonedFrom();\r | |
1116 | pd.setClonedFrom(cf);\r | |
1117 | msa.setModuleDefinitions(pd);\r | |
1118 | }\r | |
1119 | \r | |
1120 | /**\r | |
43dc3851 | 1121 | Set spd file's <Cloned> section via given identification\r |
a13899c5 | 1122 | \r |
43dc3851 | 1123 | @param spd PackageSurfaceArea for clone target\r |
1124 | @param id Identification of clone source\r | |
a13899c5 | 1125 | \r |
1126 | **/\r | |
1127 | private void updatePackageClonedId(PackageSurfaceArea spd, Identification id) {\r | |
1128 | //\r | |
1129 | // Get PlatformDefinitions First\r | |
1130 | //\r | |
1131 | PackageDefinitions pd = null;\r | |
1132 | if (spd.getPackageDefinitions() == null) {\r | |
1133 | pd = PackageDefinitions.Factory.newInstance();\r | |
1134 | spd.addNewPackageDefinitions();\r | |
1135 | } else {\r | |
1136 | pd = spd.getPackageDefinitions();\r | |
1137 | }\r | |
1138 | \r | |
1139 | //\r | |
1140 | // Get ClonedFrom then\r | |
1141 | //\r | |
1142 | PackageDefinitions.ClonedFrom cf = null;\r | |
79cb6fdb | 1143 | BigInteger count = new BigInteger("-1");\r |
a13899c5 | 1144 | if (pd.getClonedFrom() == null) {\r |
1145 | cf = PackageDefinitions.ClonedFrom.Factory.newInstance();\r | |
1146 | } else {\r | |
1147 | cf = pd.getClonedFrom();\r | |
79cb6fdb | 1148 | if (cf != null) {\r |
1149 | for (int index = 0; index < cf.getClonedList().size(); index++) {\r | |
1150 | if (cf.getClonedList().get(index).getId() != null) {\r | |
1151 | count = count.max(cf.getClonedList().get(index).getId());\r | |
1152 | }\r | |
1153 | }\r | |
1154 | }\r | |
a13899c5 | 1155 | }\r |
1156 | \r | |
1157 | //\r | |
1158 | // Set new Cloned item\r | |
1159 | //\r | |
1160 | PackageDefinitions.ClonedFrom.Cloned c = PackageDefinitions.ClonedFrom.Cloned.Factory.newInstance();\r | |
1161 | c.setPackageGuid(id.getGuid());\r | |
1162 | c.setPackageVersion(id.getVersion());\r | |
79cb6fdb | 1163 | c.setId(count.add(new BigInteger("1")));\r |
09ef9242 | 1164 | String guid = wt.getPackageFarGuid(oldId);\r |
55a2762d | 1165 | if (guid != null && !guid.equals("")) {\r |
ed1665f2 | 1166 | c.setFarGuid(guid);\r |
55a2762d | 1167 | }\r |
a13899c5 | 1168 | \r |
1169 | cf.addNewCloned();\r | |
1170 | cf.setClonedArray(cf.getClonedList().size() - 1, c);\r | |
1171 | pd.addNewClonedFrom();\r | |
1172 | pd.setClonedFrom(cf);\r | |
1173 | spd.setPackageDefinitions(pd);\r | |
1174 | }\r | |
1175 | \r | |
1176 | /**\r | |
43dc3851 | 1177 | Set fpd file's <Cloned> section via given identification\r |
a13899c5 | 1178 | \r |
43dc3851 | 1179 | @param fpd PlatformSurfaceArea for clone target\r |
1180 | @param id Identification of clone source\r | |
a13899c5 | 1181 | \r |
1182 | **/\r | |
1183 | private void updatePlatformClonedId(PlatformSurfaceArea fpd, Identification id) {\r | |
1184 | //\r | |
1185 | // Get PlatformDefinitions First\r | |
1186 | //\r | |
1187 | PlatformDefinitions pd = null;\r | |
1188 | if (fpd.getPlatformDefinitions() == null) {\r | |
1189 | pd = PlatformDefinitions.Factory.newInstance();\r | |
1190 | fpd.addNewPlatformDefinitions();\r | |
1191 | } else {\r | |
1192 | pd = fpd.getPlatformDefinitions();\r | |
1193 | }\r | |
1194 | \r | |
1195 | //\r | |
1196 | // Get ClonedFrom then\r | |
1197 | //\r | |
1198 | PlatformDefinitions.ClonedFrom cf = null;\r | |
79cb6fdb | 1199 | BigInteger count = new BigInteger("-1");\r |
a13899c5 | 1200 | if (pd.getClonedFrom() == null) {\r |
1201 | cf = PlatformDefinitions.ClonedFrom.Factory.newInstance();\r | |
1202 | } else {\r | |
1203 | cf = pd.getClonedFrom();\r | |
79cb6fdb | 1204 | if (cf != null) {\r |
1205 | for (int index = 0; index < cf.getClonedList().size(); index++) {\r | |
1206 | if (cf.getClonedList().get(index).getId() != null) {\r | |
1207 | count = count.max(cf.getClonedList().get(index).getId());\r | |
1208 | }\r | |
1209 | }\r | |
1210 | }\r | |
a13899c5 | 1211 | }\r |
1212 | \r | |
1213 | //\r | |
1214 | // Set new Cloned item\r | |
1215 | //\r | |
1216 | PlatformDefinitions.ClonedFrom.Cloned c = PlatformDefinitions.ClonedFrom.Cloned.Factory.newInstance();\r | |
1217 | c.setPlatformGuid(id.getGuid());\r | |
1218 | c.setPlatformVersion(id.getVersion());\r | |
79cb6fdb | 1219 | c.setId(count.add(new BigInteger("1")));\r |
09ef9242 | 1220 | String guid = wt.getPlatformFarGuid(oldId);\r |
55a2762d | 1221 | if (guid != null && !guid.equals("")) {\r |
ed1665f2 | 1222 | c.setFarGuid(guid);\r |
55a2762d | 1223 | }\r |
ed1665f2 | 1224 | \r |
a13899c5 | 1225 | cf.addNewCloned();\r |
1226 | cf.setClonedArray(cf.getClonedList().size() - 1, c);\r | |
1227 | pd.addNewClonedFrom();\r | |
1228 | pd.setClonedFrom(cf);\r | |
1229 | fpd.setPlatformDefinitions(pd);\r | |
1230 | }\r | |
1231 | \r | |
43dc3851 | 1232 | /**\r |
1233 | Get PlatformIdentification\r | |
1234 | \r | |
1235 | @return PlatformIdentification\r | |
1236 | \r | |
1237 | **/\r | |
a13899c5 | 1238 | public PlatformIdentification getFid() {\r |
1239 | return fid;\r | |
1240 | }\r | |
1241 | \r | |
43dc3851 | 1242 | /**\r |
1243 | Set PlatformIdentification\r | |
1244 | \r | |
1245 | @param fid PlatformIdentification\r | |
1246 | \r | |
1247 | **/\r | |
a13899c5 | 1248 | public void setFid(PlatformIdentification fid) {\r |
1249 | this.fid = fid;\r | |
1250 | }\r | |
1251 | \r | |
43dc3851 | 1252 | /**\r |
1253 | Get ModuleIdentification\r | |
1254 | \r | |
1255 | @return ModuleIdentification\r | |
1256 | \r | |
1257 | **/\r | |
a13899c5 | 1258 | public ModuleIdentification getMid() {\r |
1259 | return mid;\r | |
1260 | }\r | |
1261 | \r | |
43dc3851 | 1262 | /**\r |
1263 | Set ModuleIdentification\r | |
1264 | \r | |
1265 | @param mid ModuleIdentification\r | |
1266 | \r | |
1267 | **/\r | |
a13899c5 | 1268 | public void setMid(ModuleIdentification mid) {\r |
1269 | this.mid = mid;\r | |
1270 | }\r | |
1271 | \r | |
43dc3851 | 1272 | /**\r |
1273 | Get PackageIdentification\r | |
1274 | \r | |
1275 | @return PackageIdentification\r | |
1276 | \r | |
1277 | **/\r | |
a13899c5 | 1278 | public PackageIdentification getPid() {\r |
1279 | return pid;\r | |
1280 | }\r | |
1281 | \r | |
43dc3851 | 1282 | /**\r |
1283 | Set PackageIdentification\r | |
1284 | \r | |
1285 | @param pid PackageIdentification\r | |
1286 | \r | |
1287 | **/\r | |
a13899c5 | 1288 | public void setPid(PackageIdentification pid) {\r |
1289 | this.pid = pid;\r | |
1290 | }\r | |
1291 | }\r |