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