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