3 The file is used to create, update Guids of MSA/MBD file
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
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.
15 package org
.tianocore
.frameworkwizard
.module
.ui
;
17 import java
.awt
.event
.ActionEvent
;
18 import java
.awt
.event
.ComponentEvent
;
19 import java
.awt
.event
.ItemEvent
;
20 import java
.util
.Vector
;
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
;
30 import org
.tianocore
.GuidUsage
;
31 import org
.tianocore
.GuidsDocument
;
32 import org
.tianocore
.GuidsDocument
.Guids
;
33 import org
.tianocore
.GuidsDocument
.Guids
.GuidCNames
;
34 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
35 import org
.tianocore
.frameworkwizard
.common
.DataType
;
36 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
37 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
38 import org
.tianocore
.frameworkwizard
.common
.Log
;
39 import org
.tianocore
.frameworkwizard
.common
.Tools
;
40 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningModuleType
;
41 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
42 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
43 import org
.tianocore
.frameworkwizard
.common
.ui
.iCheckBoxList
.ICheckBoxList
;
44 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Guids
.GuidsIdentification
;
45 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Guids
.GuidsVector
;
46 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
49 The class is used to create, update Guids of MSA/MBD file
50 It extends IInternalFrame
55 public class ModuleGuids
extends IInternalFrame
{
58 /// Define class Serial Version UID
60 private static final long serialVersionUID
= 6710858997766979803L;
63 //Define class members
65 private JPanel jContentPane
= null;
67 private JLabel jLabelC_Name
= null;
69 private JComboBox jComboBoxCName
= null;
71 private JLabel jLabelUsage
= null;
73 private JComboBox jComboBoxUsage
= null;
75 private StarLabel jStarLabel1
= null;
77 private StarLabel jStarLabel2
= null;
79 private JLabel jLabelFeatureFlag
= null;
81 private JTextField jTextFieldFeatureFlag
= null;
83 private JLabel jLabelArch
= null;
85 private JTextArea jTextAreaList
= null;
87 private JComboBox jComboBoxList
= null;
89 private JButton jButtonAdd
= null;
91 private JButton jButtonRemove
= null;
93 private JButton jButtonUpdate
= null;
95 private JScrollPane jScrollPane
= null;
97 private JScrollPane jScrollPaneList
= null;
99 private ICheckBoxList iCheckBoxListArch
= null;
101 private JScrollPane jScrollPaneArch
= null;
103 private JLabel jLabelHelpText
= null;
105 private JTextField jTextFieldHelpText
= null;
110 private int intSelectedItemId
= 0;
112 private OpeningModuleType omt
= null;
114 private ModuleSurfaceArea msa
= null;
116 private GuidsDocument
.Guids guids
= null;
118 private GuidsIdentification id
= null;
120 private GuidsVector vid
= new GuidsVector();
122 private EnumerationData ed
= new EnumerationData();
124 private WorkspaceTools wt
= new WorkspaceTools();
127 This method initializes jTextFieldC_Name
129 @return javax.swing.JTextField jTextFieldC_Name
132 private JComboBox
getJComboBoxCName() {
133 if (jComboBoxCName
== null) {
134 jComboBoxCName
= new JComboBox();
135 jComboBoxCName
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
136 jComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
138 return jComboBoxCName
;
142 This method initializes jComboBoxUsage
144 @return javax.swing.JComboBox jComboBoxUsage
147 private JComboBox
getJComboBoxUsage() {
148 if (jComboBoxUsage
== null) {
149 jComboBoxUsage
= new JComboBox();
150 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
151 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
153 return jComboBoxUsage
;
157 This method initializes jTextFieldFeatureFlag
159 @return javax.swing.JTextField
162 private JTextField
getJTextFieldFeatureFlag() {
163 if (jTextFieldFeatureFlag
== null) {
164 jTextFieldFeatureFlag
= new JTextField();
165 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
166 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
168 return jTextFieldFeatureFlag
;
172 This method initializes jComboBoxFileList
174 @return javax.swing.JComboBox jComboBoxFileList
177 private JComboBox
getJComboBoxList() {
178 if (jComboBoxList
== null) {
179 jComboBoxList
= new JComboBox();
180 jComboBoxList
.setBounds(new java
.awt
.Rectangle(15, 195, 210, 20));
181 jComboBoxList
.addItemListener(this);
182 jComboBoxList
.addActionListener(this);
183 jComboBoxList
.setPreferredSize(new java
.awt
.Dimension(210, 20));
185 return jComboBoxList
;
189 This method initializes jButtonAdd
191 @return javax.swing.JButton jButtonAdd
194 private JButton
getJButtonAdd() {
195 if (jButtonAdd
== null) {
196 jButtonAdd
= new JButton();
197 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 195, 80, 20));
198 jButtonAdd
.setText("Add");
199 jButtonAdd
.addActionListener(this);
200 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(80, 20));
206 This method initializes jButtonRemove
208 @return javax.swing.JButton jButtonRemove
211 private JButton
getJButtonRemove() {
212 if (jButtonRemove
== null) {
213 jButtonRemove
= new JButton();
214 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 195, 80, 20));
215 jButtonRemove
.setText("Remove");
216 jButtonRemove
.addActionListener(this);
217 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(80, 20));
219 return jButtonRemove
;
223 This method initializes jButtonUpdate
225 @return javax.swing.JButton jButtonUpdate
228 private JButton
getJButtonUpdate() {
229 if (jButtonUpdate
== null) {
230 jButtonUpdate
= new JButton();
231 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 195, 80, 20));
232 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(80, 20));
233 jButtonUpdate
.setText("Update");
234 jButtonUpdate
.addActionListener(this);
236 return jButtonUpdate
;
240 * This method initializes jScrollPaneFileList
242 * @return javax.swing.JScrollPane
244 private JScrollPane
getJScrollPaneList() {
245 if (jScrollPaneList
== null) {
246 jScrollPaneList
= new JScrollPane();
247 jScrollPaneList
.setBounds(new java
.awt
.Rectangle(15, 220, 465, 240));
248 jScrollPaneList
.setViewportView(getJTextAreaList());
249 jScrollPaneList
.setPreferredSize(new java
.awt
.Dimension(465, 240));
251 return jScrollPaneList
;
255 This method initializes jScrollPane
257 @return javax.swing.JScrollPane
259 private JScrollPane
getJScrollPane() {
260 if (jScrollPane
== null) {
261 jScrollPane
= new JScrollPane();
262 jScrollPane
.setViewportView(getJContentPane());
268 * This method initializes jTextAreaFileList
270 * @return javax.swing.JTextArea
272 private JTextArea
getJTextAreaList() {
273 if (jTextAreaList
== null) {
274 jTextAreaList
= new JTextArea();
275 jTextAreaList
.setEditable(false);
278 return jTextAreaList
;
282 This method initializes iCheckBoxListArch
284 @return ICheckBoxList
286 private ICheckBoxList
getICheckBoxListSupportedArchitectures() {
287 if (iCheckBoxListArch
== null) {
288 iCheckBoxListArch
= new ICheckBoxList();
289 iCheckBoxListArch
.addFocusListener(this);
290 iCheckBoxListArch
.setToolTipText(DataType
.SUP_ARCH_LIST_HELP_TEXT
);
292 return iCheckBoxListArch
;
296 This method initializes jScrollPaneArch
298 @return javax.swing.JScrollPane
301 private JScrollPane
getJScrollPaneArch() {
302 if (jScrollPaneArch
== null) {
303 jScrollPaneArch
= new JScrollPane();
304 jScrollPaneArch
.setBounds(new java
.awt
.Rectangle(160, 110, 320, 80));
305 jScrollPaneArch
.setPreferredSize(new java
.awt
.Dimension(320, 80));
306 jScrollPaneArch
.setViewportView(getICheckBoxListSupportedArchitectures());
308 return jScrollPaneArch
;
312 This method initializes jTextFieldHelpText
314 @return javax.swing.JTextField
317 private JTextField
getJTextFieldHelpText() {
318 if (jTextFieldHelpText
== null) {
319 jTextFieldHelpText
= new JTextField();
320 jTextFieldHelpText
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
321 jTextFieldHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 20));
323 return jTextFieldHelpText
;
326 public static void main(String
[] args
) {
331 This method initializes this
334 private void init() {
335 this.setSize(500, 515);
336 this.setContentPane(getJScrollPane());
337 this.setTitle("Guids");
339 this.setViewMode(false);
343 This method initializes this
344 Fill values to all fields if these values are not empty
346 @param inPackageDependencies
349 private void init(Guids inGuids
) {
351 this.guids
= inGuids
;
353 if (this.guids
!= null) {
354 if (this.guids
.getGuidCNamesList().size() > 0) {
355 for (int index
= 0; index
< this.guids
.getGuidCNamesList().size(); index
++) {
356 String arg0
= guids
.getGuidCNamesList().get(index
).getGuidCName();
358 if (guids
.getGuidCNamesList().get(index
).getUsage() != null) {
359 arg1
= guids
.getGuidCNamesList().get(index
).getUsage().toString();
362 String arg2
= guids
.getGuidCNamesList().get(index
).getFeatureFlag();
363 Vector
<String
> arg3
= Tools
.convertListToVector(guids
.getGuidCNamesList().get(index
)
365 String arg4
= guids
.getGuidCNamesList().get(index
).getHelpText();
367 id
= new GuidsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
);
375 Tools
.generateComboBoxByVector(jComboBoxList
, vid
.getGuidsName());
380 This is the default constructor
383 public ModuleGuids() {
386 this.setVisible(true);
390 This is the override edit constructor
392 @param inGuids The input data of GuidsDocument.Guids
395 public ModuleGuids(OpeningModuleType inOmt
) {
398 this.msa
= omt
.getXmlMsa();
399 init(msa
.getGuids());
400 this.setVisible(true);
404 Disable all components when the mode is view
406 @param isView true - The view mode; false - The non-view mode
409 public void setViewMode(boolean isView
) {
411 this.jComboBoxUsage
.setEnabled(!isView
);
416 This method initializes jContentPane
418 @return javax.swing.JPanel jContentPane
421 private JPanel
getJContentPane() {
422 if (jContentPane
== null) {
423 jLabelUsage
= new JLabel();
424 jLabelUsage
.setText("Usage");
425 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
426 jLabelC_Name
= new JLabel();
427 jLabelC_Name
.setText("C_Name");
428 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(15, 10, 140, 20));
429 jLabelArch
= new JLabel();
430 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 110, 140, 20));
431 jLabelArch
.setText("Arch");
432 jLabelFeatureFlag
= new JLabel();
433 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 85, 140, 20));
434 jLabelFeatureFlag
.setText("Feature Flag");
435 jLabelHelpText
= new JLabel();
436 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(14, 60, 140, 20));
437 jLabelHelpText
.setText("Help Text");
439 jContentPane
= new JPanel();
440 jContentPane
.setLayout(null);
441 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 475));
443 jContentPane
.add(jLabelC_Name
, null);
444 jContentPane
.add(getJComboBoxCName(), null);
445 jContentPane
.add(jLabelUsage
, null);
446 jContentPane
.add(getJComboBoxUsage(), null);
447 jContentPane
.add(jLabelFeatureFlag
, null);
448 jContentPane
.add(jLabelArch
, null);
449 jContentPane
.add(getJTextFieldFeatureFlag(), null);
451 jStarLabel1
= new StarLabel();
452 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
453 jStarLabel2
= new StarLabel();
454 jStarLabel2
.setLocation(new java
.awt
.Point(0, 35));
456 jContentPane
.add(jStarLabel1
, null);
457 jContentPane
.add(jStarLabel2
, null);
459 jContentPane
.add(getJComboBoxList(), null);
460 jContentPane
.add(getJButtonAdd(), null);
461 jContentPane
.add(getJButtonRemove(), null);
462 jContentPane
.add(getJButtonUpdate(), null);
463 jContentPane
.add(getJScrollPaneList(), null);
464 jContentPane
.add(getJScrollPaneArch(), null);
465 jContentPane
.add(jLabelHelpText
, null);
466 jContentPane
.add(getJTextFieldHelpText(), null);
475 This method initializes Usage type
478 private void initFrame() {
479 Tools
.generateComboBoxByVector(jComboBoxCName
, wt
.getAllGuidDeclarationsFromWorkspace());
480 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVGuidUsage());
481 this.iCheckBoxListArch
.setAllItems(ed
.getVSupportedArchitectures());
485 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
487 * Override actionPerformed to listen all actions
490 public void actionPerformed(ActionEvent arg0
) {
491 if (arg0
.getSource() == jButtonAdd
) {
497 if (arg0
.getSource() == jButtonRemove
) {
500 if (arg0
.getSource() == jButtonUpdate
) {
509 Data validation for all fields
511 @retval true - All datas are valid
512 @retval false - At least one data is invalid
515 public boolean checkAdd() {
517 // Check if all fields have correct data types
523 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
524 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem().toString())) {
525 Log
.err("Incorrect data type for Guid Name");
533 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
534 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
535 Log
.err("Incorrect data type for Feature Flag");
544 Save all components of Guids
545 if exists guids, set the value directly
546 if not exists guids, new an instance first
551 int count
= this.vid
.size();
553 this.guids
= Guids
.Factory
.newInstance();
555 for (int index
= 0; index
< count
; index
++) {
556 GuidCNames p
= GuidCNames
.Factory
.newInstance();
557 if (!isEmpty(vid
.getGuids(index
).getName())) {
558 p
.setGuidCName(vid
.getGuids(index
).getName());
560 if (!isEmpty(vid
.getGuids(index
).getUsage())) {
561 p
.setUsage(GuidUsage
.Enum
.forString(vid
.getGuids(index
).getUsage()));
563 if (!isEmpty(vid
.getGuids(index
).getFeatureFlag())) {
564 p
.setFeatureFlag(vid
.getGuids(index
).getFeatureFlag());
566 if (vid
.getGuids(index
).getSupArchList() != null && vid
.getGuids(index
).getSupArchList().size() > 0) {
567 p
.setSupArchList(vid
.getGuids(index
).getSupArchList());
569 if (!isEmpty(vid
.getGuids(index
).getHelp())) {
570 p
.setHelpText(vid
.getGuids(index
).getHelp());
572 this.guids
.addNewGuidCNames();
573 this.guids
.setGuidCNamesArray(guids
.getGuidCNamesList().size() - 1, p
);
577 this.msa
.setGuids(guids
);
578 this.omt
.setSaved(false);
579 } catch (Exception e
) {
580 Log
.err("Update Guids", e
.getMessage());
585 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
587 * Override componentResized to resize all components when frame's size is changed
589 public void componentResized(ComponentEvent arg0
) {
590 int intCurrentWidth
= this.getJContentPane().getWidth();
591 int intCurrentHeight
= this.getJContentPane().getHeight();
592 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
593 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
595 resizeComponentWidth(jComboBoxCName
, intCurrentWidth
, intPreferredWidth
);
596 resizeComponentWidth(jComboBoxUsage
, intCurrentWidth
, intPreferredWidth
);
597 resizeComponentWidth(jTextFieldHelpText
, intCurrentWidth
, intPreferredWidth
);
598 resizeComponentWidth(jTextFieldFeatureFlag
, intCurrentWidth
, intPreferredWidth
);
599 resizeComponentWidth(jScrollPaneArch
, intCurrentWidth
, intPreferredWidth
);
601 resizeComponentWidth(jComboBoxList
, intCurrentWidth
, intPreferredWidth
);
602 resizeComponent(jScrollPaneList
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
);
604 relocateComponentX(jButtonAdd
, intCurrentWidth
, intPreferredWidth
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
);
605 relocateComponentX(jButtonRemove
, intCurrentWidth
, intPreferredWidth
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
);
606 relocateComponentX(jButtonUpdate
, intCurrentWidth
, intPreferredWidth
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
);
609 private GuidsIdentification
getCurrentGuids() {
610 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
611 String arg1
= this.jComboBoxUsage
.getSelectedItem().toString();
613 String arg2
= this.jTextFieldFeatureFlag
.getText();
614 Vector
<String
> arg3
= this.iCheckBoxListArch
.getAllCheckedItemsString();
615 String arg4
= this.jTextFieldHelpText
.getText();
617 id
= new GuidsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
);
622 Add current item to Vector
625 private void addToList() {
626 intSelectedItemId
= vid
.size();
628 vid
.addGuids(getCurrentGuids());
630 jComboBoxList
.addItem(id
.getName());
631 jComboBoxList
.setSelectedItem(id
.getName());
634 // Reset select item index
636 intSelectedItemId
= vid
.size();
639 // Reload all fields of selected item
650 Remove current item from Vector
653 private void removeFromList() {
655 // Check if exist items
657 if (this.vid
.size() < 1) {
661 int intTempIndex
= intSelectedItemId
;
663 jComboBoxList
.removeItemAt(intSelectedItemId
);
665 vid
.removeGuids(intTempIndex
);
668 // Reload all fields of selected item
679 Update current item of Vector
682 private void updateForList() {
684 // Check if exist items
686 if (this.vid
.size() < 1) {
691 // Backup selected item index
693 int intTempIndex
= intSelectedItemId
;
695 vid
.updateGuids(getCurrentGuids(), intTempIndex
);
697 jComboBoxList
.removeAllItems();
698 for (int index
= 0; index
< vid
.size(); index
++) {
699 jComboBoxList
.addItem(vid
.getGuids(index
).getName());
703 // Restore selected item index
705 intSelectedItemId
= intTempIndex
;
708 // Reset select item index
710 jComboBoxList
.setSelectedIndex(intSelectedItemId
);
713 // Reload all fields of selected item
724 Refresh all fields' values of selected item of Vector
727 private void reloadFromList() {
728 if (vid
.size() > 0) {
730 // Get selected item index
732 intSelectedItemId
= jComboBoxList
.getSelectedIndex();
734 this.jComboBoxCName
.setSelectedItem(vid
.getGuids(intSelectedItemId
).getName());
735 this.jComboBoxUsage
.setSelectedItem(vid
.getGuids(intSelectedItemId
).getUsage());
736 this.jTextFieldHelpText
.setText(vid
.getGuids(intSelectedItemId
).getHelp());
738 jTextFieldFeatureFlag
.setText(vid
.getGuids(intSelectedItemId
).getFeatureFlag());
739 iCheckBoxListArch
.setAllItemsUnchecked();
740 iCheckBoxListArch
.initCheckedItem(true, vid
.getGuids(intSelectedItemId
).getSupArchList());
749 Update list area pane via the elements of Vector
752 private void reloadListArea() {
753 String strListItem
= "";
754 for (int index
= 0; index
< vid
.size(); index
++) {
755 strListItem
= strListItem
+ vid
.getGuids(index
).getName() + DataType
.UNIX_LINE_SEPARATOR
;
757 this.jTextAreaList
.setText(strListItem
);
761 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
763 * Reflesh the frame when selected item changed
766 public void itemStateChanged(ItemEvent arg0
) {
767 if (arg0
.getSource() == this.jComboBoxList
&& arg0
.getStateChange() == ItemEvent
.SELECTED
) {