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