]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/BootModesDlg.java
1. Fix bug for wrong Variable name in msa file
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / BootModesDlg.java
1 /** @file
2 <<The file is used to create, update BootModes of MSA file>>
3
4 <<The BootModesDlg is called to add or edit a Module's Boot Modes definitions.>>
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 Package Name: Tools
16 Module Name: FrameworkWizard
17
18 **/
19
20 package org.tianocore.frameworkwizard.module.ui.dialog;
21
22 import java.awt.event.ActionEvent;
23 import java.util.Vector;
24
25 import javax.swing.JButton;
26 import javax.swing.JComboBox;
27 import javax.swing.JLabel;
28 import javax.swing.JPanel;
29 import javax.swing.JScrollPane;
30 import javax.swing.JTextField;
31 import javax.swing.JTextArea;
32
33 import org.tianocore.frameworkwizard.common.DataType;
34 import org.tianocore.frameworkwizard.common.DataValidation;
35 import org.tianocore.frameworkwizard.common.EnumerationData;
36 import org.tianocore.frameworkwizard.common.Log;
37 import org.tianocore.frameworkwizard.common.Tools;
38 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
39 import org.tianocore.frameworkwizard.common.ui.IDialog;
40 import org.tianocore.frameworkwizard.common.ui.IFrame;
41 import org.tianocore.frameworkwizard.common.ui.StarLabel;
42 import org.tianocore.frameworkwizard.module.Identifications.BootModes.BootModesIdentification;
43
44 /**
45 * The class is used to create, update BootModes of MSA/MBD file
46 *
47 * It extends IDialog
48 *
49 */
50 public class BootModesDlg extends IDialog {
51
52 // /
53 // / Define class Serial Version UID
54 // /
55 private static final long serialVersionUID = -3888558623432442561L;
56
57 //
58 // Define class members
59 //
60 private JPanel jContentPane = null;
61
62 private JLabel jLabelBootModeName = null;
63
64 private JComboBox jComboBoxBootModeName = null;
65
66 private JLabel jLabelUsage = null;
67
68 private JComboBox jComboBoxUsage = null;
69
70 private StarLabel jStarLabel1 = null;
71
72 private StarLabel jStarLabel2 = null;
73
74 private JLabel jLabelFeatureFlag = null;
75
76 private JTextField jTextFieldFeatureFlag = null;
77
78 private JLabel jLabelArch = null;
79
80 private JScrollPane jScrollPane = null;
81
82 private JLabel jLabelHelpText = null;
83
84 private JTextArea jTextAreaHelpText = null;
85
86 private JScrollPane jScrollPaneHelpText = null;
87
88 private ArchCheckBox jArchCheckBox = null;
89
90 private JButton jButtonOk = null;
91
92 private JButton jButtonCancel = null;
93
94 //
95 // Not used by UI
96 //
97 private BootModesIdentification id = null;
98
99 private EnumerationData ed = new EnumerationData();
100
101 /**
102 * This method initializes jComboBoxBootModeName
103 *
104 * @return javax.swing.JComboBox jComboBoxBootModeName
105 *
106 */
107 private JComboBox getJComboBoxBootModeName() {
108 if (jComboBoxBootModeName == null) {
109 jComboBoxBootModeName = new JComboBox();
110 jComboBoxBootModeName.setBounds(new java.awt.Rectangle(168, 12, 320, 20));
111 jComboBoxBootModeName.setPreferredSize(new java.awt.Dimension(320, 20));
112 jComboBoxBootModeName
113 .setToolTipText("<html><table>"
114 + "<tr><td>FULL</td><td>Boot with full configuration</td></tr>"
115 + "<tr><td>MINIMAL</td><td>Boot with minimal configuration</td></tr>"
116 + "<tr><td>NO_CHANGE</td><td>Boot assuming no configuration changes</td></tr>"
117 + "<tr><td>DIAGNOSTICS</td><td>Boot with full configuration plus diagnostics</td></tr>"
118 + "<tr><td>DEFAULT</td><td>Boot with default settings</td></tr>"
119 + "<tr><td>BOOT_ON_S#_RESUME</td><td>where # is 2, 3, 4 or 5</td></tr>"
120 + "<tr><td>FLASH_UPDATE</td><td>Boot on flash update</td></tr>"
121 + "<tr><td>RECOVERY</td><td>Boot in recovery mode</td></tr>"
122 + "</table></html>");
123 }
124 return jComboBoxBootModeName;
125 }
126
127 /**
128 * This method initializes jComboBoxUsage
129 *
130 * @return javax.swing.JComboBox jComboBoxUsage
131 *
132 */
133 private JComboBox getJComboBoxUsage() {
134 if (jComboBoxUsage == null) {
135 jComboBoxUsage = new JComboBox();
136 jComboBoxUsage.setBounds(new java.awt.Rectangle(168, 37, 320, 20));
137 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
138 jComboBoxUsage
139 .setToolTipText("<html><table>"
140 + "<tr><td>ALWAYS_CONSUMED</td><td>Indicates Supports the specified boot mode</td></tr>"
141 + "<tr><td>SOMETIMES_CONSUMED</td><td>Indicates Supports the specified boot mode on some execution paths</td></tr>"
142 + "<tr><td>ALWAYS_PRODUCED</td><td>Always changes the boot mode</td></tr>"
143 + "<tr><td>SOMETIMES_PRODUCED</td><td>Change the boot mode sometimes</td></tr>"
144 + "</table></html>");
145 }
146 return jComboBoxUsage;
147 }
148
149 /**
150 * This method initializes jTextFieldFeatureFlag
151 *
152 * @return javax.swing.JTextField
153 */
154 private JTextField getJTextFieldFeatureFlag() {
155 if (jTextFieldFeatureFlag == null) {
156 jTextFieldFeatureFlag = new JTextField();
157 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(168, 107, 320, 20));
158 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
159 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
160 }
161 return jTextFieldFeatureFlag;
162 }
163
164 /**
165 * This method initializes jScrollPane
166 *
167 * @return javax.swing.JScrollPane
168 */
169 private JScrollPane getJScrollPane() {
170 if (jScrollPane == null) {
171 jScrollPane = new JScrollPane();
172 jScrollPane.setViewportView(getJContentPane());
173 }
174 return jScrollPane;
175 }
176
177 /**
178 * This method initializes jTextAreaHelpText
179 *
180 * @return javax.swing.JTextArea
181 *
182 */
183 private JTextArea getJTextAreaHelpText() {
184 if (jTextAreaHelpText == null) {
185 jTextAreaHelpText = new JTextArea();
186 jTextAreaHelpText.setLineWrap(true);
187 jTextAreaHelpText.setWrapStyleWord(true);
188 }
189 return jTextAreaHelpText;
190 }
191
192 /**
193 * This method initializes jScrollPaneHelpText
194 *
195 * @return javax.swing.JScrollPane
196 *
197 */
198 private JScrollPane getJScrollPaneHelpText() {
199 if (jScrollPaneHelpText == null) {
200 jScrollPaneHelpText = new JScrollPane();
201 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
202 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));
203 jScrollPaneHelpText.setPreferredSize(new java.awt.Dimension(320, 40));
204 jScrollPaneHelpText.setLocation(new java.awt.Point(168, 62));
205 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
206 }
207 return jScrollPaneHelpText;
208 }
209
210 /**
211 * This method initializes jButtonOk
212 *
213 * @return javax.swing.JButton
214 *
215 */
216 private JButton getJButtonOk() {
217 if (jButtonOk == null) {
218 jButtonOk = new JButton();
219 jButtonOk.setBounds(new java.awt.Rectangle(290, 162, 90, 20));
220 jButtonOk.setText("Ok");
221 jButtonOk.addActionListener(this);
222 }
223 return jButtonOk;
224 }
225
226 /**
227 * This method initializes jButtonCancel
228 *
229 * @return javax.swing.JButton
230 *
231 */
232 private JButton getJButtonCancel() {
233 if (jButtonCancel == null) {
234 jButtonCancel = new JButton();
235 jButtonCancel.setBounds(new java.awt.Rectangle(390, 162, 90, 20));
236 jButtonCancel.setText("Cancel");
237 jButtonCancel.addActionListener(this);
238 }
239 return jButtonCancel;
240 }
241
242 public static void main(String[] args) {
243 }
244
245 /**
246 * This method initializes this
247 *
248 */
249 private void init() {
250 this.setSize(505, 235);
251 this.setContentPane(getJScrollPane());
252 this.setTitle("Boot Modes");
253 initFrame();
254 this.setViewMode(false);
255 this.centerWindow();
256 }
257
258 /**
259 * This method initializes this Fill values to all fields if these values are
260 * not empty
261 *
262 * @param inBootModesId
263 *
264 */
265 private void init(BootModesIdentification inBootModesId) {
266 init();
267 this.id = inBootModesId;
268
269 if (this.id != null) {
270 this.jComboBoxBootModeName.setSelectedItem(id.getName());
271 this.jComboBoxUsage.setSelectedItem(id.getUsage());
272 this.jTextAreaHelpText.setText(id.getHelp());
273 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
274 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
275 }
276 }
277
278 /**
279 * This is the override edit constructor
280 *
281 * @param inBootModesIdentification
282 * @param iFrame
283 *
284 */
285 public BootModesDlg(BootModesIdentification inBootModesIdentification, IFrame iFrame) {
286 super(iFrame, true);
287 init(inBootModesIdentification);
288 }
289
290 /**
291 * Disable all components when the mode is view
292 *
293 * @param isView
294 * true - The view mode; false - The non-view mode
295 *
296 */
297 public void setViewMode(boolean isView) {
298 if (isView) {
299 this.jComboBoxBootModeName.setEnabled(!isView);
300 this.jComboBoxUsage.setEnabled(!isView);
301 }
302 }
303
304 /**
305 * This method initializes jContentPane
306 *
307 * @return javax.swing.JPanel jContentPane
308 *
309 */
310 private JPanel getJContentPane() {
311 if (jContentPane == null) {
312 jStarLabel1 = new StarLabel();
313 jStarLabel1.setLocation(new java.awt.Point(2, 12));
314 jLabelBootModeName = new JLabel();
315 jLabelBootModeName.setText("Boot Mode Name");
316 jLabelBootModeName.setBounds(new java.awt.Rectangle(12, 12, 155, 20));
317 jStarLabel2 = new StarLabel();
318 jStarLabel2.setLocation(new java.awt.Point(2, 37));
319 jLabelUsage = new JLabel();
320 jLabelUsage.setText("Usage");
321 jLabelUsage.setBounds(new java.awt.Rectangle(12, 37, 155, 20));
322 jLabelHelpText = new JLabel();
323 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 62, 155, 20));
324 jLabelHelpText.setText("Help Text");
325 jLabelFeatureFlag = new JLabel();
326 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 107, 155, 20));
327 jLabelFeatureFlag.setText("Feature Flag Expression");
328 jLabelArch = new JLabel();
329 jLabelArch.setBounds(new java.awt.Rectangle(12, 132, 155, 20));
330 jLabelArch.setText("Supported Archectures");
331 jArchCheckBox = new ArchCheckBox();
332 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 132, 320, 20));
333 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
334
335 jContentPane = new JPanel();
336 jContentPane.setLayout(null);
337 jContentPane.setPreferredSize(new java.awt.Dimension(480, 180));
338
339 jContentPane.add(jLabelBootModeName, null);
340 jContentPane.add(getJComboBoxBootModeName(), null);
341 jContentPane.add(jLabelUsage, null);
342 jContentPane.add(getJComboBoxUsage(), null);
343
344 jContentPane.add(jStarLabel1, null);
345 jContentPane.add(jStarLabel2, null);
346 jContentPane.add(jLabelFeatureFlag, null);
347 jContentPane.add(getJTextFieldFeatureFlag(), null);
348 jContentPane.add(jLabelArch, null);
349
350 jContentPane.add(jLabelHelpText, null);
351 jContentPane.add(getJScrollPaneHelpText(), null);
352 jContentPane.add(jArchCheckBox, null);
353 jContentPane.add(getJButtonOk(), null);
354 jContentPane.add(getJButtonCancel(), null);
355 }
356 return jContentPane;
357 }
358
359 /**
360 * This method initializes BootModeName groups and Usage type
361 *
362 */
363 private void initFrame() {
364 Tools.generateComboBoxByVector(jComboBoxBootModeName, ed.getVBootModeNames());
365 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPpiUsage());
366 }
367
368 /*
369 * (non-Javadoc)
370 *
371 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
372 *
373 * Override actionPerformed to listen all actions
374 *
375 */
376 public void actionPerformed(ActionEvent arg0) {
377 if (arg0.getSource() == jButtonOk) {
378 if (checkAdd()) {
379 getCurrentBootModes();
380 this.returnType = DataType.RETURN_TYPE_OK;
381 this.setVisible(false);
382 }
383 }
384
385 if (arg0.getSource() == jButtonCancel) {
386 this.returnType = DataType.RETURN_TYPE_CANCEL;
387 this.setVisible(false);
388 }
389 }
390
391 /**
392 * Data validation for all fields
393 *
394 * @retval true - All datas are valid
395 * @retval false - At least one data is invalid
396 *
397 */
398 public boolean checkAdd() {
399 //
400 // Check if all fields have correct data types
401 //
402
403 //
404 // Check FeatureFlag
405 //
406 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
407 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
408 Log.wrn("Update Boot Modes", "Incorrect data type for Feature Flag");
409 return false;
410 }
411 }
412
413 return true;
414 }
415
416 private BootModesIdentification getCurrentBootModes() {
417 String arg0 = this.jComboBoxBootModeName.getSelectedItem().toString();
418 String arg1 = this.jComboBoxUsage.getSelectedItem().toString();
419
420 String arg2 = this.jTextFieldFeatureFlag.getText();
421 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
422 String arg4 = this.jTextAreaHelpText.getText();
423 id = new BootModesIdentification(arg0, arg1, arg2, arg3, arg4);
424 return id;
425 }
426
427 public BootModesIdentification getId() {
428 return id;
429 }
430
431 public void setId(BootModesIdentification id) {
432 this.id = id;
433 }
434 }