]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/BootModesDlg.java
88a010ef35bcc84375e69354842064c1ac84e149
[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, 132, 320, 20));
158 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
159 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
160 jTextFieldFeatureFlag.setEnabled(false);
161 }
162 return jTextFieldFeatureFlag;
163 }
164
165 /**
166 * This method initializes jScrollPane
167 *
168 * @return javax.swing.JScrollPane
169 */
170 private JScrollPane getJScrollPane() {
171 if (jScrollPane == null) {
172 jScrollPane = new JScrollPane();
173 jScrollPane.setViewportView(getJContentPane());
174 }
175 return jScrollPane;
176 }
177
178 /**
179 * This method initializes jTextAreaHelpText
180 *
181 * @return javax.swing.JTextArea
182 *
183 */
184 private JTextArea getJTextAreaHelpText() {
185 if (jTextAreaHelpText == null) {
186 jTextAreaHelpText = new JTextArea();
187 jTextAreaHelpText.setLineWrap(true);
188 jTextAreaHelpText.setWrapStyleWord(true);
189 }
190 return jTextAreaHelpText;
191 }
192
193 /**
194 * This method initializes jScrollPaneHelpText
195 *
196 * @return javax.swing.JScrollPane
197 *
198 */
199 private JScrollPane getJScrollPaneHelpText() {
200 if (jScrollPaneHelpText == null) {
201 jScrollPaneHelpText = new JScrollPane();
202 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
203 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));
204 jScrollPaneHelpText.setPreferredSize(new java.awt.Dimension(320, 40));
205 jScrollPaneHelpText.setLocation(new java.awt.Point(168, 62));
206 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
207 }
208 return jScrollPaneHelpText;
209 }
210
211 /**
212 * This method initializes jButtonOk
213 *
214 * @return javax.swing.JButton
215 *
216 */
217 private JButton getJButtonOk() {
218 if (jButtonOk == null) {
219 jButtonOk = new JButton();
220 jButtonOk.setBounds(new java.awt.Rectangle(290, 162, 90, 20));
221 jButtonOk.setText("Ok");
222 jButtonOk.addActionListener(this);
223 }
224 return jButtonOk;
225 }
226
227 /**
228 * This method initializes jButtonCancel
229 *
230 * @return javax.swing.JButton
231 *
232 */
233 private JButton getJButtonCancel() {
234 if (jButtonCancel == null) {
235 jButtonCancel = new JButton();
236 jButtonCancel.setBounds(new java.awt.Rectangle(390, 162, 90, 20));
237 jButtonCancel.setText("Cancel");
238 jButtonCancel.addActionListener(this);
239 }
240 return jButtonCancel;
241 }
242
243 public static void main(String[] args) {
244 }
245
246 /**
247 * This method initializes this
248 *
249 */
250 private void init() {
251 this.setSize(505, 235);
252 this.setContentPane(getJScrollPane());
253 this.setTitle("Boot Modes");
254 initFrame();
255 this.setViewMode(false);
256 this.centerWindow();
257 }
258
259 /**
260 * This method initializes this Fill values to all fields if these values are
261 * not empty
262 *
263 * @param inBootModesId
264 *
265 */
266 private void init(BootModesIdentification inBootModesId) {
267 init();
268 this.id = inBootModesId;
269
270 if (this.id != null) {
271 this.jComboBoxBootModeName.setSelectedItem(id.getName());
272 this.jComboBoxUsage.setSelectedItem(id.getUsage());
273 this.jTextAreaHelpText.setText(id.getHelp());
274 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
275 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
276 }
277 }
278
279 /**
280 * This is the override edit constructor
281 *
282 * @param inBootModesIdentification
283 * @param iFrame
284 *
285 */
286 public BootModesDlg(BootModesIdentification inBootModesIdentification, IFrame iFrame) {
287 super(iFrame, true);
288 init(inBootModesIdentification);
289 }
290
291 /**
292 * Disable all components when the mode is view
293 *
294 * @param isView
295 * true - The view mode; false - The non-view mode
296 *
297 */
298 public void setViewMode(boolean isView) {
299 if (isView) {
300 this.jComboBoxBootModeName.setEnabled(!isView);
301 this.jComboBoxUsage.setEnabled(!isView);
302 }
303 }
304
305 /**
306 * This method initializes jContentPane
307 *
308 * @return javax.swing.JPanel jContentPane
309 *
310 */
311 private JPanel getJContentPane() {
312 if (jContentPane == null) {
313 jStarLabel1 = new StarLabel();
314 jStarLabel1.setLocation(new java.awt.Point(2, 12));
315 jLabelBootModeName = new JLabel();
316 jLabelBootModeName.setText("Boot Mode Name");
317 jLabelBootModeName.setBounds(new java.awt.Rectangle(12, 12, 155, 20));
318 jStarLabel2 = new StarLabel();
319 jStarLabel2.setLocation(new java.awt.Point(2, 37));
320 jLabelUsage = new JLabel();
321 jLabelUsage.setText("Usage");
322 jLabelUsage.setBounds(new java.awt.Rectangle(12, 37, 155, 20));
323 jLabelHelpText = new JLabel();
324 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 62, 155, 20));
325 jLabelHelpText.setText("Help Text");
326 jLabelFeatureFlag = new JLabel();
327 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 132, 155, 20));
328 jLabelFeatureFlag.setText("Feature Flag Expression");
329 jLabelFeatureFlag.setEnabled(false);
330 jLabelArch = new JLabel();
331 jLabelArch.setBounds(new java.awt.Rectangle(12, 107, 155, 20));
332 jLabelArch.setText("Supported Archectures");
333 jArchCheckBox = new ArchCheckBox();
334 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 107, 320, 20));
335 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
336
337 jContentPane = new JPanel();
338 jContentPane.setLayout(null);
339 jContentPane.setPreferredSize(new java.awt.Dimension(480, 180));
340
341 jContentPane.add(jLabelBootModeName, null);
342 jContentPane.add(getJComboBoxBootModeName(), null);
343 jContentPane.add(jLabelUsage, null);
344 jContentPane.add(getJComboBoxUsage(), null);
345
346 jContentPane.add(jStarLabel1, null);
347 jContentPane.add(jStarLabel2, null);
348 jContentPane.add(jLabelFeatureFlag, null);
349 jContentPane.add(getJTextFieldFeatureFlag(), null);
350 jContentPane.add(jLabelArch, null);
351
352 jContentPane.add(jLabelHelpText, null);
353 jContentPane.add(getJScrollPaneHelpText(), null);
354 jContentPane.add(jArchCheckBox, null);
355 jContentPane.add(getJButtonOk(), null);
356 jContentPane.add(getJButtonCancel(), null);
357 }
358 return jContentPane;
359 }
360
361 /**
362 * This method initializes BootModeName groups and Usage type
363 *
364 */
365 private void initFrame() {
366 Tools.generateComboBoxByVector(jComboBoxBootModeName, ed.getVBootModeNames());
367 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPpiUsage());
368 }
369
370 /*
371 * (non-Javadoc)
372 *
373 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
374 *
375 * Override actionPerformed to listen all actions
376 *
377 */
378 public void actionPerformed(ActionEvent arg0) {
379 if (arg0.getSource() == jButtonOk) {
380 if (checkAdd()) {
381 getCurrentBootModes();
382 this.returnType = DataType.RETURN_TYPE_OK;
383 this.setVisible(false);
384 }
385 }
386
387 if (arg0.getSource() == jButtonCancel) {
388 this.returnType = DataType.RETURN_TYPE_CANCEL;
389 this.setVisible(false);
390 }
391 }
392
393 /**
394 * Data validation for all fields
395 *
396 * @retval true - All datas are valid
397 * @retval false - At least one data is invalid
398 *
399 */
400 public boolean checkAdd() {
401 //
402 // Check if all fields have correct data types
403 //
404
405 //
406 // Check FeatureFlag
407 //
408 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
409 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
410 Log.wrn("Update Boot Modes", "Incorrect data type for Feature Flag");
411 return false;
412 }
413 }
414
415 return true;
416 }
417
418 private BootModesIdentification getCurrentBootModes() {
419 String arg0 = this.jComboBoxBootModeName.getSelectedItem().toString();
420 String arg1 = this.jComboBoxUsage.getSelectedItem().toString();
421
422 String arg2 = this.jTextFieldFeatureFlag.getText();
423 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
424 String arg4 = this.jTextAreaHelpText.getText();
425 id = new BootModesIdentification(arg0, arg1, arg2, arg3, arg4);
426 return id;
427 }
428
429 public BootModesIdentification getId() {
430 return id;
431 }
432
433 public void setId(BootModesIdentification id) {
434 this.id = id;
435 }
436 }