3 The file is used to create, update Hii Packages section of the MSA 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
.dialog
;
17 import java
.awt
.event
.ActionEvent
;
18 import java
.util
.Vector
;
20 import javax
.swing
.JButton
;
21 import javax
.swing
.JComboBox
;
22 import javax
.swing
.JLabel
;
23 import javax
.swing
.JPanel
;
24 import javax
.swing
.JScrollPane
;
25 import javax
.swing
.JTextField
;
26 import javax
.swing
.JTextArea
;
28 import org
.tianocore
.frameworkwizard
.common
.DataType
;
29 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
30 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
31 import org
.tianocore
.frameworkwizard
.common
.Log
;
32 import org
.tianocore
.frameworkwizard
.common
.Tools
;
33 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
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
.HiiPackages
.HiiPackagesIdentification
;
39 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
42 * The class is used to create, update Hii Packages of the MSA file
47 public class HiiPackagesDlg
extends IDialog
{
50 // / Define class Serial Version UID
52 private static final long serialVersionUID
= -6851574146786158116L;
55 // Define class members
57 private JPanel jContentPane
= null;
59 private JLabel jLabelName
= null;
61 private JTextField jTextFieldName
= 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 HiiPackagesIdentification id
= null;
96 private EnumerationData ed
= new EnumerationData();
98 private WorkspaceTools wt
= new WorkspaceTools();
102 * This method initializes jTextFieldName
104 * @return javax.swing.JTextField jTextFieldName
107 private JTextField
getJTextFieldName() {
108 if (jTextFieldName
== null) {
109 jTextFieldName
= new JTextField();
110 jTextFieldName
.setBounds(new java
.awt
.Rectangle(168, 12, 320, 20));
111 jTextFieldName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
112 jTextFieldName
.setToolTipText("Enter the C Name of the HII Package");
114 return jTextFieldName
;
119 * This method initializes jComboBoxUsage
121 * @return javax.swing.JComboBox jComboBoxUsage
124 private JComboBox
getJComboBoxUsage() {
125 if (jComboBoxUsage
== null) {
126 jComboBoxUsage
= new JComboBox();
127 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
128 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
130 .setToolTipText("<html><table>"
131 + "<tr><td>ALWAYS_PRODUCED</td><td>Hii is always registered</td></tr>"
132 + "<tr><td>SOMETIMES_PRODUCED</td><td>Some executions paths will require the Hii to be registered</td></tr>"
133 + "</table></html>");
135 return jComboBoxUsage
;
140 * This method initializes jTextFieldFeatureFlag
142 * @return javax.swing.JTextField
144 private JTextField
getJTextFieldFeatureFlag() {
145 if (jTextFieldFeatureFlag
== null) {
146 jTextFieldFeatureFlag
= new JTextField();
147 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
148 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
149 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
150 jTextFieldFeatureFlag
.setEnabled(false);
152 return jTextFieldFeatureFlag
;
157 * This method initializes jScrollPane
159 * @return javax.swing.JScrollPane
162 private JScrollPane
getJScrollPane() {
163 if (jScrollPane
== null) {
164 jScrollPane
= new JScrollPane();
165 jScrollPane
.setViewportView(getJContentPane());
172 * This method initializes jTextAreaHelpText
174 * @return javax.swing.JTextArea jTextAreaHelpText
177 private JTextArea
getJTextAreaHelpText() {
178 if (jTextAreaHelpText
== null) {
179 jTextAreaHelpText
= new JTextArea();
180 jTextAreaHelpText
.setLineWrap(true);
181 jTextAreaHelpText
.setWrapStyleWord(true);
183 return jTextAreaHelpText
;
188 * This method initializes jScrollPaneHelpText
190 * @return javax.swing.JScrollPane
193 private JScrollPane
getJScrollPaneHelpText() {
194 if (jScrollPaneHelpText
== null) {
195 jScrollPaneHelpText
= new JScrollPane();
196 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
197 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
198 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
199 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 62));
200 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
202 return jScrollPaneHelpText
;
207 * This method initializes jButtonOk
209 * @return javax.swing.JButton
212 private JButton
getJButtonOk() {
213 if (jButtonOk
== null) {
214 jButtonOk
= new JButton();
215 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 162, 90, 20));
216 jButtonOk
.setText("Ok");
217 jButtonOk
.addActionListener(this);
224 * This method initializes jButtonCancel
226 * @return javax.swing.JButton
229 private JButton
getJButtonCancel() {
230 if (jButtonCancel
== null) {
231 jButtonCancel
= new JButton();
232 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 162, 90, 20));
233 jButtonCancel
.setText("Cancel");
234 jButtonCancel
.addActionListener(this);
236 return jButtonCancel
;
239 public static void main(String
[] args
) {
245 * This method initializes this
248 private void init() {
249 this.setSize(505, 235);
250 this.setContentPane(getJScrollPane());
251 this.setTitle("Hii Packages");
253 this.setViewMode(false);
258 * This method initializes this Fill values to all fields if these values are
261 * @param inHiiPackagesId
264 private void init(HiiPackagesIdentification inHiiPackagesId
, ModuleIdentification mid
) {
266 this.id
= inHiiPackagesId
;
269 // Init arch with module's arch
271 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
273 if (this.id
!= null) {
274 this.jTextFieldName
.setText(id
.getName());
275 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
276 this.jTextAreaHelpText
.setText(id
.getHelp());
277 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
278 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
283 * This is the override edit constructor
285 * @param inHiiPackagesIdentification
289 public HiiPackagesDlg(HiiPackagesIdentification inHiiPackagesIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
291 init(inHiiPackagesIdentification
, mid
);
296 * Disable all components when the mode is view
299 * true - The view mode; false - The non-view mode
302 public void setViewMode(boolean isView
) {
304 this.jTextFieldName
.setEnabled(!isView
);
305 this.jComboBoxUsage
.setEnabled(!isView
);
311 * This method initializes jContentPane
313 * @return javax.swing.JPanel jContentPane
316 private JPanel
getJContentPane() {
317 if (jContentPane
== null) {
318 jStarLabel1
= new StarLabel();
319 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
320 jLabelName
= new JLabel();
321 jLabelName
.setText("Hii Package C Name");
322 jLabelName
.setBounds(new java
.awt
.Rectangle(12, 12, 155, 20));
323 jStarLabel2
= new StarLabel();
324 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
325 jLabelUsage
= new JLabel();
326 jLabelUsage
.setText("Usage");
327 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 37, 155, 20));
328 jLabelHelpText
= new JLabel();
329 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 62, 155, 20));
330 jLabelHelpText
.setText("Help Text");
331 jLabelFeatureFlag
= new JLabel();
332 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 132, 155, 20));
333 jLabelFeatureFlag
.setText("Feature Flag Expression");
334 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(jLabelName
, null);
348 jContentPane
.add(getJTextFieldName(), null);
350 jContentPane
.add(jStarLabel2
, null);
351 jContentPane
.add(jLabelUsage
, null);
352 jContentPane
.add(getJComboBoxUsage(), null);
354 jContentPane
.add(jLabelHelpText
, null);
355 jContentPane
.add(getJScrollPaneHelpText(), null);
357 jContentPane
.add(jLabelFeatureFlag
, null);
358 jContentPane
.add(getJTextFieldFeatureFlag(), null);
360 jContentPane
.add(jLabelArch
, null);
361 jContentPane
.add(jArchCheckBox
, null);
363 jContentPane
.add(getJButtonOk(), null);
364 jContentPane
.add(getJButtonCancel(), null);
371 * This method initializes Usage type
374 private void initFrame() {
375 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVHiiPackageUsage());
381 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
383 * Override actionPerformed to listen all actions
386 public void actionPerformed(ActionEvent arg0
) {
387 if (arg0
.getSource() == jButtonOk
) {
389 getCurrentHiiPackages();
390 this.returnType
= DataType
.RETURN_TYPE_OK
;
391 this.setVisible(false);
395 if (arg0
.getSource() == jButtonCancel
) {
396 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
397 this.setVisible(false);
403 * Data validation for all fields
405 * @retval true - All datas are valid
406 * @retval false - At least one data is invalid
409 public boolean checkAdd() {
411 // Check if all fields have correct data types
415 // Check Hii Package Name
417 if (isEmpty(this.jTextFieldName
.getText())) {
418 Log
.wrn("Update Hii Packages", "Hii Package Name Record must be entered!");
422 if (!isEmpty(this.jTextFieldName
.getText())) {
423 if (!DataValidation
.isC_NameType(this.jTextFieldName
.getText())) {
424 Log
.wrn("Update Hii Packages", "Incorrect data type for Hii Package Name");
432 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
433 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
434 Log
.wrn("Update Hii Packages", "Incorrect data type for Feature Flag");
442 private HiiPackagesIdentification
getCurrentHiiPackages() {
443 String arg0
= this.jTextFieldName
.getText();
444 String arg1
= this.jComboBoxUsage
.getSelectedItem().toString();
446 String arg2
= this.jTextFieldFeatureFlag
.getText();
447 Vector
<String
> arg3
= this.jArchCheckBox
.getSelectedItemsVector();
448 String arg4
= this.jTextAreaHelpText
.getText();
450 id
= new HiiPackagesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
);
454 public HiiPackagesIdentification
getId() {
458 public void setId(HiiPackagesIdentification id
) {