2 <<The file is used to create, update Guids of the MSA file>>
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 package org
.tianocore
.frameworkwizard
.module
.ui
.dialog
;
16 import java
.awt
.event
.ActionEvent
;
17 import java
.util
.Vector
;
19 import javax
.swing
.JButton
;
20 import javax
.swing
.JComboBox
;
21 import javax
.swing
.JLabel
;
22 import javax
.swing
.JPanel
;
23 import javax
.swing
.JScrollPane
;
24 import javax
.swing
.JTextField
;
25 import javax
.swing
.JTextArea
;
27 import org
.tianocore
.frameworkwizard
.common
.DataType
;
28 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
29 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
30 import org
.tianocore
.frameworkwizard
.common
.Log
;
31 import org
.tianocore
.frameworkwizard
.common
.Tools
;
32 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
33 import org
.tianocore
.frameworkwizard
.common
.ui
.IComboBox
;
34 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
37 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
38 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Guids
.GuidsIdentification
;
39 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
40 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
43 * The class is used to create, update Guids of the MSA file
48 public class GuidsDlg
extends IDialog
{
51 // / Define class Serial Version UID
53 private static final long serialVersionUID
= 6710858997766979803L;
56 // Define class members
58 private JPanel jContentPane
= null;
60 private JLabel jLabelC_Name
= null;
62 private IComboBox iComboBoxCName
= null;
64 private JLabel jLabelUsage
= null;
66 private JComboBox jComboBoxUsage
= null;
68 private StarLabel jStarLabel1
= null;
70 private StarLabel jStarLabel2
= null;
72 private JLabel jLabelFeatureFlag
= null;
74 private JTextField jTextFieldFeatureFlag
= null;
76 private JLabel jLabelArch
= null;
78 private JScrollPane jScrollPane
= null;
80 private JLabel jLabelHelpText
= null;
82 private JTextArea jTextAreaHelpText
= null;
84 private JScrollPane jScrollPaneHelpText
= null;
86 private ArchCheckBox jArchCheckBox
= null;
88 private JButton jButtonOk
= null;
90 private JButton jButtonCancel
= null;
95 private GuidsIdentification id
= null;
97 private EnumerationData ed
= new EnumerationData();
99 private WorkspaceTools wt
= new WorkspaceTools();
102 * This method initializes jTextFieldC_Name
104 * @return javax.swing.JTextField jTextFieldC_Name
107 private IComboBox
getIComboBoxCName() {
108 if (iComboBoxCName
== null) {
109 iComboBoxCName
= new IComboBox();
110 iComboBoxCName
.setBounds(new java
.awt
.Rectangle(168, 12, 320, 20));
111 iComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
112 iComboBoxCName
.setToolTipText("Select the C Name of the GUID");
114 return iComboBoxCName
;
118 * This method initializes jComboBoxUsage
120 * @return javax.swing.JComboBox jComboBoxUsage
123 private JComboBox
getJComboBoxUsage() {
124 if (jComboBoxUsage
== null) {
125 jComboBoxUsage
= new JComboBox();
126 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
127 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
129 .setToolTipText("<html><table>"
130 + "<tr><td>ALWAYS_CONSUMED</td><td>Module always consumes the GUID</td></tr>"
131 + "<tr><td>SOMETIMES_CONSUMED</td><td>Module will use the GUID only if it is present</td></tr>"
132 + "<tr><td>ALWAYS_PRODUCED</td><td>Module always produces the GUID</td></tr>"
133 + "<tr><td>SOMETIMES_PRODUCED</td><td>Module will sometimes produce the GUID</td></tr>"
134 + "<tr><td>DEFAULT</td><td>Default is the the GUID that specified the<br>instance of the package</td></tr>"
135 + "</table></html>");
137 return jComboBoxUsage
;
141 * This method initializes jTextFieldFeatureFlag
143 * @return javax.swing.JTextField
146 private JTextField
getJTextFieldFeatureFlag() {
147 if (jTextFieldFeatureFlag
== null) {
148 jTextFieldFeatureFlag
= new JTextField();
149 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
150 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
151 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
152 jTextFieldFeatureFlag
.setEnabled(false);
154 return jTextFieldFeatureFlag
;
158 * This method initializes jScrollPane
160 * @return javax.swing.JScrollPane
162 private JScrollPane
getJScrollPane() {
163 if (jScrollPane
== null) {
164 jScrollPane
= new JScrollPane();
165 jScrollPane
.setViewportView(getJContentPane());
171 * This method initializes jTextAreaHelpText
173 * @return javax.swing.JTextArea
176 private JTextArea
getJTextAreaHelpText() {
177 if (jTextAreaHelpText
== null) {
178 jTextAreaHelpText
= new JTextArea();
179 jTextAreaHelpText
.setLineWrap(true);
180 jTextAreaHelpText
.setWrapStyleWord(true);
182 return jTextAreaHelpText
;
187 * This method initializes jScrollPaneHelpText
189 * @return javax.swing.JScrollPane jScrollPaneHelpText
192 private JScrollPane
getJScrollPaneHelpText() {
193 if (jScrollPaneHelpText
== null) {
194 jScrollPaneHelpText
= new JScrollPane();
195 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
196 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
197 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 62));
198 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
200 return jScrollPaneHelpText
;
204 * This method initializes jButtonOk
206 * @return javax.swing.JButton
209 private JButton
getJButtonOk() {
210 if (jButtonOk
== null) {
211 jButtonOk
= new JButton();
212 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 162, 90, 20));
213 jButtonOk
.setText("Ok");
214 jButtonOk
.addActionListener(this);
220 * This method initializes jButtonCancel
222 * @return javax.swing.JButton
225 private JButton
getJButtonCancel() {
226 if (jButtonCancel
== null) {
227 jButtonCancel
= new JButton();
228 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 162, 90, 20));
229 jButtonCancel
.setText("Cancel");
230 jButtonCancel
.addActionListener(this);
232 return jButtonCancel
;
235 public static void main(String
[] args
) {
241 * This method initializes this
244 private void init() {
245 this.setSize(505, 235);
246 this.setContentPane(getJScrollPane());
247 this.setTitle("Guids");
249 this.setViewMode(false);
255 * This method initializes this Fill values to all fields if these values are
261 private void init(GuidsIdentification inGuidsId
, ModuleIdentification mid
) {
266 // Init arch with module's arch
268 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
271 // Get defined guids from dependent packages
273 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
274 if (vpid
.size() <= 0) {
275 Log
.wrn("Init Guid", "This module hasn't defined any package dependency, so there is no guid can be added");
278 Tools
.generateComboBoxByVector(this.iComboBoxCName
,
279 wt
.getAllGuidDeclarationsFromPackages(wt
.getPackageDependenciesOfModule(mid
),
280 EnumerationData
.GUID_TYPE_GUID
));
283 if (this.id
!= null) {
284 this.iComboBoxCName
.setSelectedItem(id
.getName());
285 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
286 this.jTextAreaHelpText
.setText(id
.getHelp());
287 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
288 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
293 * This is the override edit constructor
295 * @param inGuidsIdentification
299 public GuidsDlg(GuidsIdentification inGuidsIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
301 init(inGuidsIdentification
, mid
);
305 * Disable all components when the mode is view
308 * true - The view mode; false - The non-view mode
311 public void setViewMode(boolean isView
) {
313 this.jComboBoxUsage
.setEnabled(!isView
);
318 * This method initializes jContentPane
320 * @return javax.swing.JPanel jContentPane
323 private JPanel
getJContentPane() {
324 if (jContentPane
== null) {
325 jStarLabel1
= new StarLabel();
326 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
327 jLabelC_Name
= new JLabel();
328 jLabelC_Name
.setText("Select GUID's C Name");
329 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 12, 155, 20));
331 jStarLabel2
= new StarLabel();
332 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
333 jLabelUsage
= new JLabel();
334 jLabelUsage
.setText("Usage");
335 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 37, 155, 20));
337 jLabelHelpText
= new JLabel();
338 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 62, 155, 20));
339 jLabelHelpText
.setText("Help Text");
341 jLabelFeatureFlag
= new JLabel();
342 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 132, 155, 20));
343 jLabelFeatureFlag
.setText("Feature Flag Expression");
344 jLabelFeatureFlag
.setEnabled(false);
346 jLabelArch
= new JLabel();
347 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 107, 155, 20));
348 jLabelArch
.setText("Supported Architectures");
349 jArchCheckBox
= new ArchCheckBox();
350 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 107, 320, 20));
351 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
353 jContentPane
= new JPanel();
354 jContentPane
.setLayout(null);
355 jContentPane
.setPreferredSize(new java
.awt
.Dimension(480, 180));
357 jContentPane
.add(jStarLabel1
, null);
358 jContentPane
.add(jLabelC_Name
, null);
359 jContentPane
.add(getIComboBoxCName(), null);
360 jContentPane
.add(jStarLabel2
, null);
361 jContentPane
.add(jLabelUsage
, null);
362 jContentPane
.add(getJComboBoxUsage(), null);
363 jContentPane
.add(jLabelHelpText
, null);
364 jContentPane
.add(getJScrollPaneHelpText(), null);
365 jContentPane
.add(jLabelFeatureFlag
, null);
366 jContentPane
.add(getJTextFieldFeatureFlag(), null);
367 jContentPane
.add(jLabelArch
, null);
368 jContentPane
.add(jArchCheckBox
, null);
369 jContentPane
.add(getJButtonOk(), null);
370 jContentPane
.add(getJButtonCancel(), null);
376 * This method initializes Usage type
379 private void initFrame() {
380 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVGuidUsage());
386 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
388 * Override actionPerformed to listen all actions
391 public void actionPerformed(ActionEvent arg0
) {
392 if (arg0
.getSource() == jButtonOk
) {
395 this.returnType
= DataType
.RETURN_TYPE_OK
;
396 this.setVisible(false);
400 if (arg0
.getSource() == jButtonCancel
) {
401 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
402 this.setVisible(false);
407 * Data validation for all fields
409 * @retval true - All datas are valid
410 * @retval false - At least one data is invalid
413 public boolean checkAdd() {
415 // Check if all fields have correct data types
421 if (this.iComboBoxCName
.getSelectedItem() == null) {
422 Log
.wrn("Update Guids", "Please select one Guid Name");
426 if (!isEmpty(this.iComboBoxCName
.getSelectedItem().toString())) {
427 if (!DataValidation
.isC_NameType(this.iComboBoxCName
.getSelectedItem().toString())) {
428 Log
.wrn("Update Guids", "Incorrect data type for Guid Name");
436 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
437 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
438 Log
.wrn("Update Guids", "Incorrect data type for Feature Flag");
446 private GuidsIdentification
getCurrentGuids() {
447 String arg0
= this.iComboBoxCName
.getSelectedItem().toString();
448 String arg1
= this.jComboBoxUsage
.getSelectedItem().toString();
450 String arg2
= this.jTextFieldFeatureFlag
.getText();
451 Vector
<String
> arg3
= this.jArchCheckBox
.getSelectedItemsVector();
452 String arg4
= this.jTextAreaHelpText
.getText();
454 id
= new GuidsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
);
458 public GuidsIdentification
getId() {
462 public void setId(GuidsIdentification id
) {