a13899c5 |
1 | /** @file\r |
2 | \r |
3 | The file is used to create, update Hob of MSA/MBD file\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.module.ui;\r |
16 | \r |
17 | import java.awt.event.ActionEvent;\r |
18 | import java.awt.event.ComponentEvent;\r |
19 | import java.awt.event.ItemEvent;\r |
20 | import java.util.Vector;\r |
21 | \r |
22 | import javax.swing.JButton;\r |
23 | import javax.swing.JComboBox;\r |
24 | import javax.swing.JLabel;\r |
25 | import javax.swing.JPanel;\r |
26 | import javax.swing.JScrollPane;\r |
27 | import javax.swing.JTextArea;\r |
28 | import javax.swing.JTextField;\r |
29 | \r |
30 | import org.tianocore.HobTypes;\r |
31 | import org.tianocore.HobUsage;\r |
32 | import org.tianocore.HobsDocument;\r |
33 | import org.tianocore.HobsDocument.Hobs;\r |
34 | import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r |
35 | import org.tianocore.frameworkwizard.common.DataType;\r |
36 | import org.tianocore.frameworkwizard.common.DataValidation;\r |
37 | import org.tianocore.frameworkwizard.common.EnumerationData;\r |
38 | import org.tianocore.frameworkwizard.common.Log;\r |
a13899c5 |
39 | import org.tianocore.frameworkwizard.common.Tools;\r |
79cb6fdb |
40 | import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleType;\r |
a13899c5 |
41 | import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r |
42 | import org.tianocore.frameworkwizard.common.ui.StarLabel;\r |
43 | import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;\r |
79cb6fdb |
44 | import org.tianocore.frameworkwizard.module.Identifications.Hobs.HobsIdentification;\r |
45 | import org.tianocore.frameworkwizard.module.Identifications.Hobs.HobsVector;\r |
46 | import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r |
a13899c5 |
47 | \r |
48 | /**\r |
49 | The class is used to create, update Hob of MSA/MBD file\r |
50 | It extends IInternalFrame\r |
51 | \r |
52 | \r |
53 | \r |
54 | **/\r |
55 | public class ModuleHobs extends IInternalFrame {\r |
56 | \r |
57 | ///\r |
58 | /// Define class Serial Version UID\r |
59 | ///\r |
60 | private static final long serialVersionUID = -553473437579358325L;\r |
61 | \r |
62 | //\r |
63 | //Define class members\r |
64 | //\r |
65 | private JPanel jContentPane = null;\r |
66 | \r |
67 | private JLabel jLabel = null;\r |
68 | \r |
79cb6fdb |
69 | private JComboBox jComboBoxGuidC_Name = null;\r |
a13899c5 |
70 | \r |
71 | private JLabel jLabelUsage = null;\r |
72 | \r |
73 | private JLabel jLabelHobType = null;\r |
74 | \r |
75 | private JComboBox jComboBoxUsage = null;\r |
76 | \r |
77 | private JComboBox jComboBoxHobType = null;\r |
78 | \r |
79 | private StarLabel jStarLabel1 = null;\r |
80 | \r |
81 | private JLabel jLabelArch = null;\r |
82 | \r |
83 | private JTextArea jTextAreaList = null;\r |
84 | \r |
85 | private JComboBox jComboBoxList = null;\r |
86 | \r |
87 | private JButton jButtonAdd = null;\r |
88 | \r |
89 | private JButton jButtonRemove = null;\r |
90 | \r |
91 | private JButton jButtonUpdate = null;\r |
92 | \r |
93 | private JScrollPane jScrollPane = null;\r |
94 | \r |
95 | private JScrollPane jScrollPaneList = null;\r |
96 | \r |
97 | private JLabel jLabelFeatureFlag = null;\r |
98 | \r |
99 | private JTextField jTextFieldFeatureFlag = null;\r |
100 | \r |
101 | private ICheckBoxList iCheckBoxListArch = null;\r |
102 | \r |
103 | private JScrollPane jScrollPaneArch = null;\r |
104 | \r |
105 | private JLabel jLabelHelpText = null;\r |
106 | \r |
107 | private JTextField jTextFieldHelpText = null;\r |
108 | \r |
109 | //\r |
110 | // Not used by UI\r |
111 | //\r |
112 | private int intSelectedItemId = 0;\r |
113 | \r |
114 | private OpeningModuleType omt = null;\r |
115 | \r |
116 | private ModuleSurfaceArea msa = null;\r |
117 | \r |
118 | private HobsDocument.Hobs hobs = null;\r |
119 | \r |
120 | private HobsIdentification id = null;\r |
121 | \r |
122 | private HobsVector vid = new HobsVector();\r |
123 | \r |
124 | private EnumerationData ed = new EnumerationData();\r |
79cb6fdb |
125 | \r |
126 | private WorkspaceTools wt = new WorkspaceTools();\r |
a13899c5 |
127 | \r |
128 | /**\r |
129 | This method initializes jTextField \r |
130 | \r |
131 | @return javax.swing.JTextField jTextFieldC_Name\r |
132 | \r |
133 | **/\r |
79cb6fdb |
134 | private JComboBox getJComboBoxGuidC_Name() {\r |
135 | if (jComboBoxGuidC_Name == null) {\r |
136 | jComboBoxGuidC_Name = new JComboBox();\r |
137 | jComboBoxGuidC_Name.setBounds(new java.awt.Rectangle(160, 10, 320, 20));\r |
138 | jComboBoxGuidC_Name.setPreferredSize(new java.awt.Dimension(320, 20));\r |
139 | jComboBoxGuidC_Name.setToolTipText("Select the GUID C Name of the Hob");\r |
a13899c5 |
140 | }\r |
79cb6fdb |
141 | return jComboBoxGuidC_Name;\r |
a13899c5 |
142 | }\r |
143 | \r |
144 | /**\r |
145 | This method initializes jComboBoxUsage \r |
146 | \r |
147 | @return javax.swing.JComboBox jComboBoxUsage\r |
148 | \r |
149 | **/\r |
150 | private JComboBox getJComboBoxUsage() {\r |
151 | if (jComboBoxUsage == null) {\r |
152 | jComboBoxUsage = new JComboBox();\r |
153 | jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 60, 320, 20));\r |
154 | jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));\r |
155 | }\r |
156 | return jComboBoxUsage;\r |
157 | }\r |
158 | \r |
159 | /**\r |
160 | This method initializes jComboBoxHobType \r |
161 | \r |
162 | @return javax.swing.JComboBox jComboBoxHobType\r |
163 | \r |
164 | **/\r |
165 | private JComboBox getJComboBoxHobType() {\r |
166 | if (jComboBoxHobType == null) {\r |
167 | jComboBoxHobType = new JComboBox();\r |
168 | jComboBoxHobType.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r |
169 | jComboBoxHobType.setPreferredSize(new java.awt.Dimension(320, 20));\r |
170 | }\r |
171 | return jComboBoxHobType;\r |
172 | }\r |
173 | \r |
174 | /**\r |
175 | This method initializes jComboBoxFileList \r |
176 | \r |
177 | @return javax.swing.JComboBox jComboBoxFileList\r |
178 | \r |
179 | **/\r |
180 | private JComboBox getJComboBoxList() {\r |
181 | if (jComboBoxList == null) {\r |
182 | jComboBoxList = new JComboBox();\r |
183 | jComboBoxList.setBounds(new java.awt.Rectangle(15, 220, 210, 20));\r |
184 | jComboBoxList.addItemListener(this);\r |
185 | jComboBoxList.addActionListener(this);\r |
186 | jComboBoxList.setPreferredSize(new java.awt.Dimension(210, 20));\r |
187 | }\r |
188 | return jComboBoxList;\r |
189 | }\r |
190 | \r |
191 | /**\r |
192 | This method initializes jButtonAdd \r |
193 | \r |
194 | @return javax.swing.JButton jButtonAdd\r |
195 | \r |
196 | **/\r |
197 | private JButton getJButtonAdd() {\r |
198 | if (jButtonAdd == null) {\r |
199 | jButtonAdd = new JButton();\r |
200 | jButtonAdd.setBounds(new java.awt.Rectangle(230, 220, 80, 20));\r |
201 | jButtonAdd.setText("Add");\r |
202 | jButtonAdd.addActionListener(this);\r |
203 | jButtonAdd.setPreferredSize(new java.awt.Dimension(80, 20));\r |
204 | }\r |
205 | return jButtonAdd;\r |
206 | }\r |
207 | \r |
208 | /**\r |
209 | This method initializes jButtonRemove \r |
210 | \r |
211 | @return javax.swing.JButton jButtonRemove\r |
212 | \r |
213 | **/\r |
214 | private JButton getJButtonRemove() {\r |
215 | if (jButtonRemove == null) {\r |
216 | jButtonRemove = new JButton();\r |
217 | jButtonRemove.setBounds(new java.awt.Rectangle(400, 220, 80, 20));\r |
218 | jButtonRemove.setText("Remove");\r |
219 | jButtonRemove.addActionListener(this);\r |
220 | jButtonRemove.setPreferredSize(new java.awt.Dimension(80, 20));\r |
221 | }\r |
222 | return jButtonRemove;\r |
223 | }\r |
224 | \r |
225 | /**\r |
226 | This method initializes jButtonUpdate \r |
227 | \r |
228 | @return javax.swing.JButton jButtonUpdate\r |
229 | \r |
230 | **/\r |
231 | private JButton getJButtonUpdate() {\r |
232 | if (jButtonUpdate == null) {\r |
233 | jButtonUpdate = new JButton();\r |
234 | jButtonUpdate.setBounds(new java.awt.Rectangle(315, 220, 80, 20));\r |
235 | jButtonUpdate.setPreferredSize(new java.awt.Dimension(80, 20));\r |
236 | jButtonUpdate.setText("Update");\r |
237 | jButtonUpdate.addActionListener(this);\r |
238 | }\r |
239 | return jButtonUpdate;\r |
240 | }\r |
241 | \r |
242 | /**\r |
243 | * This method initializes jScrollPaneFileList \r |
244 | * \r |
245 | * @return javax.swing.JScrollPane \r |
246 | */\r |
247 | private JScrollPane getJScrollPaneList() {\r |
248 | if (jScrollPaneList == null) {\r |
249 | jScrollPaneList = new JScrollPane();\r |
250 | jScrollPaneList.setBounds(new java.awt.Rectangle(15, 245, 465, 240));\r |
251 | jScrollPaneList.setViewportView(getJTextAreaList());\r |
252 | jScrollPaneList.setPreferredSize(new java.awt.Dimension(465, 240));\r |
253 | }\r |
254 | return jScrollPaneList;\r |
255 | }\r |
256 | \r |
257 | /**\r |
258 | This method initializes jScrollPane \r |
259 | \r |
260 | @return javax.swing.JScrollPane \r |
261 | */\r |
262 | private JScrollPane getJScrollPane() {\r |
263 | if (jScrollPane == null) {\r |
264 | jScrollPane = new JScrollPane();\r |
265 | jScrollPane.setViewportView(getJContentPane());\r |
266 | }\r |
267 | return jScrollPane;\r |
268 | }\r |
269 | \r |
270 | /**\r |
271 | * This method initializes jTextAreaFileList \r |
272 | * \r |
273 | * @return javax.swing.JTextArea \r |
274 | */\r |
275 | private JTextArea getJTextAreaList() {\r |
276 | if (jTextAreaList == null) {\r |
277 | jTextAreaList = new JTextArea();\r |
278 | jTextAreaList.setEditable(false);\r |
279 | \r |
280 | }\r |
281 | return jTextAreaList;\r |
282 | }\r |
283 | \r |
284 | /**\r |
285 | * This method initializes jTextFieldFeatureFlag \r |
286 | * \r |
287 | * @return javax.swing.JTextField \r |
288 | */\r |
289 | private JTextField getJTextFieldFeatureFlag() {\r |
290 | if (jTextFieldFeatureFlag == null) {\r |
291 | jTextFieldFeatureFlag = new JTextField();\r |
292 | jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 110, 320, 20));\r |
293 | jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));\r |
294 | }\r |
295 | return jTextFieldFeatureFlag;\r |
296 | }\r |
297 | \r |
298 | /**\r |
299 | This method initializes iCheckBoxListArch \r |
300 | \r |
301 | @return ICheckBoxList \r |
302 | **/\r |
303 | private ICheckBoxList getICheckBoxListSupportedArchitectures() {\r |
304 | if (iCheckBoxListArch == null) {\r |
305 | iCheckBoxListArch = new ICheckBoxList();\r |
306 | iCheckBoxListArch.addFocusListener(this);\r |
307 | iCheckBoxListArch.setToolTipText(DataType.SUP_ARCH_LIST_HELP_TEXT);\r |
308 | }\r |
309 | return iCheckBoxListArch;\r |
310 | }\r |
311 | \r |
312 | /**\r |
313 | This method initializes jScrollPaneArch \r |
314 | \r |
315 | @return javax.swing.JScrollPane \r |
316 | \r |
317 | **/\r |
318 | private JScrollPane getJScrollPaneArch() {\r |
319 | if (jScrollPaneArch == null) {\r |
320 | jScrollPaneArch = new JScrollPane();\r |
321 | jScrollPaneArch.setBounds(new java.awt.Rectangle(160, 135, 320, 80));\r |
322 | jScrollPaneArch.setPreferredSize(new java.awt.Dimension(320, 80));\r |
323 | jScrollPaneArch.setViewportView(getICheckBoxListSupportedArchitectures());\r |
324 | }\r |
325 | return jScrollPaneArch;\r |
326 | }\r |
327 | \r |
328 | /**\r |
329 | This method initializes jTextFieldHelpText \r |
330 | \r |
331 | @return javax.swing.JTextField \r |
332 | \r |
333 | **/\r |
334 | private JTextField getJTextFieldHelpText() {\r |
335 | if (jTextFieldHelpText == null) {\r |
336 | jTextFieldHelpText = new JTextField();\r |
337 | jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 85, 320, 20));\r |
338 | jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));\r |
339 | }\r |
340 | return jTextFieldHelpText;\r |
341 | }\r |
342 | \r |
343 | public static void main(String[] args) {\r |
344 | \r |
345 | }\r |
346 | \r |
347 | /**\r |
348 | This method initializes this\r |
349 | \r |
350 | **/\r |
351 | private void init() {\r |
352 | this.setSize(500, 515);\r |
353 | this.setContentPane(getJScrollPane());\r |
354 | this.setTitle("Hobs");\r |
355 | initFrame();\r |
356 | this.setViewMode(false);\r |
357 | }\r |
358 | \r |
359 | /**\r |
360 | This method initializes this\r |
361 | Fill values to all fields if these values are not empty\r |
362 | \r |
363 | @param inPackageDependencies\r |
364 | \r |
365 | **/\r |
366 | private void init(Hobs inHobs) {\r |
367 | init();\r |
368 | this.hobs = inHobs;\r |
369 | \r |
370 | if (this.hobs != null) {\r |
371 | if (this.hobs.getHobTypesList().size() > 0) {\r |
372 | for (int index = 0; index < this.hobs.getHobTypesList().size(); index++) {\r |
373 | String arg0 = hobs.getHobTypesList().get(index).getHobGuidCName();\r |
374 | String arg1 = null;\r |
375 | if (hobs.getHobTypesList().get(index).getHobType() != null) {\r |
376 | arg1 = hobs.getHobTypesList().get(index).getHobType().toString(); \r |
377 | }\r |
378 | String arg2 = null;\r |
379 | if (hobs.getHobTypesList().get(index).getUsage() != null) {\r |
380 | arg2 = hobs.getHobTypesList().get(index).getUsage().toString(); \r |
381 | }\r |
382 | \r |
383 | String arg3 = hobs.getHobTypesList().get(index).getFeatureFlag();\r |
384 | Vector<String> arg4 = Tools.convertListToVector(hobs.getHobTypesList().get(index).getSupArchList());\r |
385 | String arg5 = hobs.getHobTypesList().get(index).getHelpText();\r |
386 | id = new HobsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r |
387 | vid.addHobs(id);\r |
388 | }\r |
389 | }\r |
390 | }\r |
391 | //\r |
392 | // Update the list\r |
393 | //\r |
394 | Tools.generateComboBoxByVector(jComboBoxList, vid.getHobsName());\r |
395 | reloadListArea();\r |
396 | }\r |
397 | \r |
398 | /**\r |
399 | This is the default constructor\r |
400 | \r |
401 | **/\r |
402 | public ModuleHobs() {\r |
403 | super();\r |
404 | init();\r |
405 | this.setVisible(true);\r |
406 | }\r |
407 | \r |
408 | /**\r |
409 | This is the override edit constructor\r |
410 | \r |
411 | @param inHobs The input data of HobsDocument.Hobs\r |
412 | \r |
413 | **/\r |
414 | public ModuleHobs(OpeningModuleType inOmt) {\r |
415 | super();\r |
416 | this.omt = inOmt;\r |
417 | this.msa = omt.getXmlMsa();\r |
418 | init(msa.getHobs());\r |
419 | this.setVisible(true);\r |
420 | }\r |
421 | \r |
422 | /**\r |
423 | Disable all components when the mode is view\r |
424 | \r |
425 | @param isView true - The view mode; false - The non-view mode\r |
426 | \r |
427 | **/\r |
428 | public void setViewMode(boolean isView) {\r |
429 | if (isView) {\r |
79cb6fdb |
430 | this.jComboBoxGuidC_Name.setEnabled(!isView);\r |
a13899c5 |
431 | this.jComboBoxUsage.setEnabled(!isView);\r |
432 | this.jComboBoxHobType.setEnabled(!isView);\r |
433 | }\r |
434 | }\r |
435 | \r |
436 | /**\r |
437 | This method initializes jContentPane\r |
438 | \r |
439 | @return javax.swing.JPanel jContentPane\r |
440 | \r |
441 | **/\r |
442 | public JPanel getJContentPane() {\r |
443 | if (jContentPane == null) {\r |
444 | jLabelFeatureFlag = new JLabel();\r |
445 | jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 110, 140, 20));\r |
446 | jLabelFeatureFlag.setText("Feature Flag");\r |
447 | jLabelArch = new JLabel();\r |
448 | jLabelArch.setBounds(new java.awt.Rectangle(15, 135, 140, 20));\r |
449 | jLabelArch.setText("Arch");\r |
450 | jLabelHobType = new JLabel();\r |
451 | jLabelHobType.setText("Hob Type");\r |
452 | jLabelHobType.setBounds(new java.awt.Rectangle(15, 35, 140, 20));\r |
453 | jLabelUsage = new JLabel();\r |
454 | jLabelUsage.setText("Usage");\r |
455 | jLabelUsage.setBounds(new java.awt.Rectangle(15, 60, 140, 20));\r |
456 | jLabel = new JLabel();\r |
457 | jLabel.setText("C_Name");\r |
458 | jLabel.setBounds(new java.awt.Rectangle(15, 10, 140, 20));\r |
459 | jLabelHelpText = new JLabel();\r |
460 | jLabelHelpText.setBounds(new java.awt.Rectangle(14, 85, 140, 20));\r |
461 | jLabelHelpText.setText("Help Text");\r |
462 | \r |
463 | jContentPane = new JPanel();\r |
464 | jContentPane.setLayout(null);\r |
465 | jContentPane.setPreferredSize(new java.awt.Dimension(490, 495));\r |
466 | \r |
467 | jContentPane.add(jLabel, null);\r |
79cb6fdb |
468 | jContentPane.add(getJComboBoxGuidC_Name(), null);\r |
a13899c5 |
469 | jContentPane.add(jLabelUsage, null);\r |
470 | jContentPane.add(jLabelHobType, null);\r |
471 | jContentPane.add(getJComboBoxUsage(), null);\r |
472 | jContentPane.add(getJComboBoxHobType(), null);\r |
473 | jStarLabel1 = new StarLabel();\r |
474 | jStarLabel1.setLocation(new java.awt.Point(0, 10));\r |
475 | jContentPane.add(jStarLabel1, null);\r |
476 | \r |
477 | jContentPane.add(jLabelArch, null);\r |
478 | \r |
479 | jContentPane.add(getJComboBoxList(), null);\r |
480 | jContentPane.add(getJButtonAdd(), null);\r |
481 | jContentPane.add(getJButtonRemove(), null);\r |
482 | jContentPane.add(getJButtonUpdate(), null);\r |
483 | jContentPane.add(getJScrollPaneList(), null);\r |
484 | jContentPane.add(jLabelFeatureFlag, null);\r |
485 | jContentPane.add(getJTextFieldFeatureFlag(), null);\r |
486 | jContentPane.add(getJScrollPaneArch(), null);\r |
487 | jContentPane.add(jLabelHelpText, null);\r |
488 | jContentPane.add(getJTextFieldHelpText(), null);\r |
489 | }\r |
490 | return jContentPane;\r |
491 | }\r |
492 | \r |
493 | /**\r |
494 | This method initializes Usage type and Hob type\r |
495 | \r |
496 | **/\r |
497 | private void initFrame() {\r |
498 | Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVHobUsage());\r |
499 | Tools.generateComboBoxByVector(jComboBoxHobType, ed.getVHobType());\r |
79cb6fdb |
500 | Tools.generateComboBoxByVector(jComboBoxGuidC_Name, wt.getAllGuidDeclarationsFromWorkspace());\r |
a13899c5 |
501 | \r |
502 | this.iCheckBoxListArch.setAllItems(ed.getVSupportedArchitectures());\r |
503 | }\r |
504 | \r |
505 | /* (non-Javadoc)\r |
506 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r |
507 | *\r |
508 | * Override actionPerformed to listen all actions\r |
509 | * \r |
510 | */\r |
511 | public void actionPerformed(ActionEvent arg0) {\r |
512 | if (arg0.getSource() == jButtonAdd) {\r |
513 | if (!checkAdd()) {\r |
514 | return;\r |
515 | }\r |
516 | addToList();\r |
517 | }\r |
518 | if (arg0.getSource() == jButtonRemove) {\r |
519 | removeFromList();\r |
520 | }\r |
521 | if (arg0.getSource() == jButtonUpdate) {\r |
522 | if (!checkAdd()) {\r |
523 | return;\r |
524 | }\r |
525 | updateForList();\r |
526 | }\r |
527 | }\r |
528 | \r |
529 | /**\r |
530 | Data validation for all fields\r |
531 | \r |
532 | @retval true - All datas are valid\r |
533 | @retval false - At least one data is invalid\r |
534 | \r |
535 | **/\r |
536 | public boolean checkAdd() {\r |
537 | //\r |
538 | // Check if all fields have correct data types \r |
539 | //\r |
540 | \r |
541 | //\r |
542 | // Check Name \r |
543 | //\r |
79cb6fdb |
544 | if (isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {\r |
a13899c5 |
545 | Log.err("Hob Name couldn't be empty");\r |
546 | return false;\r |
547 | }\r |
548 | \r |
79cb6fdb |
549 | if (!isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {\r |
550 | if (!DataValidation.isC_NameType(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {\r |
a13899c5 |
551 | Log.err("Incorrect data type for Hob Name");\r |
552 | return false;\r |
553 | }\r |
554 | }\r |
555 | \r |
556 | //\r |
557 | // Check FeatureFlag\r |
558 | //\r |
559 | if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r |
560 | if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r |
561 | Log.err("Incorrect data type for Feature Flag");\r |
562 | return false;\r |
563 | }\r |
564 | }\r |
565 | \r |
566 | return true;\r |
567 | }\r |
568 | \r |
569 | /**\r |
570 | Save all components of Hobs\r |
571 | if exists hobs, set the value directly\r |
572 | if not exists hobs, new an instance first\r |
573 | \r |
574 | **/\r |
575 | public void save() {\r |
576 | try {\r |
577 | int count = this.vid.size();\r |
578 | \r |
579 | this.hobs = Hobs.Factory.newInstance();\r |
580 | if (count > 0) {\r |
581 | for (int index = 0; index < count; index++) {\r |
582 | HobsDocument.Hobs.HobTypes p = HobsDocument.Hobs.HobTypes.Factory.newInstance();\r |
583 | if (!isEmpty(vid.getHobs(index).getName())) {\r |
584 | p.setHobGuidCName(vid.getHobs(index).getName());\r |
585 | }\r |
586 | if (!isEmpty(vid.getHobs(index).getUsage())) {\r |
587 | p.setUsage(HobUsage.Enum.forString(vid.getHobs(index).getUsage()));\r |
588 | }\r |
589 | if (!isEmpty(vid.getHobs(index).getType())) {\r |
590 | p.setHobType(HobTypes.Enum.forString(vid.getHobs(index).getType()));\r |
591 | }\r |
592 | if (!isEmpty(vid.getHobs(index).getFeatureFlag())) {\r |
593 | p.setFeatureFlag(vid.getHobs(index).getFeatureFlag());\r |
594 | }\r |
595 | if (vid.getHobs(index).getSupArchList() != null && vid.getHobs(index).getSupArchList().size() > 0) {\r |
596 | p.setSupArchList(vid.getHobs(index).getSupArchList());\r |
597 | }\r |
598 | this.hobs.addNewHobTypes();\r |
599 | this.hobs.setHobTypesArray(hobs.getHobTypesList().size() - 1, p);\r |
600 | }\r |
601 | }\r |
602 | \r |
603 | this.msa.setHobs(hobs);\r |
604 | this.omt.setSaved(false);\r |
605 | } catch (Exception e) {\r |
606 | e.printStackTrace();\r |
607 | Log.err("Update Hobs", e.getMessage());\r |
608 | }\r |
609 | }\r |
610 | \r |
611 | /* (non-Javadoc)\r |
612 | * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r |
613 | * \r |
614 | * Override componentResized to resize all components when frame's size is changed\r |
615 | */\r |
616 | public void componentResized(ComponentEvent arg0) {\r |
617 | int intCurrentWidth = this.getJContentPane().getWidth();\r |
618 | int intCurrentHeight = this.getJContentPane().getHeight();\r |
619 | int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r |
620 | int intPreferredHeight = this.getJContentPane().getPreferredSize().height;\r |
621 | \r |
79cb6fdb |
622 | resizeComponentWidth(jComboBoxGuidC_Name, intCurrentWidth, intPreferredWidth);\r |
a13899c5 |
623 | resizeComponentWidth(jComboBoxHobType, intCurrentWidth, intPreferredWidth);\r |
624 | resizeComponentWidth(jComboBoxUsage, intCurrentWidth, intPreferredWidth);\r |
625 | resizeComponentWidth(jTextFieldHelpText, intCurrentWidth, intPreferredWidth);\r |
626 | resizeComponentWidth(jTextFieldFeatureFlag, intCurrentWidth, intPreferredWidth);\r |
627 | resizeComponentWidth(jScrollPaneArch, intCurrentWidth, intPreferredWidth);\r |
628 | \r |
629 | resizeComponentWidth(jComboBoxList, intCurrentWidth, intPreferredWidth);\r |
630 | resizeComponent(jScrollPaneList, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight);\r |
631 | \r |
632 | relocateComponentX(jButtonAdd, intCurrentWidth, intPreferredWidth, DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON);\r |
633 | relocateComponentX(jButtonRemove, intCurrentWidth, intPreferredWidth, DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON);\r |
634 | relocateComponentX(jButtonUpdate, intCurrentWidth, intPreferredWidth, DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON);\r |
635 | }\r |
636 | \r |
637 | private HobsIdentification getCurrentHobs() {\r |
79cb6fdb |
638 | String arg0 = this.jComboBoxGuidC_Name.getSelectedItem().toString();\r |
a13899c5 |
639 | String arg1 = this.jComboBoxHobType.getSelectedItem().toString();\r |
640 | String arg2 = this.jComboBoxUsage.getSelectedItem().toString();\r |
641 | \r |
642 | String arg3 = this.jTextFieldFeatureFlag.getText();\r |
643 | Vector<String> arg4 = this.iCheckBoxListArch.getAllCheckedItemsString();\r |
644 | String arg5 = this.jTextFieldHelpText.getText();\r |
645 | id = new HobsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r |
646 | return id;\r |
647 | }\r |
648 | \r |
649 | /**\r |
650 | Add current item to Vector\r |
651 | \r |
652 | **/\r |
653 | private void addToList() {\r |
654 | intSelectedItemId = vid.size();\r |
655 | \r |
656 | vid.addHobs(getCurrentHobs());\r |
657 | \r |
658 | jComboBoxList.addItem(id.getName());\r |
659 | jComboBoxList.setSelectedItem(id.getName());\r |
660 | \r |
661 | //\r |
662 | // Reset select item index\r |
663 | //\r |
664 | intSelectedItemId = vid.size();\r |
665 | \r |
666 | //\r |
667 | // Reload all fields of selected item\r |
668 | //\r |
669 | reloadFromList();\r |
670 | \r |
671 | // \r |
672 | // Save to memory\r |
673 | //\r |
674 | save();\r |
675 | }\r |
676 | \r |
677 | /**\r |
678 | Remove current item from Vector\r |
679 | \r |
680 | **/\r |
681 | private void removeFromList() {\r |
682 | //\r |
683 | // Check if exist items\r |
684 | //\r |
685 | if (this.vid.size() < 1) {\r |
686 | return;\r |
687 | }\r |
688 | \r |
689 | int intTempIndex = intSelectedItemId;\r |
690 | \r |
691 | jComboBoxList.removeItemAt(intSelectedItemId);\r |
692 | \r |
693 | vid.removeHobs(intTempIndex);\r |
694 | \r |
695 | //\r |
696 | // Reload all fields of selected item\r |
697 | //\r |
698 | reloadFromList();\r |
699 | \r |
700 | // \r |
701 | // Save to memory\r |
702 | //\r |
703 | save();\r |
704 | }\r |
705 | \r |
706 | /**\r |
707 | Update current item of Vector\r |
708 | \r |
709 | **/\r |
710 | private void updateForList() {\r |
711 | //\r |
712 | // Check if exist items\r |
713 | //\r |
714 | if (this.vid.size() < 1) {\r |
715 | return;\r |
716 | }\r |
717 | \r |
718 | //\r |
719 | // Backup selected item index\r |
720 | //\r |
721 | int intTempIndex = intSelectedItemId;\r |
722 | \r |
723 | vid.updateHobs(getCurrentHobs(), intTempIndex);\r |
724 | \r |
725 | jComboBoxList.removeAllItems();\r |
726 | for (int index = 0; index < vid.size(); index++) {\r |
727 | jComboBoxList.addItem(vid.getHobs(index).getName());\r |
728 | }\r |
729 | \r |
730 | //\r |
731 | // Restore selected item index\r |
732 | //\r |
733 | intSelectedItemId = intTempIndex;\r |
734 | \r |
735 | //\r |
736 | // Reset select item index\r |
737 | //\r |
738 | jComboBoxList.setSelectedIndex(intSelectedItemId);\r |
739 | \r |
740 | //\r |
741 | // Reload all fields of selected item\r |
742 | //\r |
743 | reloadFromList();\r |
744 | \r |
745 | // \r |
746 | // Save to memory\r |
747 | //\r |
748 | save();\r |
749 | }\r |
750 | \r |
751 | /**\r |
752 | Refresh all fields' values of selected item of Vector\r |
753 | \r |
754 | **/\r |
755 | private void reloadFromList() {\r |
756 | if (vid.size() > 0) {\r |
757 | //\r |
758 | // Get selected item index\r |
759 | //\r |
760 | intSelectedItemId = jComboBoxList.getSelectedIndex();\r |
761 | \r |
79cb6fdb |
762 | this.jComboBoxGuidC_Name.setSelectedItem(vid.getHobs(intSelectedItemId).getName());\r |
a13899c5 |
763 | this.jComboBoxHobType.setSelectedItem(vid.getHobs(intSelectedItemId).getType());\r |
764 | this.jComboBoxUsage.setSelectedItem(vid.getHobs(intSelectedItemId).getUsage());\r |
765 | this.jTextFieldHelpText.setText(vid.getHobs(intSelectedItemId).getHelp());\r |
766 | \r |
767 | jTextFieldFeatureFlag.setText(vid.getHobs(intSelectedItemId).getFeatureFlag());\r |
768 | iCheckBoxListArch.setAllItemsUnchecked();\r |
769 | iCheckBoxListArch.initCheckedItem(true, vid.getHobs(intSelectedItemId).getSupArchList());\r |
770 | \r |
771 | } else {\r |
772 | }\r |
773 | \r |
774 | reloadListArea();\r |
775 | }\r |
776 | \r |
777 | /**\r |
778 | Update list area pane via the elements of Vector\r |
779 | \r |
780 | **/\r |
781 | private void reloadListArea() {\r |
782 | String strListItem = "";\r |
783 | for (int index = 0; index < vid.size(); index++) {\r |
784 | strListItem = strListItem + vid.getHobs(index).getName() + DataType.UNIX_LINE_SEPARATOR;\r |
785 | }\r |
786 | this.jTextAreaList.setText(strListItem);\r |
787 | }\r |
788 | \r |
789 | /* (non-Javadoc)\r |
790 | * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)\r |
791 | *\r |
792 | * Reflesh the frame when selected item changed\r |
793 | * \r |
794 | */\r |
795 | public void itemStateChanged(ItemEvent arg0) {\r |
796 | if (arg0.getSource() == this.jComboBoxList && arg0.getStateChange() == ItemEvent.SELECTED) {\r |
797 | reloadFromList();\r |
798 | }\r |
799 | }\r |
800 | }\r |