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