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