]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | \r | |
3 | The file is used to create, update Ppi 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.packaging.module.ui;\r | |
16 | \r | |
17 | import java.awt.event.ActionEvent;\r | |
18 | \r | |
19 | import javax.swing.JButton;\r | |
20 | import javax.swing.JComboBox;\r | |
21 | import javax.swing.JLabel;\r | |
22 | import javax.swing.JPanel;\r | |
23 | import javax.swing.JRadioButton;\r | |
24 | import javax.swing.JTextField;\r | |
25 | \r | |
26 | import org.tianocore.PPIsDocument;\r | |
27 | import org.tianocore.PpiNotifyUsage;\r | |
28 | import org.tianocore.PpiUsage;\r | |
29 | import org.tianocore.common.DataValidation;\r | |
30 | import org.tianocore.common.Log;\r | |
31 | import org.tianocore.common.Tools;\r | |
32 | import org.tianocore.packaging.common.ui.IDefaultMutableTreeNode;\r | |
33 | import org.tianocore.packaging.common.ui.IInternalFrame;\r | |
34 | import org.tianocore.packaging.common.ui.StarLabel;\r | |
35 | \r | |
36 | /**\r | |
37 | The class is used to create, update Ppi of MSA/MBD file\r | |
38 | It extends IInternalFrame\r | |
39 | \r | |
40 | @since ModuleEditor 1.0\r | |
41 | \r | |
42 | **/\r | |
43 | public class ModulePpis extends IInternalFrame {\r | |
44 | \r | |
45 | ///\r | |
46 | /// Define class Serial Version UID\r | |
47 | ///\r | |
48 | private static final long serialVersionUID = -4284901202357037724L;\r | |
49 | \r | |
50 | //\r | |
51 | //Define class members\r | |
52 | //\r | |
53 | private PPIsDocument.PPIs ppis = null;\r | |
54 | \r | |
55 | private int location = -1;\r | |
56 | \r | |
57 | private static int PPI = 1;\r | |
58 | \r | |
59 | private static int PPI_NOTIFY = 2;\r | |
60 | \r | |
61 | private JPanel jContentPane = null;\r | |
62 | \r | |
63 | private JRadioButton jRadioButtonPpi = null;\r | |
64 | \r | |
65 | private JRadioButton jRadioButtonPpiNotify = null;\r | |
66 | \r | |
67 | private JLabel jLabelC_Name = null;\r | |
68 | \r | |
69 | private JTextField jTextFieldC_Name = null;\r | |
70 | \r | |
71 | private JLabel jLabelGuid = null;\r | |
72 | \r | |
73 | private JTextField jTextFieldGuid = null;\r | |
74 | \r | |
75 | private JTextField jTextFieldFeatureFlag = null;\r | |
76 | \r | |
77 | private JLabel jLabelFeatureFlag = null;\r | |
78 | \r | |
79 | private JLabel jLabelUsage = null;\r | |
80 | \r | |
81 | private JComboBox jComboBoxUsage = null;\r | |
82 | \r | |
83 | private JLabel jLabelEnableFeature = null;\r | |
84 | \r | |
85 | private JRadioButton jRadioButtonEnableFeature = null;\r | |
86 | \r | |
87 | private JRadioButton jRadioButtonDisableFeature = null;\r | |
88 | \r | |
89 | private JButton jButtonOk = null;\r | |
90 | \r | |
91 | private JButton jButtonCancel = null;\r | |
92 | \r | |
93 | private JLabel jLabelPpiType = null;\r | |
94 | \r | |
95 | private JButton jButtonGenerateGuid = null;\r | |
96 | \r | |
97 | private StarLabel jStarLabel1 = null;\r | |
98 | \r | |
99 | private StarLabel jStarLabel2 = null;\r | |
100 | \r | |
101 | private JLabel jLabelOverrideID = null;\r | |
102 | \r | |
103 | private JTextField jTextFieldOverrideID = null;\r | |
104 | \r | |
105 | /**\r | |
106 | This method initializes jRadioButtonPpi \r | |
107 | \r | |
108 | @return javax.swing.JRadioButton jRadioButtonPpi\r | |
109 | \r | |
110 | **/\r | |
111 | private JRadioButton getJRadioButtonPpiType() {\r | |
112 | if (jRadioButtonPpi == null) {\r | |
113 | jRadioButtonPpi = new JRadioButton();\r | |
114 | jRadioButtonPpi.setText("Ppi");\r | |
115 | jRadioButtonPpi.setBounds(new java.awt.Rectangle(160, 10, 100, 20));\r | |
116 | jRadioButtonPpi.addActionListener(this);\r | |
117 | jRadioButtonPpi.setSelected(true);\r | |
118 | }\r | |
119 | return jRadioButtonPpi;\r | |
120 | }\r | |
121 | \r | |
122 | /**\r | |
123 | This method initializes jRadioButtonPpiNotify \r | |
124 | \r | |
125 | @return javax.swing.JRadioButton jRadioButtonPpiNotify\r | |
126 | \r | |
127 | **/\r | |
128 | private JRadioButton getJRadioButtonPpiNotify() {\r | |
129 | if (jRadioButtonPpiNotify == null) {\r | |
130 | jRadioButtonPpiNotify = new JRadioButton();\r | |
131 | jRadioButtonPpiNotify.setText("Ppi Notify");\r | |
132 | jRadioButtonPpiNotify.setBounds(new java.awt.Rectangle(320, 10, 100, 20));\r | |
133 | jRadioButtonPpiNotify.addActionListener(this);\r | |
134 | }\r | |
135 | return jRadioButtonPpiNotify;\r | |
136 | }\r | |
137 | \r | |
138 | /**\r | |
139 | This method initializes jTextFieldC_Name \r | |
140 | \r | |
141 | @return javax.swing.JTextField jTextFieldC_Name\r | |
142 | \r | |
143 | **/\r | |
144 | private JTextField getJTextFieldC_Name() {\r | |
145 | if (jTextFieldC_Name == null) {\r | |
146 | jTextFieldC_Name = new JTextField();\r | |
147 | jTextFieldC_Name.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r | |
148 | }\r | |
149 | return jTextFieldC_Name;\r | |
150 | }\r | |
151 | \r | |
152 | /**\r | |
153 | This method initializes jTextFieldGuid \r | |
154 | \r | |
155 | @return javax.swing.JTextField jTextFieldGuid\r | |
156 | \r | |
157 | **/\r | |
158 | private JTextField getJTextFieldGuid() {\r | |
159 | if (jTextFieldGuid == null) {\r | |
160 | jTextFieldGuid = new JTextField();\r | |
2a8b1c0a | 161 | jTextFieldGuid.setBounds(new java.awt.Rectangle(160, 60, 250, 20));\r |
878ddf1f | 162 | }\r |
163 | return jTextFieldGuid;\r | |
164 | }\r | |
165 | \r | |
166 | /**\r | |
167 | This method initializes jTextFieldFeatureFlag \r | |
168 | \r | |
169 | @return javax.swing.JTextField jTextFieldFeatureFlag\r | |
170 | \r | |
171 | **/\r | |
172 | private JTextField getJTextFieldFeatureFlag() {\r | |
173 | if (jTextFieldFeatureFlag == null) {\r | |
174 | jTextFieldFeatureFlag = new JTextField();\r | |
175 | jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 135, 320, 20));\r | |
176 | }\r | |
177 | return jTextFieldFeatureFlag;\r | |
178 | }\r | |
179 | \r | |
180 | /**\r | |
181 | This method initializes jComboBox\r | |
182 | \r | |
183 | @return javax.swing.JComboBox jComboBoxUsage\r | |
184 | \r | |
185 | **/\r | |
186 | private JComboBox getJComboBox() {\r | |
187 | if (jComboBoxUsage == null) {\r | |
188 | jComboBoxUsage = new JComboBox();\r | |
189 | jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 85, 320, 20));\r | |
190 | }\r | |
191 | return jComboBoxUsage;\r | |
192 | }\r | |
193 | \r | |
194 | /**\r | |
195 | This method initializes jRadioButtonEnableFeature \r | |
196 | \r | |
197 | @return javax.swing.JRadioButton jRadioButtonEnableFeature\r | |
198 | \r | |
199 | **/\r | |
200 | private JRadioButton getJRadioButtonEnableFeature() {\r | |
201 | if (jRadioButtonEnableFeature == null) {\r | |
202 | jRadioButtonEnableFeature = new JRadioButton();\r | |
203 | jRadioButtonEnableFeature.setText("Enable");\r | |
204 | jRadioButtonEnableFeature.setBounds(new java.awt.Rectangle(160, 110, 90, 20));\r | |
205 | jRadioButtonEnableFeature.addActionListener(this);\r | |
206 | jRadioButtonEnableFeature.setSelected(true);\r | |
207 | }\r | |
208 | return jRadioButtonEnableFeature;\r | |
209 | }\r | |
210 | \r | |
211 | /**\r | |
212 | This method initializes jRadioButtonDisableFeature \r | |
213 | \r | |
214 | @return javax.swing.JRadioButton jRadioButtonDisableFeature\r | |
215 | \r | |
216 | **/\r | |
217 | private JRadioButton getJRadioButtonDisableFeature() {\r | |
218 | if (jRadioButtonDisableFeature == null) {\r | |
219 | jRadioButtonDisableFeature = new JRadioButton();\r | |
220 | jRadioButtonDisableFeature.setText("Disable");\r | |
221 | jRadioButtonDisableFeature.setBounds(new java.awt.Rectangle(320, 110, 90, 20));\r | |
222 | jRadioButtonDisableFeature.addActionListener(this);\r | |
223 | }\r | |
224 | return jRadioButtonDisableFeature;\r | |
225 | }\r | |
226 | \r | |
227 | /**\r | |
228 | This method initializes jButtonOk \r | |
229 | \r | |
230 | @return javax.swing.JButton jButtonOk\r | |
231 | \r | |
232 | **/\r | |
233 | private JButton getJButtonOk() {\r | |
234 | if (jButtonOk == null) {\r | |
235 | jButtonOk = new JButton();\r | |
236 | jButtonOk.setText("OK");\r | |
237 | jButtonOk.setBounds(new java.awt.Rectangle(290, 190, 90, 20));\r | |
238 | jButtonOk.addActionListener(this);\r | |
239 | }\r | |
240 | return jButtonOk;\r | |
241 | }\r | |
242 | \r | |
243 | /**\r | |
244 | This method initializes jButtonCancel \r | |
245 | \r | |
246 | @return javax.swing.JButton jButtonCancel\r | |
247 | \r | |
248 | **/\r | |
249 | private JButton getJButtonCancel() {\r | |
250 | if (jButtonCancel == null) {\r | |
251 | jButtonCancel = new JButton();\r | |
252 | jButtonCancel.setText("Cancel");\r | |
253 | jButtonCancel.setBounds(new java.awt.Rectangle(390, 190, 90, 20));\r | |
254 | jButtonCancel.addActionListener(this);\r | |
255 | }\r | |
256 | return jButtonCancel;\r | |
257 | }\r | |
258 | \r | |
259 | /**\r | |
260 | This method initializes jButtonGenerateGuid \r | |
261 | \r | |
262 | @return javax.swing.JButton jButtonGenerateGuid\r | |
263 | \r | |
264 | **/\r | |
265 | private JButton getJButtonGenerateGuid() {\r | |
266 | if (jButtonGenerateGuid == null) {\r | |
267 | jButtonGenerateGuid = new JButton();\r | |
2a8b1c0a | 268 | jButtonGenerateGuid.setBounds(new java.awt.Rectangle(415, 60, 65, 20));\r |
878ddf1f | 269 | jButtonGenerateGuid.setText("GEN");\r |
270 | jButtonGenerateGuid.addActionListener(this);\r | |
271 | }\r | |
272 | return jButtonGenerateGuid;\r | |
273 | }\r | |
274 | \r | |
275 | /**\r | |
276 | This method initializes jTextFieldOverrideID \r | |
277 | \r | |
278 | @return javax.swing.JTextField jTextFieldOverrideID\r | |
279 | \r | |
280 | **/\r | |
281 | private JTextField getJTextFieldOverrideID() {\r | |
282 | if (jTextFieldOverrideID == null) {\r | |
283 | jTextFieldOverrideID = new JTextField();\r | |
2a8b1c0a | 284 | jTextFieldOverrideID.setBounds(new java.awt.Rectangle(160, 160, 50, 20));\r |
878ddf1f | 285 | }\r |
286 | return jTextFieldOverrideID;\r | |
287 | }\r | |
288 | \r | |
289 | public static void main(String[] args) {\r | |
290 | \r | |
291 | }\r | |
292 | \r | |
293 | /**\r | |
294 | This is the default constructor\r | |
295 | \r | |
296 | **/\r | |
297 | public ModulePpis() {\r | |
298 | super();\r | |
299 | init();\r | |
300 | this.setVisible(true);\r | |
301 | }\r | |
302 | \r | |
303 | /**\r | |
304 | This is the override edit constructor\r | |
305 | \r | |
306 | @param inPpis The input data of PPIsDocument.PPIs\r | |
307 | \r | |
308 | **/\r | |
309 | public ModulePpis(PPIsDocument.PPIs inPpis) {\r | |
310 | super();\r | |
311 | init(inPpis);\r | |
312 | this.setVisible(true);\r | |
313 | }\r | |
314 | \r | |
315 | /**\r | |
316 | This is the override edit constructor\r | |
317 | \r | |
318 | @param inPpis The input data of PPIsDocument.PPIs\r | |
319 | @param type The input data of node type\r | |
320 | @param index The input data of node index\r | |
321 | \r | |
322 | **/\r | |
323 | public ModulePpis(PPIsDocument.PPIs inPpis, int type, int index) {\r | |
324 | super();\r | |
325 | init(inPpis, type, index);\r | |
326 | this.setVisible(true);\r | |
327 | }\r | |
328 | \r | |
329 | /**\r | |
330 | This method initializes this\r | |
331 | \r | |
332 | @param inPpis The input data of PPIsDocument.PPIs\r | |
333 | \r | |
334 | **/\r | |
335 | private void init(PPIsDocument.PPIs inPpis) {\r | |
336 | init();\r | |
337 | this.setPpis(inPpis);\r | |
338 | }\r | |
339 | \r | |
340 | /**\r | |
341 | This method initializes this\r | |
342 | Fill values to all fields if these values are not empty\r | |
343 | \r | |
344 | @param inPpis The input data of PPIsDocument.PPIs\r | |
345 | @param type The input data of node type\r | |
346 | @param index The input data of node index\r | |
347 | \r | |
348 | **/\r | |
349 | private void init(PPIsDocument.PPIs inPpis, int type, int index) {\r | |
350 | init(inPpis);\r | |
351 | this.location = index;\r | |
352 | if (type == IDefaultMutableTreeNode.PPIS_PPI_ITEM) {\r | |
353 | initUsage(ModulePpis.PPI);\r | |
354 | this.jRadioButtonPpi.setSelected(true);\r | |
355 | this.jRadioButtonPpiNotify.setSelected(false);\r | |
356 | if (this.ppis.getPpiArray(index).getStringValue() != null) {\r | |
357 | this.jTextFieldC_Name.setText(this.ppis.getPpiArray(index).getStringValue());\r | |
358 | }\r | |
359 | if (this.ppis.getPpiArray(index).getGuid() != null) {\r | |
360 | this.jTextFieldGuid.setText(this.ppis.getPpiArray(index).getGuid());\r | |
361 | }\r | |
362 | if (this.ppis.getPpiArray(index).getUsage() != null) {\r | |
363 | this.jComboBoxUsage.setSelectedItem(this.ppis.getPpiArray(index).getUsage().toString());\r | |
364 | }\r | |
365 | this.jRadioButtonEnableFeature.setSelected(this.ppis.getPpiArray(index).getEnableFeature());\r | |
366 | this.jRadioButtonDisableFeature.setSelected(!this.ppis.getPpiArray(index).getEnableFeature());\r | |
367 | if (this.ppis.getPpiArray(index).getFeatureFlag() != null) {\r | |
368 | this.jTextFieldFeatureFlag.setText(this.ppis.getPpiArray(index).getFeatureFlag());\r | |
369 | }\r | |
370 | this.jTextFieldOverrideID.setText(String.valueOf(this.ppis.getPpiArray(index).getOverrideID()));\r | |
371 | } else if (type == IDefaultMutableTreeNode.PPIS_PPINOTIFY_ITEM) {\r | |
372 | initUsage(ModulePpis.PPI_NOTIFY);\r | |
373 | this.jRadioButtonPpi.setSelected(false);\r | |
374 | this.jRadioButtonPpiNotify.setSelected(true);\r | |
375 | if (this.ppis.getPpiNotifyArray(index).getStringValue() != null) {\r | |
376 | this.jTextFieldC_Name.setText(this.ppis.getPpiNotifyArray(index).getStringValue());\r | |
377 | }\r | |
378 | if (this.ppis.getPpiNotifyArray(index).getGuid() != null) {\r | |
379 | this.jTextFieldGuid.setText(this.ppis.getPpiNotifyArray(index).getGuid());\r | |
380 | }\r | |
381 | if (this.ppis.getPpiNotifyArray(index).getUsage() != null) {\r | |
382 | this.jComboBoxUsage.setSelectedItem(this.ppis.getPpiNotifyArray(index).getUsage().toString());\r | |
383 | }\r | |
384 | this.jRadioButtonEnableFeature.setSelected(this.ppis.getPpiNotifyArray(index).getEnableFeature());\r | |
385 | this.jRadioButtonDisableFeature.setSelected(!this.ppis.getPpiNotifyArray(index).getEnableFeature());\r | |
386 | if (this.ppis.getPpiNotifyArray(index).getFeatureFlag() != null) {\r | |
387 | this.jTextFieldFeatureFlag.setText(this.ppis.getPpiNotifyArray(index).getFeatureFlag());\r | |
388 | }\r | |
389 | this.jTextFieldOverrideID.setText(String.valueOf(this.ppis.getPpiNotifyArray(index).getOverrideID()));\r | |
390 | }\r | |
391 | this.jRadioButtonPpi.setEnabled(false);\r | |
392 | this.jRadioButtonPpiNotify.setEnabled(false);\r | |
393 | }\r | |
394 | \r | |
395 | /**\r | |
396 | This method initializes this\r | |
397 | \r | |
398 | **/\r | |
399 | private void init() {\r | |
400 | this.setContentPane(getJContentPane());\r | |
401 | this.setTitle("Ppis");\r | |
402 | this.setBounds(new java.awt.Rectangle(0, 0, 500, 515));\r | |
403 | initFrame();\r | |
404 | this.setViewMode(false);\r | |
405 | }\r | |
406 | \r | |
407 | /**\r | |
408 | Disable all components when the mode is view\r | |
409 | \r | |
410 | @param isView true - The view mode; false - The non-view mode\r | |
411 | \r | |
412 | **/\r | |
413 | public void setViewMode(boolean isView) {\r | |
414 | this.jButtonOk.setVisible(false);\r | |
415 | this.jButtonCancel.setVisible(false);\r | |
416 | if (isView) {\r | |
417 | this.jRadioButtonPpi.setEnabled(!isView);\r | |
418 | this.jRadioButtonPpiNotify.setEnabled(!isView);\r | |
419 | this.jTextFieldC_Name.setEnabled(!isView);\r | |
420 | this.jTextFieldGuid.setEnabled(!isView);\r | |
421 | this.jComboBoxUsage.setEnabled(!isView);\r | |
422 | this.jRadioButtonEnableFeature.setEnabled(!isView);\r | |
423 | this.jRadioButtonDisableFeature.setEnabled(!isView);\r | |
424 | this.jTextFieldFeatureFlag.setEnabled(!isView);\r | |
425 | this.jTextFieldOverrideID.setEnabled(!isView);\r | |
426 | this.jButtonGenerateGuid.setEnabled(!isView);\r | |
427 | }\r | |
428 | }\r | |
429 | \r | |
430 | /**\r | |
431 | This method initializes jContentPane\r | |
432 | \r | |
433 | @return javax.swing.JPanel jContentPane\r | |
434 | \r | |
435 | **/\r | |
436 | private JPanel getJContentPane() {\r | |
437 | if (jContentPane == null) {\r | |
438 | jLabelOverrideID = new JLabel();\r | |
439 | jLabelOverrideID.setBounds(new java.awt.Rectangle(15, 160, 140, 20));\r | |
440 | jLabelOverrideID.setText("Override ID");\r | |
441 | jLabelPpiType = new JLabel();\r | |
442 | jLabelPpiType.setBounds(new java.awt.Rectangle(15, 10, 140, 20));\r | |
443 | jLabelPpiType.setText("Ppi Type");\r | |
444 | jLabelEnableFeature = new JLabel();\r | |
445 | jLabelEnableFeature.setText("Enable Feature");\r | |
446 | jLabelEnableFeature.setBounds(new java.awt.Rectangle(15, 110, 140, 20));\r | |
447 | jLabelUsage = new JLabel();\r | |
448 | jLabelUsage.setText("Usage");\r | |
449 | jLabelUsage.setBounds(new java.awt.Rectangle(15, 85, 140, 20));\r | |
450 | jLabelFeatureFlag = new JLabel();\r | |
451 | jLabelFeatureFlag.setText("Feature Flag");\r | |
452 | jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 135, 140, 20));\r | |
453 | jLabelGuid = new JLabel();\r | |
454 | jLabelGuid.setText("Guid");\r | |
455 | jLabelGuid.setBounds(new java.awt.Rectangle(15, 60, 140, 20));\r | |
456 | jLabelC_Name = new JLabel();\r | |
457 | jLabelC_Name.setText("C_Name");\r | |
458 | jLabelC_Name.setBounds(new java.awt.Rectangle(15, 35, 140, 20));\r | |
459 | jContentPane = new JPanel();\r | |
460 | jContentPane.setLayout(null);\r | |
461 | jContentPane.add(getJRadioButtonPpiType(), null);\r | |
462 | jContentPane.add(jLabelC_Name, null);\r | |
463 | jContentPane.add(getJTextFieldC_Name(), null);\r | |
464 | jContentPane.add(jLabelGuid, null);\r | |
465 | jContentPane.add(getJTextFieldGuid(), null);\r | |
466 | jContentPane.add(getJTextFieldFeatureFlag(), null);\r | |
467 | jContentPane.add(jLabelFeatureFlag, null);\r | |
468 | jContentPane.add(jLabelUsage, null);\r | |
469 | jContentPane.add(getJComboBox(), null);\r | |
470 | jContentPane.add(jLabelEnableFeature, null);\r | |
471 | jContentPane.add(getJRadioButtonEnableFeature(), null);\r | |
472 | jContentPane.add(getJRadioButtonDisableFeature(), null);\r | |
473 | jContentPane.add(getJButtonOk(), null);\r | |
474 | jContentPane.add(getJButtonCancel(), null);\r | |
475 | jContentPane.add(getJRadioButtonPpiNotify(), null);\r | |
476 | jContentPane.add(jLabelPpiType, null);\r | |
477 | jContentPane.add(getJButtonGenerateGuid(), null);\r | |
478 | \r | |
479 | jStarLabel1 = new StarLabel();\r | |
480 | jStarLabel1.setBounds(new java.awt.Rectangle(0, 10, 10, 20));\r | |
481 | jStarLabel2 = new StarLabel();\r | |
482 | jStarLabel2.setBounds(new java.awt.Rectangle(0, 35, 10, 20));\r | |
483 | \r | |
484 | jContentPane.add(jStarLabel1, null);\r | |
485 | jContentPane.add(jStarLabel2, null);\r | |
486 | jContentPane.add(jLabelOverrideID, null);\r | |
487 | jContentPane.add(getJTextFieldOverrideID(), null);\r | |
488 | }\r | |
489 | return jContentPane;\r | |
490 | }\r | |
491 | \r | |
492 | /**\r | |
493 | This method initializes Usage type\r | |
494 | \r | |
495 | **/\r | |
496 | private void initFrame() {\r | |
497 | jComboBoxUsage.addItem("ALWAYS_CONSUMED");\r | |
498 | jComboBoxUsage.addItem("SOMETIMES_CONSUMED");\r | |
499 | jComboBoxUsage.addItem("ALWAYS_PRODUCED");\r | |
500 | jComboBoxUsage.addItem("SOMETIMES_PRODUCED");\r | |
501 | jComboBoxUsage.addItem("PRIVATE");\r | |
502 | }\r | |
503 | \r | |
504 | /* (non-Javadoc)\r | |
505 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r | |
506 | *\r | |
507 | * Override actionPerformed to listen all actions\r | |
508 | * \r | |
509 | */\r | |
510 | public void actionPerformed(ActionEvent arg0) {\r | |
511 | if (arg0.getSource() == jButtonOk) {\r | |
512 | this.setEdited(true);\r | |
513 | this.save();\r | |
514 | this.dispose();\r | |
515 | }\r | |
516 | if (arg0.getSource() == jButtonCancel) {\r | |
517 | this.dispose();\r | |
518 | }\r | |
519 | \r | |
520 | //\r | |
521 | //Contorl the selected status when click RadionButton\r | |
522 | //Do not use Radio Button Group\r | |
523 | //\r | |
524 | if (arg0.getSource() == jRadioButtonPpi) {\r | |
525 | if (jRadioButtonPpi.isSelected()) {\r | |
526 | jRadioButtonPpiNotify.setSelected(false);\r | |
527 | initUsage(ModulePpis.PPI);\r | |
528 | }\r | |
529 | if (!jRadioButtonPpiNotify.isSelected() && !jRadioButtonPpi.isSelected()) {\r | |
530 | jRadioButtonPpi.setSelected(true);\r | |
531 | initUsage(ModulePpis.PPI);\r | |
532 | }\r | |
533 | }\r | |
534 | \r | |
535 | if (arg0.getSource() == jRadioButtonPpiNotify) {\r | |
536 | if (jRadioButtonPpiNotify.isSelected()) {\r | |
537 | jRadioButtonPpi.setSelected(false);\r | |
538 | initUsage(ModulePpis.PPI_NOTIFY);\r | |
539 | }\r | |
540 | if (!jRadioButtonPpiNotify.isSelected() && !jRadioButtonPpi.isSelected()) {\r | |
541 | jRadioButtonPpiNotify.setSelected(true);\r | |
542 | initUsage(ModulePpis.PPI_NOTIFY);\r | |
543 | }\r | |
544 | }\r | |
545 | \r | |
546 | //\r | |
547 | //Contorl the selected status when click RadionButton\r | |
548 | //Do not use Radio Button Group\r | |
549 | //\r | |
550 | if (arg0.getSource() == jRadioButtonEnableFeature) {\r | |
551 | if (jRadioButtonEnableFeature.isSelected()) {\r | |
552 | jRadioButtonDisableFeature.setSelected(false);\r | |
553 | }\r | |
554 | if (!jRadioButtonDisableFeature.isSelected() && !jRadioButtonEnableFeature.isSelected()) {\r | |
555 | jRadioButtonEnableFeature.setSelected(true);\r | |
556 | }\r | |
557 | }\r | |
558 | \r | |
559 | if (arg0.getSource() == jRadioButtonDisableFeature) {\r | |
560 | if (jRadioButtonDisableFeature.isSelected()) {\r | |
561 | jRadioButtonEnableFeature.setSelected(false);\r | |
562 | }\r | |
563 | if (!jRadioButtonDisableFeature.isSelected() && !jRadioButtonEnableFeature.isSelected()) {\r | |
564 | jRadioButtonDisableFeature.setSelected(true);\r | |
565 | }\r | |
566 | }\r | |
567 | \r | |
568 | if (arg0.getSource() == jButtonGenerateGuid) {\r | |
569 | jTextFieldGuid.setText(Tools.generateUuidString());\r | |
570 | }\r | |
571 | }\r | |
572 | \r | |
573 | /**\r | |
574 | Get PPIsDocument.PPIs\r | |
575 | \r | |
576 | @return PPIsDocument.PPIs\r | |
577 | \r | |
578 | **/\r | |
579 | public PPIsDocument.PPIs getPpis() {\r | |
580 | return ppis;\r | |
581 | }\r | |
582 | \r | |
583 | /**\r | |
584 | Set PPIsDocument.PPIs\r | |
585 | \r | |
586 | @param ppis The input data of PPIsDocument.PPIs\r | |
587 | \r | |
588 | **/\r | |
589 | public void setPpis(PPIsDocument.PPIs ppis) {\r | |
590 | this.ppis = ppis;\r | |
591 | }\r | |
592 | \r | |
593 | /**\r | |
594 | Data validation for all fields\r | |
595 | \r | |
596 | @retval true - All datas are valid\r | |
597 | @retval false - At least one data is invalid\r | |
598 | \r | |
599 | **/\r | |
600 | public boolean check() {\r | |
601 | //\r | |
602 | // Check if all required fields are not empty\r | |
603 | //\r | |
604 | if (isEmpty(this.jTextFieldC_Name.getText())) {\r | |
605 | Log.err("C_Name couldn't be empty");\r | |
606 | return false;\r | |
607 | }\r | |
608 | \r | |
609 | //\r | |
610 | // Check if all fields have correct data types \r | |
611 | //\r | |
612 | if (!DataValidation.isCName(this.jTextFieldC_Name.getText())) {\r | |
613 | Log.err("Incorrect data type for C_Name");\r | |
614 | return false;\r | |
615 | }\r | |
616 | if (!isEmpty(this.jTextFieldGuid.getText()) && !DataValidation.isGuid(this.jTextFieldGuid.getText())) {\r | |
617 | Log.err("Incorrect data type for Guid");\r | |
618 | return false;\r | |
619 | }\r | |
620 | if (!isEmpty(this.jTextFieldFeatureFlag.getText())\r | |
621 | && !DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r | |
622 | Log.err("Incorrect data type for Feature Flag");\r | |
623 | return false;\r | |
624 | }\r | |
625 | if (!isEmpty(this.jTextFieldOverrideID.getText())\r | |
626 | && !DataValidation.isOverrideID(this.jTextFieldOverrideID.getText())) {\r | |
627 | Log.err("Incorrect data type for Override ID");\r | |
628 | return false;\r | |
629 | }\r | |
630 | \r | |
631 | return true;\r | |
632 | }\r | |
633 | \r | |
634 | /**\r | |
635 | Save all components of PPIs\r | |
636 | if exists ppis, set the value directly\r | |
637 | if not exists ppis, new an instance first\r | |
638 | \r | |
639 | **/\r | |
640 | public void save() {\r | |
641 | try {\r | |
642 | if (this.ppis == null) {\r | |
643 | ppis = PPIsDocument.PPIs.Factory.newInstance();\r | |
644 | }\r | |
645 | if (this.jRadioButtonPpi.isSelected()) {\r | |
646 | PPIsDocument.PPIs.Ppi ppi = PPIsDocument.PPIs.Ppi.Factory.newInstance();\r | |
647 | ppi.setStringValue(this.jTextFieldC_Name.getText());\r | |
648 | if (!isEmpty(this.jTextFieldGuid.getText())) {\r | |
649 | ppi.setGuid(this.jTextFieldGuid.getText());\r | |
650 | }\r | |
651 | ppi.setUsage(PpiUsage.Enum.forString(jComboBoxUsage.getSelectedItem().toString()));\r | |
652 | ppi.setEnableFeature(this.jRadioButtonEnableFeature.isSelected());\r | |
653 | if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r | |
654 | ppi.setFeatureFlag(this.jTextFieldFeatureFlag.getText());\r | |
655 | }\r | |
656 | if (!isEmpty(this.jTextFieldOverrideID.getText())) {\r | |
657 | ppi.setOverrideID(Integer.parseInt(this.jTextFieldOverrideID.getText()));\r | |
658 | }\r | |
659 | if (location > -1) {\r | |
660 | ppis.setPpiArray(location, ppi);\r | |
661 | } else {\r | |
662 | ppis.addNewPpi();\r | |
663 | ppis.setPpiArray(ppis.getPpiList().size() - 1, ppi);\r | |
664 | }\r | |
665 | }\r | |
666 | if (this.jRadioButtonPpiNotify.isSelected()) {\r | |
667 | PPIsDocument.PPIs.PpiNotify ppiNotify = PPIsDocument.PPIs.PpiNotify.Factory.newInstance();\r | |
668 | ppiNotify.setStringValue(this.jTextFieldC_Name.getText());\r | |
669 | if (!isEmpty(this.jTextFieldGuid.getText())) {\r | |
670 | ppiNotify.setGuid(this.jTextFieldGuid.getText());\r | |
671 | }\r | |
672 | ppiNotify.setUsage(PpiNotifyUsage.Enum.forString(jComboBoxUsage.getSelectedItem().toString()));\r | |
673 | ppiNotify.setEnableFeature(this.jRadioButtonEnableFeature.isSelected());\r | |
674 | if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r | |
675 | ppiNotify.setFeatureFlag(this.jTextFieldFeatureFlag.getText());\r | |
676 | }\r | |
677 | if (!isEmpty(this.jTextFieldOverrideID.getText())) {\r | |
678 | ppiNotify.setOverrideID(Integer.parseInt(this.jTextFieldOverrideID.getText()));\r | |
679 | }\r | |
680 | if (location > -1) {\r | |
681 | ppis.setPpiNotifyArray(location, ppiNotify);\r | |
682 | } else {\r | |
683 | ppis.addNewPpiNotify();\r | |
684 | ppis.setPpiNotifyArray(ppis.getPpiNotifyList().size() - 1, ppiNotify);\r | |
685 | }\r | |
686 | }\r | |
687 | } catch (Exception e) {\r | |
688 | Log.err("Update Protocols", e.getMessage());\r | |
689 | }\r | |
690 | }\r | |
691 | \r | |
692 | /**\r | |
693 | Enable/Disable relevant fields via different PPI types\r | |
694 | \r | |
695 | @param intType The input data of PPI type\r | |
696 | \r | |
697 | **/\r | |
698 | private void initUsage(int intType) {\r | |
699 | jComboBoxUsage.removeAllItems();\r | |
700 | if (intType == ModulePpis.PPI) {\r | |
701 | jComboBoxUsage.addItem("ALWAYS_CONSUMED");\r | |
702 | jComboBoxUsage.addItem("SOMETIMES_CONSUMED");\r | |
703 | jComboBoxUsage.addItem("ALWAYS_PRODUCED");\r | |
704 | jComboBoxUsage.addItem("SOMETIMES_PRODUCED");\r | |
705 | jComboBoxUsage.addItem("PRIVATE");\r | |
706 | }\r | |
707 | if (intType == ModulePpis.PPI_NOTIFY) {\r | |
708 | jComboBoxUsage.addItem("SOMETIMES_CONSUMED");\r | |
709 | }\r | |
710 | }\r | |
711 | }\r |