]>
Commit | Line | Data |
---|---|---|
a13899c5 | 1 | /** @file\r |
2 | \r | |
3 | The file is used to let user choose to create module in an existing package\r | |
4 | or to create a new package first.\r | |
5 | \r | |
6 | Copyright (c) 2006, Intel Corporation\r | |
7 | All rights reserved. This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | package org.tianocore.frameworkwizard;\r | |
17 | \r | |
92e29378 | 18 | import java.awt.Component;\r |
a13899c5 | 19 | import java.awt.event.ActionEvent;\r |
20 | import java.io.File;\r | |
21 | import java.util.Vector;\r | |
22 | \r | |
92e29378 | 23 | import javax.swing.ButtonGroup;\r |
a13899c5 | 24 | import javax.swing.JButton;\r |
25 | import javax.swing.JComboBox;\r | |
26 | import javax.swing.JFileChooser;\r | |
27 | import javax.swing.JLabel;\r | |
28 | import javax.swing.JPanel;\r | |
29 | import javax.swing.JTextField;\r | |
30 | \r | |
d1760183 | 31 | import org.tianocore.ModuleTypeDef;\r |
a13899c5 | 32 | import org.tianocore.MsaHeaderDocument;\r |
33 | import org.tianocore.SpdHeaderDocument;\r | |
739c6b04 | 34 | import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r |
a13899c5 | 35 | import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r |
36 | import org.tianocore.PlatformHeaderDocument.PlatformHeader;\r | |
37 | import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;\r | |
38 | import org.tianocore.frameworkwizard.common.DataType;\r | |
39 | import org.tianocore.frameworkwizard.common.DataValidation;\r | |
40 | import org.tianocore.frameworkwizard.common.IFileFilter;\r | |
41 | import org.tianocore.frameworkwizard.common.Log;\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.common.ui.StarLabel;\r | |
79cb6fdb | 47 | import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r |
a13899c5 | 48 | import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r |
49 | import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r | |
50 | import org.tianocore.frameworkwizard.workspace.Workspace;\r | |
51 | import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r | |
92e29378 | 52 | import javax.swing.JRadioButton;\r |
a13899c5 | 53 | \r |
54 | public class SelectModuleBelong extends IDialog {\r | |
55 | \r | |
56 | /**\r | |
57 | Define class members\r | |
58 | \r | |
59 | **/\r | |
60 | private static final long serialVersionUID = 4171355136991448972L;\r | |
61 | \r | |
f9d0ab92 | 62 | private JPanel jContentPane = null;\r |
a13899c5 | 63 | \r |
64 | private JComboBox jComboBoxExistingPackage = null;\r | |
65 | \r | |
66 | private JButton jButtonOk = null;\r | |
67 | \r | |
68 | private JButton jButtonCancel = null;\r | |
69 | \r | |
70 | private Vector<PackageIdentification> packages = null;\r | |
71 | \r | |
72 | private JLabel jLabelPackage = null;\r | |
73 | \r | |
74 | private JLabel jLabelFilePath = null;\r | |
75 | \r | |
76 | private JTextField jTextFieldFilePath = null;\r | |
77 | \r | |
78 | private JButton jButtonBrowse = null;\r | |
79 | \r | |
80 | private JLabel jLabelName = null;\r | |
81 | \r | |
82 | private JTextField jTextFieldName = null;\r | |
83 | \r | |
84 | private JLabel jLabelGuid = null;\r | |
85 | \r | |
86 | private JTextField jTextFieldGuid = null;\r | |
87 | \r | |
88 | private JButton jButtonGen = null;\r | |
89 | \r | |
90 | private JLabel jLabelVersion = null;\r | |
91 | \r | |
92 | private JTextField jTextFieldVersion = null;\r | |
93 | \r | |
94 | private StarLabel jStarLabel1 = null;\r | |
95 | \r | |
96 | private StarLabel jStarLabel2 = null;\r | |
97 | \r | |
98 | private StarLabel jStarLabel3 = null;\r | |
99 | \r | |
100 | private StarLabel jStarLabel4 = null;\r | |
101 | \r | |
102 | private StarLabel jStarLabel5 = null;\r | |
f9d0ab92 | 103 | \r |
92e29378 | 104 | private ButtonGroup bg = new ButtonGroup();\r |
a13899c5 | 105 | \r |
106 | private WorkspaceTools wt = new WorkspaceTools();\r | |
107 | \r | |
108 | private ModuleIdentification mid = null;\r | |
109 | \r | |
110 | private PackageIdentification pid = null;\r | |
111 | \r | |
112 | private PlatformIdentification fid = null;\r | |
739c6b04 | 113 | \r |
114 | private ModuleSurfaceArea msa = null;\r | |
115 | \r | |
116 | private PackageSurfaceArea spd = null;\r | |
117 | \r | |
118 | private PlatformSurfaceArea fpd = null;\r | |
a13899c5 | 119 | \r |
120 | private int mode = -1;\r | |
121 | \r | |
92e29378 | 122 | private JLabel jLabelIsLibrary = null;\r |
123 | \r | |
124 | private JRadioButton jRadioButtonYes = null;\r | |
125 | \r | |
126 | private JRadioButton jRadioButtonNo = null;\r | |
127 | \r | |
a13899c5 | 128 | /**\r |
129 | * This method initializes jComboBoxExistingPackage \r | |
130 | * \r | |
131 | * @return javax.swing.JComboBox \r | |
132 | */\r | |
133 | private JComboBox getJComboBoxExistingPackage() {\r | |
134 | if (jComboBoxExistingPackage == null) {\r | |
135 | jComboBoxExistingPackage = new JComboBox();\r | |
136 | jComboBoxExistingPackage.setBounds(new java.awt.Rectangle(140, 10, 340, 20));\r | |
137 | }\r | |
138 | return jComboBoxExistingPackage;\r | |
139 | }\r | |
140 | \r | |
141 | /**\r | |
142 | * This method initializes jButtonNext \r | |
143 | * \r | |
144 | * @return javax.swing.JButton \r | |
145 | */\r | |
146 | private JButton getJButtonOk() {\r | |
147 | if (jButtonOk == null) {\r | |
148 | jButtonOk = new JButton();\r | |
92e29378 | 149 | jButtonOk.setBounds(new java.awt.Rectangle(310, 165, 80, 20));\r |
a13899c5 | 150 | jButtonOk.setText("Ok");\r |
151 | jButtonOk.addActionListener(this);\r | |
152 | }\r | |
153 | return jButtonOk;\r | |
154 | }\r | |
155 | \r | |
156 | /**\r | |
157 | * This method initializes jButtonCancel \r | |
158 | * \r | |
159 | * @return javax.swing.JButton \r | |
160 | */\r | |
161 | private JButton getJButtonCancel() {\r | |
162 | if (jButtonCancel == null) {\r | |
163 | jButtonCancel = new JButton();\r | |
92e29378 | 164 | jButtonCancel.setBounds(new java.awt.Rectangle(395, 165, 80, 20));\r |
a13899c5 | 165 | jButtonCancel.setText("Cancel");\r |
166 | jButtonCancel.addActionListener(this);\r | |
167 | }\r | |
168 | return jButtonCancel;\r | |
169 | }\r | |
170 | \r | |
171 | /**\r | |
172 | * This method initializes jTextFieldFilePath \r | |
173 | * \r | |
174 | * @return javax.swing.JTextField \r | |
175 | */\r | |
176 | private JTextField getJTextFieldFilePath() {\r | |
177 | if (jTextFieldFilePath == null) {\r | |
178 | jTextFieldFilePath = new JTextField();\r | |
92e29378 | 179 | jTextFieldFilePath.setBounds(new java.awt.Rectangle(140, 60, 250, 20));\r |
a13899c5 | 180 | }\r |
181 | return jTextFieldFilePath;\r | |
182 | }\r | |
183 | \r | |
184 | /**\r | |
185 | * This method initializes jButtonBrowse \r | |
186 | * \r | |
187 | * @return javax.swing.JButton \r | |
188 | */\r | |
189 | private JButton getJButtonBrowse() {\r | |
190 | if (jButtonBrowse == null) {\r | |
191 | jButtonBrowse = new JButton();\r | |
92e29378 | 192 | jButtonBrowse.setBounds(new java.awt.Rectangle(395, 60, 85, 20));\r |
a13899c5 | 193 | jButtonBrowse.setText("Browse");\r |
194 | jButtonBrowse.addActionListener(this);\r | |
195 | }\r | |
196 | return jButtonBrowse;\r | |
197 | }\r | |
198 | \r | |
199 | /**\r | |
200 | * This method initializes jTextFieldModuleName \r | |
201 | * \r | |
202 | * @return javax.swing.JTextField \r | |
203 | */\r | |
204 | private JTextField getJTextFieldName() {\r | |
205 | if (jTextFieldName == null) {\r | |
206 | jTextFieldName = new JTextField();\r | |
92e29378 | 207 | jTextFieldName.setBounds(new java.awt.Rectangle(140, 85, 340, 20));\r |
a13899c5 | 208 | }\r |
209 | return jTextFieldName;\r | |
210 | }\r | |
211 | \r | |
212 | /**\r | |
213 | * This method initializes jTextFieldGuid \r | |
214 | * \r | |
215 | * @return javax.swing.JTextField \r | |
216 | */\r | |
217 | private JTextField getJTextFieldGuid() {\r | |
218 | if (jTextFieldGuid == null) {\r | |
219 | jTextFieldGuid = new JTextField();\r | |
92e29378 | 220 | jTextFieldGuid.setBounds(new java.awt.Rectangle(140, 110, 250, 20));\r |
a13899c5 | 221 | }\r |
222 | return jTextFieldGuid;\r | |
223 | }\r | |
224 | \r | |
225 | /**\r | |
226 | * This method initializes jButtonGen \r | |
227 | * \r | |
228 | * @return javax.swing.JButton \r | |
229 | */\r | |
230 | private JButton getJButtonGen() {\r | |
231 | if (jButtonGen == null) {\r | |
232 | jButtonGen = new JButton();\r | |
92e29378 | 233 | jButtonGen.setBounds(new java.awt.Rectangle(395, 110, 85, 20));\r |
a13899c5 | 234 | jButtonGen.setText("GEN");\r |
235 | jButtonGen.addActionListener(this);\r | |
236 | }\r | |
237 | return jButtonGen;\r | |
238 | }\r | |
239 | \r | |
240 | /**\r | |
241 | * This method initializes jTextFieldVersion \r | |
242 | * \r | |
243 | * @return javax.swing.JTextField \r | |
244 | */\r | |
245 | private JTextField getJTextFieldVersion() {\r | |
246 | if (jTextFieldVersion == null) {\r | |
247 | jTextFieldVersion = new JTextField();\r | |
92e29378 | 248 | jTextFieldVersion.setBounds(new java.awt.Rectangle(140, 135, 340, 20));\r |
a13899c5 | 249 | }\r |
250 | return jTextFieldVersion;\r | |
251 | }\r | |
252 | \r | |
92e29378 | 253 | /**\r |
254 | * This method initializes jRadioButtonYes \r | |
255 | * \r | |
256 | * @return javax.swing.JRadioButton \r | |
257 | */\r | |
258 | private JRadioButton getJRadioButtonYes() {\r | |
259 | if (jRadioButtonYes == null) {\r | |
260 | jRadioButtonYes = new JRadioButton();\r | |
f9d0ab92 | 261 | jRadioButtonYes.setBounds(new java.awt.Rectangle(140, 35, 100, 20));\r |
262 | jRadioButtonYes.setSelected(false);\r | |
92e29378 | 263 | jRadioButtonYes.setText("Yes");\r |
264 | }\r | |
265 | return jRadioButtonYes;\r | |
266 | }\r | |
267 | \r | |
268 | /**\r | |
269 | * This method initializes jRadioButtonNo \r | |
270 | * \r | |
271 | * @return javax.swing.JRadioButton \r | |
272 | */\r | |
273 | private JRadioButton getJRadioButtonNo() {\r | |
274 | if (jRadioButtonNo == null) {\r | |
275 | jRadioButtonNo = new JRadioButton();\r | |
f9d0ab92 | 276 | jRadioButtonNo.setBounds(new java.awt.Rectangle(300, 35, 110, 20));\r |
277 | jRadioButtonNo.setSelected(true);\r | |
92e29378 | 278 | jRadioButtonNo.setText("No");\r |
279 | }\r | |
280 | return jRadioButtonNo;\r | |
281 | }\r | |
282 | \r | |
a13899c5 | 283 | /**\r |
284 | * @param args\r | |
285 | */\r | |
286 | public static void main(String[] args) {\r | |
287 | SelectModuleBelong smb = new SelectModuleBelong();\r | |
288 | smb.setVisible(true);\r | |
289 | }\r | |
290 | \r | |
291 | /**\r | |
292 | * This is the default constructor\r | |
293 | */\r | |
294 | public SelectModuleBelong() {\r | |
295 | super();\r | |
296 | init();\r | |
297 | }\r | |
298 | \r | |
299 | /**\r | |
300 | * This is the default constructor\r | |
301 | */\r | |
302 | public SelectModuleBelong(IFrame parentFrame, boolean modal, int fileType) {\r | |
303 | super(parentFrame, modal);\r | |
304 | this.mode = fileType;\r | |
305 | init();\r | |
306 | initExistingPackage();\r | |
307 | if (mode != DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r | |
308 | this.jStarLabel1.setVisible(false);\r | |
309 | this.jLabelPackage.setVisible(false);\r | |
310 | this.jComboBoxExistingPackage.setVisible(false);\r | |
92e29378 | 311 | this.jLabelIsLibrary.setVisible(false);\r |
312 | this.jRadioButtonYes.setVisible(false);\r | |
313 | this.jRadioButtonNo.setVisible(false);\r | |
314 | upLocation(this.jStarLabel2, 50);\r | |
315 | upLocation(this.jStarLabel3, 50);\r | |
316 | upLocation(this.jStarLabel4, 50);\r | |
317 | upLocation(this.jStarLabel5, 50);\r | |
318 | upLocation(this.jLabelFilePath, 50);\r | |
319 | upLocation(this.jLabelName, 50);\r | |
320 | upLocation(this.jLabelGuid, 50);\r | |
321 | upLocation(this.jLabelVersion, 50);\r | |
322 | upLocation(this.jTextFieldFilePath, 50);\r | |
323 | upLocation(this.jTextFieldName, 50);\r | |
324 | upLocation(this.jTextFieldGuid, 50);\r | |
325 | upLocation(this.jTextFieldVersion, 50);\r | |
326 | upLocation(this.jButtonBrowse, 50);\r | |
327 | upLocation(this.jButtonGen, 50);\r | |
a13899c5 | 328 | }\r |
329 | }\r | |
330 | \r | |
331 | /**\r | |
332 | * This method initializes this\r | |
333 | * \r | |
334 | * @return void\r | |
335 | */\r | |
336 | private void init() {\r | |
92e29378 | 337 | this.setSize(500, 230);\r |
a13899c5 | 338 | this.setContentPane(getJContentPane());\r |
8f4f211c | 339 | this.setTitle("New");\r |
a13899c5 | 340 | this.centerWindow();\r |
341 | }\r | |
342 | \r | |
343 | /**\r | |
344 | * This method initializes jContentPane\r | |
345 | * \r | |
346 | * @return javax.swing.JPanel\r | |
347 | */\r | |
348 | private JPanel getJContentPane() {\r | |
349 | if (jContentPane == null) {\r | |
92e29378 | 350 | jLabelIsLibrary = new JLabel();\r |
f9d0ab92 | 351 | jLabelIsLibrary.setBounds(new java.awt.Rectangle(15, 35, 120, 20));\r |
ea7f8a93 | 352 | jLabelIsLibrary.setText("Is this a Library");\r |
a13899c5 | 353 | jLabelVersion = new JLabel();\r |
92e29378 | 354 | jLabelVersion.setBounds(new java.awt.Rectangle(15, 135, 120, 20));\r |
a13899c5 | 355 | jLabelVersion.setText("Version");\r |
356 | jLabelGuid = new JLabel();\r | |
92e29378 | 357 | jLabelGuid.setBounds(new java.awt.Rectangle(15, 110, 120, 20));\r |
a13899c5 | 358 | jLabelGuid.setText("Guid");\r |
359 | jLabelName = new JLabel();\r | |
92e29378 | 360 | jLabelName.setBounds(new java.awt.Rectangle(15, 85, 120, 20));\r |
ea7f8a93 | 361 | jLabelName.setText("Module Name");\r |
a13899c5 | 362 | jLabelFilePath = new JLabel();\r |
92e29378 | 363 | jLabelFilePath.setBounds(new java.awt.Rectangle(15, 60, 120, 20));\r |
a13899c5 | 364 | jLabelFilePath.setText("File Path");\r |
365 | jLabelPackage = new JLabel();\r | |
366 | jLabelPackage.setBounds(new java.awt.Rectangle(15, 10, 120, 20));\r | |
ea7f8a93 | 367 | jLabelPackage.setText("Choose a Package");\r |
a13899c5 | 368 | jContentPane = new JPanel();\r |
369 | jContentPane.setLayout(null);\r | |
f9d0ab92 | 370 | jContentPane.setSize(new java.awt.Dimension(490, 198));\r |
a13899c5 | 371 | jContentPane.add(getJComboBoxExistingPackage(), null);\r |
372 | jContentPane.add(getJButtonOk(), null);\r | |
373 | jContentPane.add(getJButtonCancel(), null);\r | |
374 | jContentPane.add(jLabelPackage, null);\r | |
375 | jContentPane.add(jLabelFilePath, null);\r | |
376 | jContentPane.add(getJTextFieldFilePath(), null);\r | |
377 | jContentPane.add(getJButtonBrowse(), null);\r | |
378 | jContentPane.add(jLabelName, null);\r | |
379 | jContentPane.add(getJTextFieldName(), null);\r | |
380 | jContentPane.add(jLabelGuid, null);\r | |
381 | jContentPane.add(getJTextFieldGuid(), null);\r | |
382 | jContentPane.add(getJButtonGen(), null);\r | |
383 | jContentPane.add(jLabelVersion, null);\r | |
384 | jContentPane.add(getJTextFieldVersion(), null);\r | |
385 | \r | |
386 | jStarLabel1 = new StarLabel();\r | |
387 | jStarLabel1.setLocation(new java.awt.Point(0, 10));\r | |
388 | jStarLabel2 = new StarLabel();\r | |
92e29378 | 389 | jStarLabel2.setLocation(new java.awt.Point(0, 60));\r |
a13899c5 | 390 | jStarLabel3 = new StarLabel();\r |
92e29378 | 391 | jStarLabel3.setLocation(new java.awt.Point(0, 85));\r |
a13899c5 | 392 | jStarLabel4 = new StarLabel();\r |
92e29378 | 393 | jStarLabel4.setLocation(new java.awt.Point(0, 110));\r |
a13899c5 | 394 | jStarLabel5 = new StarLabel();\r |
92e29378 | 395 | jStarLabel5.setLocation(new java.awt.Point(0, 135));\r |
a13899c5 | 396 | jContentPane.add(jStarLabel1, null);\r |
397 | jContentPane.add(jStarLabel2, null);\r | |
398 | jContentPane.add(jStarLabel3, null);\r | |
399 | jContentPane.add(jStarLabel4, null);\r | |
400 | jContentPane.add(jStarLabel5, null);\r | |
92e29378 | 401 | jContentPane.add(jLabelIsLibrary, null);\r |
402 | jContentPane.add(getJRadioButtonYes(), null);\r | |
403 | jContentPane.add(getJRadioButtonNo(), null);\r | |
404 | bg.add(getJRadioButtonNo());\r | |
405 | bg.add(getJRadioButtonYes());\r | |
a13899c5 | 406 | }\r |
407 | return jContentPane;\r | |
408 | }\r | |
409 | \r | |
410 | /**\r | |
411 | Query all existing packages and fill them into combox\r | |
412 | \r | |
413 | **/\r | |
414 | private void initExistingPackage() {\r | |
415 | packages = wt.getAllPackages();\r | |
416 | for (int index = 0; index < packages.size(); index++) {\r | |
417 | this.jComboBoxExistingPackage.addItem(packages.elementAt(index).getName());\r | |
418 | }\r | |
419 | }\r | |
420 | \r | |
421 | /* (non-Javadoc)\r | |
422 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r | |
423 | * \r | |
424 | * Override actionPerformed to listen all actions\r | |
425 | */\r | |
426 | public void actionPerformed(ActionEvent arg0) {\r | |
427 | if (arg0.getSource() == jButtonCancel) {\r | |
428 | this.setVisible(false);\r | |
429 | this.returnType = DataType.RETURN_TYPE_CANCEL;\r | |
430 | }\r | |
431 | \r | |
432 | if (arg0.getSource() == jButtonOk) {\r | |
433 | if (this.check()) {\r | |
434 | this.save();\r | |
435 | } else {\r | |
436 | return;\r | |
437 | }\r | |
438 | this.setVisible(false);\r | |
439 | this.returnType = DataType.RETURN_TYPE_OK;\r | |
440 | }\r | |
441 | \r | |
442 | if (arg0.getSource() == this.jButtonGen) {\r | |
443 | this.jTextFieldGuid.setText(Tools.generateUuidString());\r | |
444 | }\r | |
445 | \r | |
446 | if (arg0.getSource() == this.jButtonBrowse) {\r | |
447 | JFileChooser fc = new JFileChooser();\r | |
448 | fc.setAcceptAllFileFilterUsed(false);\r | |
449 | \r | |
450 | if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r | |
451 | fc.setCurrentDirectory(new File(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex())\r | |
452 | .getPath()));\r | |
453 | fc.addChoosableFileFilter(new IFileFilter(DataType.MODULE_SURFACE_AREA_EXT));\r | |
454 | }\r | |
455 | if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r | |
456 | fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));\r | |
457 | fc.addChoosableFileFilter(new IFileFilter(DataType.PACKAGE_SURFACE_AREA_EXT));\r | |
458 | }\r | |
459 | if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r | |
460 | fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));\r | |
461 | fc.addChoosableFileFilter(new IFileFilter(DataType.PLATFORM_SURFACE_AREA_EXT));\r | |
462 | }\r | |
463 | int result = fc.showSaveDialog(new JPanel());\r | |
464 | if (result == JFileChooser.APPROVE_OPTION) {\r | |
465 | this.jTextFieldFilePath.setText(Tools.addPathExt(fc.getSelectedFile().getPath(), mode));\r | |
466 | }\r | |
467 | }\r | |
468 | }\r | |
469 | \r | |
470 | /**\r | |
471 | Data validation for all fields\r | |
472 | \r | |
473 | @retval true - All datas are valid\r | |
474 | @retval false - At least one data is invalid\r | |
475 | \r | |
476 | **/\r | |
477 | public boolean check() {\r | |
478 | //\r | |
479 | // Check if all required fields are not empty\r | |
480 | //\r | |
481 | if (isEmpty(this.jTextFieldFilePath.getText())) {\r | |
ea7f8a93 | 482 | Log.wrn("New File", "A File Path must be entered!");\r |
a13899c5 | 483 | return false;\r |
484 | }\r | |
485 | if (isEmpty(this.jTextFieldName.getText())) {\r | |
ea7f8a93 | 486 | Log.wrn("New File", "A Name must be entered");\r |
a13899c5 | 487 | return false;\r |
488 | }\r | |
489 | if (isEmpty(this.jTextFieldGuid.getText())) {\r | |
ea7f8a93 | 490 | Log.wrn("New File", "The Guid must be entered!");\r |
a13899c5 | 491 | return false;\r |
492 | }\r | |
493 | if (isEmpty(this.jTextFieldVersion.getText())) {\r | |
ea7f8a93 | 494 | Log.wrn("New File", "A Version number must be entered!");\r |
a13899c5 | 495 | return false;\r |
496 | }\r | |
497 | \r | |
498 | //\r | |
499 | // Check if all fields have correct data types \r | |
500 | //\r | |
501 | if (!DataValidation.isBaseName(this.jTextFieldName.getText())) {\r | |
ea7f8a93 | 502 | Log.wrn("New File", "Incorrect data type for the Name!");\r |
a13899c5 | 503 | return false;\r |
504 | }\r | |
505 | if (!DataValidation.isGuid((this.jTextFieldGuid).getText())) {\r | |
ea7f8a93 | 506 | Log.wrn("New File", "Incorrect data type for Guid, which must be in registry format! (8-4-4-4-12)");\r |
a13899c5 | 507 | return false;\r |
508 | }\r | |
509 | \r | |
510 | if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r | |
511 | //\r | |
512 | // Check if the module is already existed in current package\r | |
513 | //\r | |
514 | String packagePath = packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getPath();\r | |
515 | String modulePath = Tools.convertPathToCurrentOsType(this.jTextFieldFilePath.getText());\r | |
516 | Vector<String> msaFile = wt.getAllModulesOfPackage(packagePath);\r | |
a13899c5 | 517 | \r |
518 | for (int index = 0; index < msaFile.size(); index++) {\r | |
79cb6fdb | 519 | if (msaFile.elementAt(index).equals(modulePath)) {\r |
ea7f8a93 | 520 | Log.wrn("New File", "This module is already exists in the selected package!");\r |
a13899c5 | 521 | return false;\r |
522 | }\r | |
523 | }\r | |
524 | }\r | |
525 | \r | |
526 | if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r | |
527 | //\r | |
528 | // Check if the package is already existed in database\r | |
529 | //\r | |
530 | String path = Tools.convertPathToCurrentOsType(this.jTextFieldFilePath.getText());\r | |
531 | Vector<PackageIdentification> vPackageList = wt.getAllPackages();\r | |
532 | if (vPackageList != null && vPackageList.size() > 0) {\r | |
533 | for (int index = 0; index < vPackageList.size(); index++) {\r | |
534 | if (vPackageList.get(index).getPath().equals(path)) {\r | |
ea7f8a93 | 535 | Log.wrn("New File", "This package is already exists in this workspace!");\r |
a13899c5 | 536 | return false;\r |
537 | }\r | |
538 | }\r | |
539 | }\r | |
540 | }\r | |
541 | \r | |
542 | if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r | |
543 | //\r | |
544 | // Check if the platform is already existed in database\r | |
545 | //\r | |
546 | String path = Tools.convertPathToCurrentOsType(this.jTextFieldFilePath.getText());\r | |
547 | Vector<PlatformIdentification> vPlatfromList = wt.getAllPlatforms();\r | |
548 | if (vPlatfromList != null && vPlatfromList.size() > 0) {\r | |
549 | for (int index = 0; index < vPlatfromList.size(); index++) {\r | |
550 | if (vPlatfromList.get(index).getPath().equals(path)) {\r | |
ea7f8a93 | 551 | Log.wrn("New File", "This platform is already exists in this workspace!");\r |
a13899c5 | 552 | return false;\r |
553 | }\r | |
554 | }\r | |
555 | }\r | |
556 | }\r | |
557 | \r | |
558 | return true;\r | |
559 | }\r | |
560 | \r | |
561 | /**\r | |
562 | Save file\r | |
563 | \r | |
564 | **/\r | |
565 | public void save() {\r | |
566 | if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r | |
567 | this.saveModule();\r | |
568 | }\r | |
569 | if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r | |
570 | this.savePackage();\r | |
571 | }\r | |
572 | if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r | |
573 | this.savePlatform();\r | |
574 | }\r | |
575 | }\r | |
576 | \r | |
577 | /**\r | |
578 | Save all components of Msa Header\r | |
579 | \r | |
580 | **/\r | |
581 | private void saveModule() {\r | |
739c6b04 | 582 | msa = null;\r |
a13899c5 | 583 | String path = Tools.convertPathToCurrentOsType(this.jTextFieldFilePath.getText());\r |
584 | \r | |
585 | //\r | |
586 | // Save to memory\r | |
587 | //\r | |
588 | try {\r | |
589 | MsaHeaderDocument.MsaHeader msaHeader = null;\r | |
590 | \r | |
739c6b04 | 591 | msa = ModuleSurfaceArea.Factory.newInstance();\r |
a13899c5 | 592 | msaHeader = MsaHeaderDocument.MsaHeader.Factory.newInstance();\r |
593 | \r | |
594 | msaHeader.setModuleName(this.jTextFieldName.getText());\r | |
595 | msaHeader.setGuidValue(this.jTextFieldGuid.getText());\r | |
596 | msaHeader.setVersion(this.jTextFieldVersion.getText());\r | |
d1760183 | 597 | msaHeader.setModuleType(ModuleTypeDef.BASE);\r |
a13899c5 | 598 | \r |
599 | msa.setMsaHeader(msaHeader);\r | |
600 | } catch (Exception e) {\r | |
601 | Log.err("Save ModuleSurfaceArea Document", e.getMessage());\r | |
602 | return;\r | |
603 | }\r | |
604 | \r | |
605 | //\r | |
606 | // Save to real file\r | |
607 | //\r | |
608 | try {\r | |
609 | SaveFile.saveMsaFile(path, msa);\r | |
a13899c5 | 610 | } catch (Exception e) {\r |
ed1665f2 | 611 | Log.wrn("Save Module to file system", e.getMessage());\r |
a13899c5 | 612 | Log.err("Save Module to file system", e.getMessage());\r |
613 | return;\r | |
614 | }\r | |
615 | \r | |
616 | //\r | |
617 | // Save to identification\r | |
618 | //\r | |
619 | mid = new ModuleIdentification(this.jTextFieldName.getText(), this.jTextFieldGuid.getText(),\r | |
92e29378 | 620 | this.jTextFieldVersion.getText(), path, jRadioButtonYes.isSelected());\r |
a13899c5 | 621 | mid.setPackageId(packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()));\r |
622 | }\r | |
623 | \r | |
624 | /**\r | |
625 | Save all components of Spd Header\r | |
626 | \r | |
627 | **/\r | |
628 | private void savePackage() {\r | |
739c6b04 | 629 | spd = null;\r |
a13899c5 | 630 | String path = Tools.convertPathToCurrentOsType(this.jTextFieldFilePath.getText());\r |
631 | \r | |
632 | //\r | |
633 | // Save to memory\r | |
634 | //\r | |
635 | try {\r | |
636 | SpdHeaderDocument.SpdHeader spdHeader = null;\r | |
637 | \r | |
638 | spd = PackageSurfaceArea.Factory.newInstance();\r | |
639 | spdHeader = SpdHeaderDocument.SpdHeader.Factory.newInstance();\r | |
640 | \r | |
641 | spdHeader.setPackageName(this.jTextFieldName.getText());\r | |
642 | spdHeader.setGuidValue(this.jTextFieldGuid.getText());\r | |
643 | spdHeader.setVersion(this.jTextFieldVersion.getText());\r | |
644 | \r | |
645 | spd.setSpdHeader(spdHeader);\r | |
646 | } catch (Exception e) {\r | |
ea7f8a93 | 647 | Log.wrn("Save Package Surface Area Description Document", e.getMessage());\r |
a13899c5 | 648 | return;\r |
649 | }\r | |
650 | \r | |
651 | //\r | |
652 | // Save to real file\r | |
653 | //\r | |
654 | try {\r | |
655 | SaveFile.saveSpdFile(path, spd);\r | |
656 | \r | |
657 | } catch (Exception e) {\r | |
ed1665f2 | 658 | Log.wrn("Save Package to file system", e.getMessage());\r |
a13899c5 | 659 | Log.err("Save Package to file system", e.getMessage());\r |
660 | return;\r | |
661 | }\r | |
662 | \r | |
663 | //\r | |
664 | // Save to identification\r | |
665 | //\r | |
666 | pid = new PackageIdentification(this.jTextFieldName.getText(), this.jTextFieldGuid.getText(),\r | |
667 | this.jTextFieldVersion.getText(), path);\r | |
668 | }\r | |
669 | \r | |
670 | /**\r | |
671 | Save all components of Fpd Header\r | |
672 | \r | |
673 | **/\r | |
674 | private void savePlatform() {\r | |
739c6b04 | 675 | fpd = null;\r |
a13899c5 | 676 | String path = Tools.convertPathToCurrentOsType(this.jTextFieldFilePath.getText());\r |
677 | \r | |
678 | //\r | |
679 | // Save to memory\r | |
680 | //\r | |
681 | try {\r | |
682 | PlatformHeader fpdHeader = null;\r | |
683 | \r | |
684 | fpd = PlatformSurfaceArea.Factory.newInstance();\r | |
685 | fpdHeader = PlatformHeader.Factory.newInstance();\r | |
686 | \r | |
687 | fpdHeader.setPlatformName(this.jTextFieldName.getText());\r | |
688 | fpdHeader.setGuidValue(this.jTextFieldGuid.getText());\r | |
689 | fpdHeader.setVersion(this.jTextFieldVersion.getText());\r | |
690 | \r | |
691 | fpd.setPlatformHeader(fpdHeader);\r | |
692 | } catch (Exception e) {\r | |
ea7f8a93 | 693 | Log.wrn("Save Framework Platform Description Document", e.getMessage());\r |
a13899c5 | 694 | return;\r |
695 | }\r | |
696 | \r | |
697 | //\r | |
698 | // Save to real file\r | |
699 | //\r | |
700 | try {\r | |
701 | SaveFile.saveFpdFile(path, fpd);\r | |
702 | \r | |
703 | } catch (Exception e) {\r | |
ed1665f2 | 704 | Log.wrn("Save Platform to file system", e.getMessage());\r |
a13899c5 | 705 | Log.err("Save Platform to file system", e.getMessage());\r |
706 | return;\r | |
707 | }\r | |
708 | \r | |
709 | //\r | |
710 | // Save to identification\r | |
711 | //\r | |
712 | fid = new PlatformIdentification(this.jTextFieldName.getText(), this.jTextFieldGuid.getText(),\r | |
713 | this.jTextFieldVersion.getText(), path);\r | |
714 | }\r | |
715 | \r | |
716 | public ModuleIdentification getMid() {\r | |
717 | return mid;\r | |
718 | }\r | |
719 | \r | |
a13899c5 | 720 | public PlatformIdentification getFid() {\r |
721 | return fid;\r | |
722 | }\r | |
723 | \r | |
a13899c5 | 724 | public PackageIdentification getPid() {\r |
725 | return pid;\r | |
726 | }\r | |
727 | \r | |
92e29378 | 728 | private void upLocation(Component c, int size) {\r |
729 | c.setLocation(c.getLocation().x, c.getLocation().y - size);\r | |
730 | }\r | |
739c6b04 | 731 | \r |
732 | public PlatformSurfaceArea getFpd() {\r | |
733 | return fpd;\r | |
734 | }\r | |
735 | \r | |
736 | public ModuleSurfaceArea getMsa() {\r | |
737 | return msa;\r | |
738 | }\r | |
739 | \r | |
740 | public PackageSurfaceArea getSpd() {\r | |
741 | return spd;\r | |
742 | }\r | |
a13899c5 | 743 | }\r |