]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleProtocols.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / ModuleProtocols.java
CommitLineData
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
16package org.tianocore.frameworkwizard.module.ui;\r
17\r
18import java.awt.event.ActionEvent;\r
19import java.awt.event.ComponentEvent;\r
20import java.awt.event.ItemEvent;\r
21import java.util.Vector;\r
22\r
23import javax.swing.JButton;\r
24import javax.swing.JComboBox;\r
25import javax.swing.JLabel;\r
26import javax.swing.JPanel;\r
27import javax.swing.JScrollPane;\r
28import javax.swing.JTextArea;\r
29import javax.swing.JTextField;\r
30\r
31import org.tianocore.ProtocolNotifyUsage;\r
32import org.tianocore.ProtocolUsage;\r
33import org.tianocore.ProtocolsDocument;\r
34import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
35import org.tianocore.ProtocolsDocument.Protocols;\r
36import org.tianocore.ProtocolsDocument.Protocols.Protocol;\r
37import org.tianocore.ProtocolsDocument.Protocols.ProtocolNotify;\r
38import org.tianocore.frameworkwizard.common.DataType;\r
39import org.tianocore.frameworkwizard.common.DataValidation;\r
40import org.tianocore.frameworkwizard.common.EnumerationData;\r
41import org.tianocore.frameworkwizard.common.Log;\r
42import org.tianocore.frameworkwizard.common.OpeningModuleType;\r
43import org.tianocore.frameworkwizard.common.Tools;\r
44import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r
45import org.tianocore.frameworkwizard.common.ui.StarLabel;\r
46import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;\r
47import org.tianocore.frameworkwizard.module.Identification.Protocols.ProtocolsIdentification;\r
48import org.tianocore.frameworkwizard.module.Identification.Protocols.ProtocolsVector;\r
49import 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
58public 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
284 }\r
285 return jComboBoxProtocolType;\r
286 }\r
287\r
288 /**\r
289 * This method initializes jComboBoxCName \r
290 * \r
291 * @return javax.swing.JComboBox \r
292 */\r
293 private JComboBox getJComboBoxCName() {\r
294 if (jComboBoxCName == null) {\r
295 jComboBoxCName = new JComboBox();\r
296 jComboBoxCName.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r
297 jComboBoxCName.setPreferredSize(new java.awt.Dimension(320, 20));\r
298\r
299 }\r
300 return jComboBoxCName;\r
301 }\r
302\r
303 /**\r
304 This method initializes iCheckBoxListArch \r
305 \r
306 @return ICheckBoxList \r
307 **/\r
308 private ICheckBoxList getICheckBoxListSupportedArchitectures() {\r
309 if (iCheckBoxListArch == null) {\r
310 iCheckBoxListArch = new ICheckBoxList();\r
311 iCheckBoxListArch.addFocusListener(this);\r
312 iCheckBoxListArch.setToolTipText(DataType.SUP_ARCH_LIST_HELP_TEXT);\r
313 }\r
314 return iCheckBoxListArch;\r
315 }\r
316\r
317 /**\r
318 This method initializes jScrollPaneArch \r
319 \r
320 @return javax.swing.JScrollPane \r
321 \r
322 **/\r
323 private JScrollPane getJScrollPaneArch() {\r
324 if (jScrollPaneArch == null) {\r
325 jScrollPaneArch = new JScrollPane();\r
326 jScrollPaneArch.setBounds(new java.awt.Rectangle(160, 135, 320, 80));\r
327 jScrollPaneArch.setPreferredSize(new java.awt.Dimension(320, 80));\r
328 jScrollPaneArch.setViewportView(getICheckBoxListSupportedArchitectures());\r
329 }\r
330 return jScrollPaneArch;\r
331 }\r
332 \r
333 /**\r
334 This method initializes jTextFieldHelpText \r
335 \r
336 @return javax.swing.JTextField \r
337 \r
338 **/\r
339 private JTextField getJTextFieldHelpText() {\r
340 if (jTextFieldHelpText == null) {\r
341 jTextFieldHelpText = new JTextField();\r
342 jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 85, 320, 20));\r
343 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));\r
344 }\r
345 return jTextFieldHelpText;\r
346 }\r
347\r
348 public static void main(String[] args) {\r
349\r
350 }\r
351\r
352 /**\r
353 This method initializes this\r
354 \r
355 **/\r
356 private void init() {\r
357 this.setSize(500, 515);\r
358 this.setContentPane(getJScrollPane());\r
359 this.setTitle("Protocols");\r
360 initFrame();\r
361 this.setViewMode(false);\r
362 }\r
363\r
364 /**\r
365 This method initializes this\r
366 Fill values to all fields if these values are not empty\r
367 \r
368 @param inPackageDependencies\r
369\r
370 **/\r
371 private void init(Protocols inProtocols) {\r
372 init();\r
373 this.protocols = inProtocols;\r
374\r
375 if (this.protocols != null) {\r
376 if (this.protocols.getProtocolList().size() > 0) {\r
377 for (int index = 0; index < this.protocols.getProtocolList().size(); index++) {\r
378 String arg0 = protocols.getProtocolList().get(index).getProtocolCName();\r
379 String arg1 = ed.getVProtocolType().get(0);\r
380 String arg2 = null;\r
381 if (protocols.getProtocolList().get(index).getUsage() != null) {\r
382 arg2 = protocols.getProtocolList().get(index).getUsage().toString(); \r
383 }\r
384 \r
385 String arg3 = protocols.getProtocolList().get(index).getFeatureFlag();\r
386 Vector<String> arg4 = Tools.convertListToVector(protocols.getProtocolList().get(index)\r
387 .getSupArchList());\r
388 String arg5 = protocols.getProtocolList().get(index).getHelpText();\r
389 id = new ProtocolsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r
390 vid.addProtocols(id);\r
391 }\r
392 }\r
393 if (this.protocols.getProtocolNotifyList().size() > 0) {\r
394 for (int index = 0; index < this.protocols.getProtocolNotifyList().size(); index++) {\r
395 String arg0 = protocols.getProtocolNotifyList().get(index).getProtocolNotifyCName();\r
396 String arg1 = ed.getVProtocolType().get(1);\r
397 String arg2 = null;\r
398 if (protocols.getProtocolNotifyList().get(index).getUsage() != null) {\r
399 arg2 = protocols.getProtocolNotifyList().get(index).getUsage().toString(); \r
400 }\r
401 \r
402 String arg3 = protocols.getProtocolNotifyList().get(index).getFeatureFlag();\r
403 Vector<String> arg4 = Tools.convertListToVector(protocols.getProtocolNotifyList().get(index)\r
404 .getSupArchList());\r
405 String arg5 = protocols.getProtocolNotifyList().get(index).getHelpText();\r
406 id = new ProtocolsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r
407 vid.addProtocols(id);\r
408 }\r
409 }\r
410 }\r
411 //\r
412 // Update the list\r
413 //\r
414 Tools.generateComboBoxByVector(jComboBoxList, vid.getProtocolsName());\r
415 reloadListArea();\r
416 }\r
417\r
418 /**\r
419 This is the default constructor\r
420 \r
421 **/\r
422 public ModuleProtocols() {\r
423 super();\r
424 init();\r
425 this.setVisible(true);\r
426 }\r
427\r
428 /**\r
429 This is the override edit constructor\r
430 \r
431 @param inProtocol The input data of ProtocolsDocument.Protocols\r
432 \r
433 **/\r
434 public ModuleProtocols(OpeningModuleType inOmt) {\r
435 super();\r
436 this.omt = inOmt;\r
437 this.msa = omt.getXmlMsa();\r
438 init(msa.getProtocols());\r
439 this.setVisible(true);\r
440 }\r
441\r
442 /**\r
443 Disable all components when the mode is view\r
444 \r
445 @param isView true - The view mode; false - The non-view mode\r
446 \r
447 **/\r
448 public void setViewMode(boolean isView) {\r
449 if (isView) {\r
450 this.jComboBoxUsage.setEnabled(!isView);\r
451 this.jTextFieldFeatureFlag.setEnabled(!isView);\r
452 }\r
453 }\r
454\r
455 /**\r
456 This method initializes jContentPane\r
457 \r
458 @return javax.swing.JPanel jContentPane\r
459 \r
460 **/\r
461 private JPanel getJContentPane() {\r
462 if (jContentPane == null) {\r
463 jLabelHelpText = new JLabel();\r
464 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 85, 140, 20));\r
465 jLabelHelpText.setText("Help Text");\r
466 jLabelArch = new JLabel();\r
467 jLabelArch.setBounds(new java.awt.Rectangle(15, 135, 140, 20));\r
468 jLabelArch.setText("Arch Type");\r
469 jLabelProtocolType = new JLabel();\r
470 jLabelProtocolType.setBounds(new java.awt.Rectangle(15, 10, 140, 20));\r
471 jLabelProtocolType.setText("Protocol Type");\r
472 jLabelUsage = new JLabel();\r
473 jLabelUsage.setText("Usage");\r
474 jLabelUsage.setBounds(new java.awt.Rectangle(15, 60, 140, 20));\r
475 jLabelFeatureFlag = new JLabel();\r
476 jLabelFeatureFlag.setText("Feature Flag");\r
477 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 110, 140, 20));\r
478 jLabelC_Name = new JLabel();\r
479 jLabelC_Name.setText("C_Name Type");\r
480 jLabelC_Name.setBounds(new java.awt.Rectangle(15, 35, 140, 20));\r
481\r
482 jContentPane = new JPanel();\r
483 jContentPane.setLayout(null);\r
484 jContentPane.setPreferredSize(new java.awt.Dimension(490, 495));\r
485\r
486 jContentPane.add(jLabelC_Name, null);\r
487 jContentPane.add(jLabelFeatureFlag, null);\r
488 jContentPane.add(getJTextFieldFeatureFlag(), null);\r
489 jContentPane.add(jLabelUsage, null);\r
490 jContentPane.add(getJComboBoxProtocolUsage(), null);\r
491 jContentPane.add(jLabelProtocolType, null);\r
492\r
493 jStarLabel1 = new StarLabel();\r
494 jStarLabel1.setBounds(new java.awt.Rectangle(0, 10, 10, 20));\r
495 jStarLabel2 = new StarLabel();\r
496 jStarLabel2.setBounds(new java.awt.Rectangle(0, 35, 10, 20));\r
497\r
498 jContentPane.add(jStarLabel1, null);\r
499 jContentPane.add(jStarLabel2, null);\r
500 jContentPane.add(jLabelArch, null);\r
501 jContentPane.add(getJComboBoxList(), null);\r
502 jContentPane.add(getJButtonAdd(), null);\r
503 jContentPane.add(getJButtonRemove(), null);\r
504 jContentPane.add(getJButtonUpdate(), null);\r
505 jContentPane.add(getJScrollPaneList(), null);\r
506\r
507 jContentPane.add(getJComboBoxProtocolType(), null);\r
508 jContentPane.add(getJComboBoxCName(), null);\r
509 jContentPane.add(getJScrollPaneArch(), null);\r
510 jContentPane.add(jLabelHelpText, null);\r
511 jContentPane.add(getJTextFieldHelpText(), null);\r
512 }\r
513 return jContentPane;\r
514 }\r
515\r
516 /**\r
517 This method initializes Usage type\r
518 \r
519 **/\r
520 private void initFrame() {\r
521 Tools.generateComboBoxByVector(jComboBoxProtocolType, ed.getVProtocolType());\r
522 Tools.generateComboBoxByVector(jComboBoxCName, wt.getAllProtocolDeclarationsFromWorkspace());\r
523 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVProtocolUsage());\r
524\r
525 this.iCheckBoxListArch.setAllItems(ed.getVSupportedArchitectures());\r
526 }\r
527\r
528 /* (non-Javadoc)\r
529 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
530 *\r
531 * Override actionPerformed to listen all actions\r
532 * \r
533 */\r
534 public void actionPerformed(ActionEvent arg0) {\r
535 if (arg0.getSource() == jButtonAdd) {\r
536 if (!checkAdd()) {\r
537 return;\r
538 }\r
539 addToList();\r
540 }\r
541 if (arg0.getSource() == jButtonRemove) {\r
542 removeFromList();\r
543 }\r
544 if (arg0.getSource() == jButtonUpdate) {\r
545 if (!checkAdd()) {\r
546 return;\r
547 }\r
548 updateForList();\r
549 }\r
550 }\r
551\r
552 /**\r
553 Data validation for all fields\r
554 \r
555 @retval true - All datas are valid\r
556 @retval false - At least one data is invalid\r
557 \r
558 **/\r
559 public boolean checkAdd() {\r
560 //\r
561 // Check if all fields have correct data types \r
562 //\r
563\r
564 //\r
565 // Check Name \r
566 //\r
567 if (!isEmpty(this.jComboBoxCName.getSelectedItem().toString())) {\r
568 if (!DataValidation.isC_NameType(this.jComboBoxCName.getSelectedItem().toString())) {\r
569 Log.err("Incorrect data type for Protocol/ProtocolNotify Name");\r
570 return false;\r
571 }\r
572 }\r
573 \r
574 //\r
575 // Check FeatureFlag\r
576 //\r
577 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r
578 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r
579 Log.err("Incorrect data type for Feature Flag");\r
580 return false;\r
581 }\r
582 }\r
583\r
584 return true;\r
585 }\r
586\r
587 /**\r
588 Save all components of Protocols\r
589 if exists protocols, set the value directly\r
590 if not exists protocols, new an instance first\r
591 \r
592 **/\r
593 public void save() {\r
594 try {\r
595 int count = this.vid.size();\r
596\r
597 this.protocols = Protocols.Factory.newInstance();\r
598 if (count > 0) {\r
599 for (int index = 0; index < count; index++) {\r
600 if (vid.getProtocols(index).getType().equals(ed.getVProtocolType().get(0))) {\r
601 Protocol p = Protocol.Factory.newInstance();\r
602 if (!isEmpty(vid.getProtocols(index).getName())) {\r
603 p.setProtocolCName(vid.getProtocols(index).getName());\r
604 }\r
605 if (!isEmpty(vid.getProtocols(index).getUsage())) {\r
606 p.setUsage(ProtocolUsage.Enum.forString(vid.getProtocols(index).getUsage()));\r
607 }\r
608 if (!isEmpty(vid.getProtocols(index).getFeatureFlag())) {\r
609 p.setFeatureFlag(vid.getProtocols(index).getFeatureFlag());\r
610 }\r
611 if (vid.getProtocols(index).getSupArchList() != null\r
612 && vid.getProtocols(index).getSupArchList().size() > 0) {\r
613 p.setSupArchList(vid.getProtocols(index).getSupArchList());\r
614 }\r
615 if (!isEmpty(vid.getProtocols(index).getHelp())) {\r
616 p.setHelpText(vid.getProtocols(index).getHelp());\r
617 }\r
618 this.protocols.addNewProtocol();\r
619 this.protocols.setProtocolArray(protocols.getProtocolList().size() - 1, p);\r
620 }\r
621 if (vid.getProtocols(index).getType().equals(ed.getVProtocolType().get(1))) {\r
622 ProtocolNotify p = ProtocolNotify.Factory.newInstance();\r
623 if (!isEmpty(vid.getProtocols(index).getName())) {\r
624 p.setProtocolNotifyCName(vid.getProtocols(index).getName());\r
625 }\r
626 if (!isEmpty(vid.getProtocols(index).getUsage())) {\r
627 p.setUsage(ProtocolNotifyUsage.Enum.forString(vid.getProtocols(index).getUsage()));\r
628 }\r
629 if (!isEmpty(vid.getProtocols(index).getFeatureFlag())) {\r
630 p.setFeatureFlag(vid.getProtocols(index).getFeatureFlag());\r
631 }\r
632 if (vid.getProtocols(index).getSupArchList() != null\r
633 && vid.getProtocols(index).getSupArchList().size() > 0) {\r
634 p.setSupArchList(vid.getProtocols(index).getSupArchList());\r
635 }\r
636 if (!isEmpty(vid.getProtocols(index).getHelp())) {\r
637 p.setHelpText(vid.getProtocols(index).getHelp());\r
638 }\r
639 this.protocols.addNewProtocolNotify();\r
640 this.protocols.setProtocolNotifyArray(protocols.getProtocolNotifyList().size() - 1, p);\r
641 }\r
642 }\r
643 }\r
644\r
645 this.msa.setProtocols(protocols);\r
646 this.omt.setSaved(false);\r
647 } catch (Exception e) {\r
648 e.printStackTrace();\r
649 Log.err("Update Protocols", e.getMessage());\r
650 }\r
651 }\r
652\r
653 /* (non-Javadoc)\r
654 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r
655 * \r
656 * Override componentResized to resize all components when frame's size is changed\r
657 */\r
658 public void componentResized(ComponentEvent arg0) {\r
659 int intCurrentWidth = this.getJContentPane().getWidth();\r
660 int intCurrentHeight = this.getJContentPane().getHeight();\r
661 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r
662 int intPreferredHeight = this.getJContentPane().getPreferredSize().height;\r
663\r
664 resizeComponentWidth(this.jComboBoxProtocolType, intCurrentWidth, intPreferredWidth);\r
665 resizeComponentWidth(this.jComboBoxCName, intCurrentWidth, intPreferredWidth);\r
666 resizeComponentWidth(this.jComboBoxUsage, intCurrentWidth, intPreferredWidth);\r
667 resizeComponentWidth(this.jTextFieldHelpText, intCurrentWidth, intPreferredWidth);\r
668 resizeComponentWidth(this.jTextFieldFeatureFlag, intCurrentWidth, intPreferredWidth);\r
669 resizeComponentWidth(this.jScrollPaneArch, intCurrentWidth, intPreferredWidth);\r
670\r
671 resizeComponentWidth(this.jComboBoxList, intCurrentWidth, intPreferredWidth);\r
672 resizeComponent(this.jScrollPaneList, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight);\r
673\r
674 relocateComponentX(this.jButtonAdd, intCurrentWidth, intPreferredWidth, DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON);\r
675 relocateComponentX(this.jButtonRemove, intCurrentWidth, intPreferredWidth,\r
676 DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON);\r
677 relocateComponentX(this.jButtonUpdate, intCurrentWidth, intPreferredWidth,\r
678 DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON);\r
679 }\r
680\r
681 private ProtocolsIdentification getCurrentProtocols() {\r
682 String arg0 = this.jComboBoxCName.getSelectedItem().toString();\r
683 String arg1 = this.jComboBoxProtocolType.getSelectedItem().toString();\r
684 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();\r
685\r
686 String arg3 = this.jTextFieldFeatureFlag.getText();\r
687 Vector<String> arg4 = this.iCheckBoxListArch.getAllCheckedItemsString();\r
688 String arg5 = this.jTextFieldHelpText.getText();\r
689 id = new ProtocolsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r
690 return id;\r
691 }\r
692\r
693 /**\r
694 Add current item to Vector\r
695 \r
696 **/\r
697 private void addToList() {\r
698 intSelectedItemId = vid.size();\r
699\r
700 vid.addProtocols(getCurrentProtocols());\r
701\r
702 jComboBoxList.addItem(id.getName());\r
703 jComboBoxList.setSelectedItem(id.getName());\r
704\r
705 //\r
706 // Reset select item index\r
707 //\r
708 intSelectedItemId = vid.size();\r
709\r
710 //\r
711 // Reload all fields of selected item\r
712 //\r
713 reloadFromList();\r
714\r
715 // \r
716 // Save to memory\r
717 //\r
718 save();\r
719 }\r
720\r
721 /**\r
722 Remove current item from Vector\r
723 \r
724 **/\r
725 private void removeFromList() {\r
726 //\r
727 // Check if exist items\r
728 //\r
729 if (this.vid.size() < 1) {\r
730 return;\r
731 }\r
732\r
733 int intTempIndex = intSelectedItemId;\r
734\r
735 jComboBoxList.removeItemAt(intSelectedItemId);\r
736\r
737 vid.removeProtocols(intTempIndex);\r
738\r
739 //\r
740 // Reload all fields of selected item\r
741 //\r
742 reloadFromList();\r
743\r
744 // \r
745 // Save to memory\r
746 //\r
747 save();\r
748 }\r
749\r
750 /**\r
751 Update current item of Vector\r
752 \r
753 **/\r
754 private void updateForList() {\r
755 //\r
756 // Check if exist items\r
757 //\r
758 if (this.vid.size() < 1) {\r
759 return;\r
760 }\r
761\r
762 //\r
763 // Backup selected item index\r
764 //\r
765 int intTempIndex = intSelectedItemId;\r
766\r
767 vid.updateProtocols(getCurrentProtocols(), intTempIndex);\r
768\r
769 jComboBoxList.removeAllItems();\r
770 for (int index = 0; index < vid.size(); index++) {\r
771 jComboBoxList.addItem(vid.getProtocols(index).getName());\r
772 }\r
773\r
774 //\r
775 // Restore selected item index\r
776 //\r
777 intSelectedItemId = intTempIndex;\r
778\r
779 //\r
780 // Reset select item index\r
781 //\r
782 jComboBoxList.setSelectedIndex(intSelectedItemId);\r
783\r
784 //\r
785 // Reload all fields of selected item\r
786 //\r
787 reloadFromList();\r
788\r
789 // \r
790 // Save to memory\r
791 //\r
792 save();\r
793 }\r
794\r
795 /**\r
796 Refresh all fields' values of selected item of Vector\r
797 \r
798 **/\r
799 private void reloadFromList() {\r
800 if (vid.size() > 0) {\r
801 //\r
802 // Get selected item index\r
803 //\r
804 intSelectedItemId = jComboBoxList.getSelectedIndex();\r
805\r
806 this.jComboBoxCName.setSelectedItem(vid.getProtocols(intSelectedItemId).getName());\r
807 this.jComboBoxProtocolType.setSelectedItem(vid.getProtocols(intSelectedItemId).getType());\r
808 this.jComboBoxUsage.setSelectedItem(vid.getProtocols(intSelectedItemId).getUsage());\r
809 this.jTextFieldHelpText.setText(vid.getProtocols(intSelectedItemId).getHelp());\r
810 \r
811 jTextFieldFeatureFlag.setText(vid.getProtocols(intSelectedItemId).getFeatureFlag());\r
812 iCheckBoxListArch.setAllItemsUnchecked();\r
813 iCheckBoxListArch.initCheckedItem(true, vid.getProtocols(intSelectedItemId).getSupArchList());\r
814 \r
815\r
816 } else {\r
817 }\r
818\r
819 reloadListArea();\r
820 }\r
821\r
822 /**\r
823 Update list area pane via the elements of Vector\r
824 \r
825 **/\r
826 private void reloadListArea() {\r
827 String strListItem = "";\r
828 for (int index = 0; index < vid.size(); index++) {\r
829 strListItem = strListItem + vid.getProtocols(index).getName() + DataType.UNIX_LINE_SEPARATOR;\r
830 }\r
831 this.jTextAreaList.setText(strListItem);\r
832 }\r
833\r
834 /* (non-Javadoc)\r
835 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)\r
836 *\r
837 * Reflesh the frame when selected item changed\r
838 * \r
839 */\r
840 public void itemStateChanged(ItemEvent arg0) {\r
841 if (arg0.getSource() == this.jComboBoxList && arg0.getStateChange() == ItemEvent.SELECTED) {\r
842 reloadFromList();\r
843 }\r
844 if (arg0.getSource() == this.jComboBoxProtocolType && arg0.getStateChange() == ItemEvent.SELECTED) {\r
845 if (this.jComboBoxProtocolType.getSelectedItem().toString().equals(ed.getVProtocolType().get(0))) {\r
846 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVProtocolUsage());\r
847 } else {\r
848 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVProtocolNotifyUsage());\r
849 }\r
850 }\r
851 }\r
852}\r