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