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