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
.IDialog
;
34 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
36 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
37 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Guids
.GuidsIdentification
;
38 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
39 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
42 * The class is used to create, update Guids of the MSA file
47 public class GuidsDlg
extends IDialog
{
50 // / Define class Serial Version UID
52 private static final long serialVersionUID
= 6710858997766979803L;
55 // Define class members
57 private JPanel jContentPane
= null;
59 private JLabel jLabelC_Name
= null;
61 private JComboBox jComboBoxCName
= null;
63 private JLabel jLabelUsage
= null;
65 private JComboBox jComboBoxUsage
= null;
67 private StarLabel jStarLabel1
= null;
69 private StarLabel jStarLabel2
= null;
71 private JLabel jLabelFeatureFlag
= null;
73 private JTextField jTextFieldFeatureFlag
= null;
75 private JLabel jLabelArch
= null;
77 private JScrollPane jScrollPane
= null;
79 private JLabel jLabelHelpText
= null;
81 private JTextArea jTextAreaHelpText
= null;
83 private JScrollPane jScrollPaneHelpText
= null;
85 private ArchCheckBox jArchCheckBox
= null;
87 private JButton jButtonOk
= null;
89 private JButton jButtonCancel
= null;
94 private GuidsIdentification id
= null;
96 private EnumerationData ed
= new EnumerationData();
98 private WorkspaceTools wt
= new WorkspaceTools();
101 * This method initializes jTextFieldC_Name
103 * @return javax.swing.JTextField jTextFieldC_Name
106 private JComboBox
getJComboBoxCName() {
107 if (jComboBoxCName
== null) {
108 jComboBoxCName
= new JComboBox();
109 jComboBoxCName
.setBounds(new java
.awt
.Rectangle(168, 12, 320, 20));
110 jComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
111 jComboBoxCName
.setToolTipText("Select the C Name of the GUID");
113 return jComboBoxCName
;
117 * This method initializes jComboBoxUsage
119 * @return javax.swing.JComboBox jComboBoxUsage
122 private JComboBox
getJComboBoxUsage() {
123 if (jComboBoxUsage
== null) {
124 jComboBoxUsage
= new JComboBox();
125 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
126 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
128 .setToolTipText("<html><table>"
129 + "<tr><td>ALWAYS_CONSUMED</td><td>Module always consumes the GUID</td></tr>"
130 + "<tr><td>SOMETIMES_CONSUMED</td><td>Module will use the GUID only if it is present</td></tr>"
131 + "<tr><td>ALWAYS_PRODUCED</td><td>Module always produces the GUID</td></tr>"
132 + "<tr><td>SOMETIMES_PRODUCED</td><td>Module will sometimes produce the GUID</td></tr>"
133 + "<tr><td>DEFAULT</td><td>Default is the the GUID that specified the<br>instance of the package</td></tr>"
134 + "</table></html>");
136 return jComboBoxUsage
;
140 * This method initializes jTextFieldFeatureFlag
142 * @return javax.swing.JTextField
145 private JTextField
getJTextFieldFeatureFlag() {
146 if (jTextFieldFeatureFlag
== null) {
147 jTextFieldFeatureFlag
= new JTextField();
148 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
149 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
150 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
151 jTextFieldFeatureFlag
.setEnabled(false);
153 return jTextFieldFeatureFlag
;
157 * This method initializes jScrollPane
159 * @return javax.swing.JScrollPane
161 private JScrollPane
getJScrollPane() {
162 if (jScrollPane
== null) {
163 jScrollPane
= new JScrollPane();
164 jScrollPane
.setViewportView(getJContentPane());
170 * This method initializes jTextAreaHelpText
172 * @return javax.swing.JTextArea
175 private JTextArea
getJTextAreaHelpText() {
176 if (jTextAreaHelpText
== null) {
177 jTextAreaHelpText
= new JTextArea();
178 jTextAreaHelpText
.setLineWrap(true);
179 jTextAreaHelpText
.setWrapStyleWord(true);
181 return jTextAreaHelpText
;
186 * This method initializes jScrollPaneHelpText
188 * @return javax.swing.JScrollPane jScrollPaneHelpText
191 private JScrollPane
getJScrollPaneHelpText() {
192 if (jScrollPaneHelpText
== null) {
193 jScrollPaneHelpText
= new JScrollPane();
194 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
195 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
196 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 62));
197 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
199 return jScrollPaneHelpText
;
203 * This method initializes jButtonOk
205 * @return javax.swing.JButton
208 private JButton
getJButtonOk() {
209 if (jButtonOk
== null) {
210 jButtonOk
= new JButton();
211 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 162, 90, 20));
212 jButtonOk
.setText("Ok");
213 jButtonOk
.addActionListener(this);
219 * This method initializes jButtonCancel
221 * @return javax.swing.JButton
224 private JButton
getJButtonCancel() {
225 if (jButtonCancel
== null) {
226 jButtonCancel
= new JButton();
227 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 162, 90, 20));
228 jButtonCancel
.setText("Cancel");
229 jButtonCancel
.addActionListener(this);
231 return jButtonCancel
;
234 public static void main(String
[] args
) {
240 * This method initializes this
243 private void init() {
244 this.setSize(505, 235);
245 this.setContentPane(getJScrollPane());
246 this.setTitle("Guids");
248 this.setViewMode(false);
254 * This method initializes this Fill values to all fields if these values are
260 private void init(GuidsIdentification inGuidsId
, ModuleIdentification mid
) {
264 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
265 if (vpid
.size() <= 0) {
266 Log
.wrn("Init Guid", "This module hasn't defined any package dependency, so there is no guid can be added");
269 Tools
.generateComboBoxByVector(this.jComboBoxCName
,
270 wt
.getAllGuidDeclarationsFromPackages(wt
.getPackageDependenciesOfModule(mid
)));
272 if (this.id
!= null) {
273 this.jComboBoxCName
.setSelectedItem(id
.getName());
274 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
275 this.jTextAreaHelpText
.setText(id
.getHelp());
276 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
277 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
282 * This is the override edit constructor
284 * @param inGuidsIdentification
288 public GuidsDlg(GuidsIdentification inGuidsIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
290 init(inGuidsIdentification
, mid
);
294 * Disable all components when the mode is view
297 * true - The view mode; false - The non-view mode
300 public void setViewMode(boolean isView
) {
302 this.jComboBoxUsage
.setEnabled(!isView
);
307 * This method initializes jContentPane
309 * @return javax.swing.JPanel jContentPane
312 private JPanel
getJContentPane() {
313 if (jContentPane
== null) {
314 jStarLabel1
= new StarLabel();
315 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
316 jLabelC_Name
= new JLabel();
317 jLabelC_Name
.setText("Select GUID's C Name");
318 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 12, 155, 20));
320 jStarLabel2
= new StarLabel();
321 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
322 jLabelUsage
= new JLabel();
323 jLabelUsage
.setText("Usage");
324 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 37, 155, 20));
326 jLabelHelpText
= new JLabel();
327 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 62, 155, 20));
328 jLabelHelpText
.setText("Help Text");
330 jLabelFeatureFlag
= new JLabel();
331 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 132, 155, 20));
332 jLabelFeatureFlag
.setText("Feature Flag Expression");
333 jLabelFeatureFlag
.setEnabled(false);
335 jLabelArch
= new JLabel();
336 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 107, 155, 20));
337 jLabelArch
.setText("Supported Architectures");
338 jArchCheckBox
= new ArchCheckBox();
339 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 107, 320, 20));
340 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
342 jContentPane
= new JPanel();
343 jContentPane
.setLayout(null);
344 jContentPane
.setPreferredSize(new java
.awt
.Dimension(480, 180));
346 jContentPane
.add(jStarLabel1
, null);
347 jContentPane
.add(jLabelC_Name
, null);
348 jContentPane
.add(getJComboBoxCName(), null);
349 jContentPane
.add(jStarLabel2
, null);
350 jContentPane
.add(jLabelUsage
, null);
351 jContentPane
.add(getJComboBoxUsage(), null);
352 jContentPane
.add(jLabelHelpText
, null);
353 jContentPane
.add(getJScrollPaneHelpText(), null);
354 jContentPane
.add(jLabelFeatureFlag
, null);
355 jContentPane
.add(getJTextFieldFeatureFlag(), null);
356 jContentPane
.add(jLabelArch
, null);
357 jContentPane
.add(jArchCheckBox
, null);
358 jContentPane
.add(getJButtonOk(), null);
359 jContentPane
.add(getJButtonCancel(), null);
365 * This method initializes Usage type
368 private void initFrame() {
369 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVGuidUsage());
375 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
377 * Override actionPerformed to listen all actions
380 public void actionPerformed(ActionEvent arg0
) {
381 if (arg0
.getSource() == jButtonOk
) {
384 this.returnType
= DataType
.RETURN_TYPE_OK
;
385 this.setVisible(false);
389 if (arg0
.getSource() == jButtonCancel
) {
390 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
391 this.setVisible(false);
396 * Data validation for all fields
398 * @retval true - All datas are valid
399 * @retval false - At least one data is invalid
402 public boolean checkAdd() {
404 // Check if all fields have correct data types
410 if (this.jComboBoxCName
.getSelectedItem() == null) {
411 Log
.wrn("Update Guids", "Please select one Guid Name");
415 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
416 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem().toString())) {
417 Log
.wrn("Update Guids", "Incorrect data type for Guid Name");
425 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
426 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
427 Log
.wrn("Update Guids", "Incorrect data type for Feature Flag");
435 private GuidsIdentification
getCurrentGuids() {
436 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
437 String arg1
= this.jComboBoxUsage
.getSelectedItem().toString();
439 String arg2
= this.jTextFieldFeatureFlag
.getText();
440 Vector
<String
> arg3
= this.jArchCheckBox
.getSelectedItemsVector();
441 String arg4
= this.jTextAreaHelpText
.getText();
443 id
= new GuidsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
);
447 public GuidsIdentification
getId() {
451 public void setId(GuidsIdentification id
) {