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