Fixed grammar in messages.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / HobsDlg.java
CommitLineData
06a19cee 1/** @file\r
2 \r
9e857952 3 The file is used to create, update Hob section of the MSA file\r
06a19cee 4 \r
5 Copyright (c) 2006, Intel Corporation\r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13 \r
14 **/\r
15package org.tianocore.frameworkwizard.module.ui.dialog;\r
16\r
17import java.awt.event.ActionEvent;\r
18import java.util.Vector;\r
19\r
20import javax.swing.JButton;\r
21import javax.swing.JComboBox;\r
22import javax.swing.JLabel;\r
23import javax.swing.JPanel;\r
24import javax.swing.JScrollPane;\r
25import javax.swing.JTextField;\r
5101eff9 26import javax.swing.JTextArea;\r
06a19cee 27\r
28import org.tianocore.frameworkwizard.common.DataType;\r
29import org.tianocore.frameworkwizard.common.DataValidation;\r
30import org.tianocore.frameworkwizard.common.EnumerationData;\r
31import org.tianocore.frameworkwizard.common.Log;\r
32import org.tianocore.frameworkwizard.common.Tools;\r
33import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;\r
34import org.tianocore.frameworkwizard.common.ui.IDialog;\r
35import org.tianocore.frameworkwizard.common.ui.IFrame;\r
36import org.tianocore.frameworkwizard.common.ui.StarLabel;\r
37import org.tianocore.frameworkwizard.module.Identifications.Hobs.HobsIdentification;\r
38import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r
39\r
40/**\r
9e857952 41 * The class is used to create, update Hob of the MSA file \r
42 * \r
43 * It extends IDialog\r
5101eff9 44 * \r
45 */\r
06a19cee 46public class HobsDlg extends IDialog {\r
47\r
a929458e 48 // /\r
49 // / Define class Serial Version UID\r
50 // /\r
51 private static final long serialVersionUID = -553473437579358325L;\r
06a19cee 52\r
a929458e 53 //\r
54 // Define class members\r
55 //\r
56 private JPanel jContentPane = null;\r
06a19cee 57\r
a929458e 58 private JLabel jLabelC_Name = null;\r
06a19cee 59\r
a929458e 60 private JComboBox jComboBoxGuidC_Name = null;\r
06a19cee 61\r
a929458e 62 private JLabel jLabelUsage = null;\r
06a19cee 63\r
a929458e 64 private JLabel jLabelHobType = null;\r
06a19cee 65\r
a929458e 66 private JComboBox jComboBoxUsage = null;\r
06a19cee 67\r
a929458e 68 private JComboBox jComboBoxHobType = null;\r
06a19cee 69\r
a929458e 70 private StarLabel jStarLabel1 = null;\r
06a19cee 71\r
a929458e 72 private StarLabel jStarLabel2 = null;\r
06a19cee 73\r
a929458e 74 private StarLabel jStarLabel3 = null;\r
06a19cee 75\r
a929458e 76 private JLabel jLabelArch = null;\r
06a19cee 77\r
a929458e 78 private JScrollPane jScrollPane = null;\r
06a19cee 79\r
a929458e 80 private JLabel jLabelFeatureFlag = null;\r
06a19cee 81\r
a929458e 82 private JTextField jTextFieldFeatureFlag = null;\r
06a19cee 83\r
a929458e 84 private JLabel jLabelHelpText = null;\r
06a19cee 85\r
a929458e 86 private JTextArea jTextAreaHelpText = null;\r
06a19cee 87\r
a929458e 88 private JScrollPane jScrollPaneHelpText = null;\r
06a19cee 89\r
a929458e 90 private ArchCheckBox jArchCheckBox = null;\r
06a19cee 91\r
a929458e 92 private JButton jButtonOk = null;\r
06a19cee 93\r
a929458e 94 private JButton jButtonCancel = null;\r
06a19cee 95\r
a929458e 96 //\r
97 // Not used by UI\r
98 //\r
99 private HobsIdentification id = null;\r
100\r
101 private EnumerationData ed = new EnumerationData();\r
102\r
103 private WorkspaceTools wt = new WorkspaceTools();\r
104\r
105 /**\r
106 * This method initializes jTextField\r
107 * \r
108 * @return javax.swing.JTextField jTextFieldC_Name\r
109 * \r
110 */\r
111 private JComboBox getJComboBoxGuidC_Name() {\r
112 if (jComboBoxGuidC_Name == null) {\r
113 jComboBoxGuidC_Name = new JComboBox();\r
3f62225f 114 jComboBoxGuidC_Name.setBounds(new java.awt.Rectangle(168, 12, 320, 20));\r
a929458e 115 jComboBoxGuidC_Name.setPreferredSize(new java.awt.Dimension(320, 20));\r
116 jComboBoxGuidC_Name.setToolTipText("Select the GUID C Name of the Hob");\r
117 }\r
118 return jComboBoxGuidC_Name;\r
119 }\r
06a19cee 120\r
a929458e 121 /**\r
122 * This method initializes jComboBoxHobType\r
123 * \r
124 * @return javax.swing.JComboBox jComboBoxHobType\r
125 * \r
126 */\r
127 private JComboBox getJComboBoxHobType() {\r
128 if (jComboBoxHobType == null) {\r
129 jComboBoxHobType = new JComboBox();\r
3f62225f 130 jComboBoxHobType.setBounds(new java.awt.Rectangle(168, 37, 320, 20));\r
a929458e 131 jComboBoxHobType.setPreferredSize(new java.awt.Dimension(320, 20));\r
132 jComboBoxHobType\r
133 .setToolTipText("<html><table>"\r
134 + "<tr><td>PHIT</td><td>EFI_HOB_TYPE_HANDOFF</td></tr>"\r
135 + "<tr><td>MEMORY_ALLOCATION</td><td>EFI_HOB_TYPE_MEMORY_ALLOCATION and $BaseName</td></tr>"\r
136 + "<tr><td>RESOURCE_DESCRIPTOR</td><td>EFI_HOB_TYPE_RESOURCE_DESCRIPTOR</td></tr>"\r
137 + "<tr><td>GUID_EXTENTION</td><td>EFI_HOB_TYPE_GUID_EXTENSION and BaseName of GUID</td></tr>"\r
138 + "<tr><td>FIRMWARE_VOLUME</td><td>EFI_HOB_TYPE_FV</td></tr>"\r
139 + "<tr><td>CPU</td><td>EFI_HOB_TYPE_CPU</td></tr>"\r
140 + "<tr><td>POOL</td><td>EFI_HOB_TYPE_PEI_MEMORY_POOL</td></tr>"\r
141 + "<tr><td>CAPSULE_VOLUME</td><td>EFI_HOB_TYPE_CV</td></tr>"\r
142 + "</table></html>");\r
143 }\r
144 return jComboBoxHobType;\r
145 }\r
06a19cee 146\r
a929458e 147 /**\r
148 * This method initializes jComboBoxUsage\r
149 * \r
150 * @return javax.swing.JComboBox jComboBoxUsage\r
151 * \r
152 */\r
153 private JComboBox getJComboBoxUsage() {\r
154 if (jComboBoxUsage == null) {\r
155 jComboBoxUsage = new JComboBox();\r
3f62225f 156 jComboBoxUsage.setBounds(new java.awt.Rectangle(168, 62, 320, 20));\r
a929458e 157 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));\r
158 jComboBoxUsage\r
159 .setToolTipText("<html><table>"\r
160 + "<tr><td>ALWAYS_CONSUMED</td><td>HOB must be present in the system</td></tr>"\r
161 + "<tr><td>SOMETIMES_CONSUMED</td><td>HOB will be used if it's present</td></tr>"\r
162 + "<tr><td>ALWAYS_PRODUCED</td><td>HOB is always produced</td></tr>"\r
163 + "<tr><td>SOMETIMES_PRODUCED</td><td>HOB will sometimes be produced by the module</td></tr>"\r
164 + "</table></html>");\r
165 }\r
166 return jComboBoxUsage;\r
167 }\r
06a19cee 168\r
a929458e 169 /**\r
170 * This method initializes jScrollPane\r
171 * \r
172 * @return javax.swing.JScrollPane\r
173 */\r
174 private JScrollPane getJScrollPane() {\r
175 if (jScrollPane == null) {\r
176 jScrollPane = new JScrollPane();\r
177 jScrollPane.setViewportView(getJContentPane());\r
178 }\r
179 return jScrollPane;\r
06a19cee 180 }\r
a929458e 181\r
182 /**\r
183 * This method initializes jTextFieldFeatureFlag\r
184 * \r
185 * @return javax.swing.JTextField\r
186 */\r
187 private JTextField getJTextFieldFeatureFlag() {\r
188 if (jTextFieldFeatureFlag == null) {\r
189 jTextFieldFeatureFlag = new JTextField();\r
21b42c66 190 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(168, 157, 320, 20));\r
a929458e 191 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));\r
192 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");\r
21b42c66 193 jTextFieldFeatureFlag.setEnabled(false);\r
a929458e 194 }\r
195 return jTextFieldFeatureFlag;\r
06a19cee 196 }\r
a929458e 197\r
198 /**\r
199 * This method initializes jTextFieldHelpText\r
200 * \r
201 * @return javax.swing.JTextField\r
202 * \r
203 */\r
204 private JTextArea getJTextAreaHelpText() {\r
205 if (jTextAreaHelpText == null) {\r
206 jTextAreaHelpText = new JTextArea();\r
207 jTextAreaHelpText.setLineWrap(true);\r
208 jTextAreaHelpText.setWrapStyleWord(true);\r
209 }\r
210 return jTextAreaHelpText;\r
06a19cee 211 }\r
a929458e 212\r
213 /**\r
214 * This method initializes jScrollPaneHelpText\r
215 * \r
216 * @return javax.swing.JScrollPane\r
217 */\r
218 private JScrollPane getJScrollPaneHelpText() {\r
219 if (jScrollPaneHelpText == null) {\r
220 jScrollPaneHelpText = new JScrollPane();\r
221 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);\r
222 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));\r
223 jScrollPaneHelpText.setPreferredSize(new java.awt.Dimension(320, 40));\r
3f62225f 224 jScrollPaneHelpText.setLocation(new java.awt.Point(168, 87));\r
a929458e 225 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());\r
226 }\r
227 return jScrollPaneHelpText;\r
06a19cee 228 }\r
a929458e 229\r
230 /**\r
231 * This method initializes jButtonOk\r
232 * \r
233 * @return javax.swing.JButton\r
234 * \r
235 */\r
236 private JButton getJButtonOk() {\r
237 if (jButtonOk == null) {\r
238 jButtonOk = new JButton();\r
3f62225f 239 jButtonOk.setBounds(new java.awt.Rectangle(290, 187, 90, 20));\r
a929458e 240 jButtonOk.setText("Ok");\r
241 jButtonOk.addActionListener(this);\r
242 }\r
243 return jButtonOk;\r
06a19cee 244 }\r
a929458e 245\r
246 /**\r
247 * This method initializes jButtonCancel\r
248 * \r
249 * @return javax.swing.JButton\r
250 * \r
251 */\r
252 private JButton getJButtonCancel() {\r
253 if (jButtonCancel == null) {\r
254 jButtonCancel = new JButton();\r
3f62225f 255 jButtonCancel.setBounds(new java.awt.Rectangle(390, 187, 90, 20));\r
a929458e 256 jButtonCancel.setText("Cancel");\r
257 jButtonCancel.addActionListener(this);\r
258 }\r
259 return jButtonCancel;\r
06a19cee 260 }\r
a929458e 261\r
262 public static void main(String[] args) {\r
263\r
06a19cee 264 }\r
a929458e 265\r
266 /**\r
267 * This method initializes this\r
268 * \r
269 */\r
270 private void init() {\r
3f62225f 271 this.setSize(505, 260);\r
a929458e 272 this.setContentPane(getJScrollPane());\r
273 this.setTitle("Hobs");\r
274 initFrame();\r
275 this.setViewMode(false);\r
276 this.centerWindow();\r
06a19cee 277 }\r
a929458e 278\r
279 /**\r
280 * This method initializes this Fill values to all fields if these values are\r
281 * not empty\r
282 * \r
283 * @param inHobsId\r
284 * \r
285 */\r
286 private void init(HobsIdentification inHobsId) {\r
287 init();\r
288 this.id = inHobsId;\r
289\r
290 if (this.id != null) {\r
291 this.jComboBoxGuidC_Name.setSelectedItem(id.getName());\r
292 this.jComboBoxHobType.setSelectedItem(id.getType());\r
293 this.jComboBoxUsage.setSelectedItem(id.getUsage());\r
294 this.jTextAreaHelpText.setText(id.getHelp());\r
295 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());\r
296 this.jArchCheckBox.setSelectedItems(id.getSupArchList());\r
297 }\r
06a19cee 298 }\r
a929458e 299\r
300 /**\r
301 * This is the override edit constructor\r
302 * \r
303 * @param inHobsIdentification\r
304 * @param iFrame\r
305 * \r
306 */\r
307 public HobsDlg(HobsIdentification inHobsIdentification, IFrame iFrame) {\r
308 super(iFrame, true);\r
309 init(inHobsIdentification);\r
06a19cee 310 }\r
a929458e 311\r
312 /**\r
313 * Disable all components when the mode is view\r
314 * \r
315 * @param isView\r
316 * true - The view mode; false - The non-view mode\r
317 * \r
318 */\r
319 public void setViewMode(boolean isView) {\r
320 if (isView) {\r
321 this.jComboBoxGuidC_Name.setEnabled(!isView);\r
322 this.jComboBoxUsage.setEnabled(!isView);\r
323 this.jComboBoxHobType.setEnabled(!isView);\r
324 }\r
5101eff9 325 }\r
a929458e 326\r
327 /**\r
328 * This method initializes jContentPane\r
329 * \r
330 * @return javax.swing.JPanel jContentPane\r
331 * \r
332 */\r
333 public JPanel getJContentPane() {\r
334 if (jContentPane == null) {\r
335 jStarLabel1 = new StarLabel();\r
3f62225f 336 jStarLabel1.setLocation(new java.awt.Point(2, 12));\r
a929458e 337 jLabelC_Name = new JLabel();\r
338 jLabelC_Name.setText("Hob's Guid C Name");\r
3f62225f 339 jLabelC_Name.setBounds(new java.awt.Rectangle(12, 12, 155, 20));\r
a929458e 340\r
341 jStarLabel2 = new StarLabel();\r
3f62225f 342 jStarLabel2.setLocation(new java.awt.Point(2, 37));\r
a929458e 343 jLabelHobType = new JLabel();\r
344 jLabelHobType.setText("Hob Type");\r
3f62225f 345 jLabelHobType.setBounds(new java.awt.Rectangle(12, 37, 155, 20));\r
a929458e 346\r
347 jStarLabel3 = new StarLabel();\r
3f62225f 348 jStarLabel3.setLocation(new java.awt.Point(2, 62));\r
a929458e 349 jLabelUsage = new JLabel();\r
350 jLabelUsage.setText("Usage");\r
3f62225f 351 jLabelUsage.setBounds(new java.awt.Rectangle(12, 62, 155, 20));\r
a929458e 352\r
353 jLabelHelpText = new JLabel();\r
3f62225f 354 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 87, 155, 20));\r
a929458e 355 jLabelHelpText.setText("Help Text");\r
356\r
357 jLabelFeatureFlag = new JLabel();\r
21b42c66 358 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 157, 155, 20));\r
a929458e 359 jLabelFeatureFlag.setText("Feature Flag Expression");\r
21b42c66 360 jLabelFeatureFlag.setEnabled(false);\r
a929458e 361\r
362 jLabelArch = new JLabel();\r
21b42c66 363 jLabelArch.setBounds(new java.awt.Rectangle(12, 132, 155, 20));\r
a929458e 364 jLabelArch.setText("Supported Architectures");\r
365 jArchCheckBox = new ArchCheckBox();\r
21b42c66 366 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 132, 320, 20));\r
a929458e 367 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));\r
368\r
369 jContentPane = new JPanel();\r
370 jContentPane.setLayout(null);\r
3f62225f 371 jContentPane.setPreferredSize(new java.awt.Dimension(485, 215));\r
a929458e 372\r
373 jContentPane.add(jStarLabel1, null);\r
374 jContentPane.add(jLabelC_Name, null);\r
375 jContentPane.add(getJComboBoxGuidC_Name(), null);\r
376 jContentPane.add(jStarLabel2, null);\r
377 jContentPane.add(jLabelHobType, null);\r
378 jContentPane.add(getJComboBoxHobType(), null);\r
379 jContentPane.add(jStarLabel3, null);\r
380 jContentPane.add(jLabelUsage, null);\r
381 jContentPane.add(getJComboBoxUsage(), null);\r
382 jContentPane.add(jLabelHelpText, null);\r
383 jContentPane.add(getJScrollPaneHelpText(), null);\r
384 jContentPane.add(jLabelFeatureFlag, null);\r
385 jContentPane.add(getJTextFieldFeatureFlag(), null);\r
386 jContentPane.add(jLabelArch, null);\r
387 jContentPane.add(jArchCheckBox, null);\r
388 jContentPane.add(getJButtonOk(), null);\r
389 jContentPane.add(getJButtonCancel(), null);\r
390 }\r
391 return jContentPane;\r
5101eff9 392 }\r
a929458e 393\r
394 /**\r
395 * This method initializes Usage type and Hob type\r
396 * \r
397 */\r
398 private void initFrame() {\r
399 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVHobUsage());\r
400 Tools.generateComboBoxByVector(jComboBoxHobType, ed.getVHobType());\r
401 Tools.generateComboBoxByVector(jComboBoxGuidC_Name, wt.getAllGuidDeclarationsFromWorkspace());\r
06a19cee 402 }\r
403\r
a929458e 404 /*\r
405 * (non-Javadoc)\r
406 * \r
407 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
408 * \r
409 * Override actionPerformed to listen all actions\r
410 * \r
411 */\r
412 public void actionPerformed(ActionEvent arg0) {\r
413 if (arg0.getSource() == jButtonOk) {\r
414 if (checkAdd()) {\r
415 getCurrentHobs();\r
416 this.returnType = DataType.RETURN_TYPE_OK;\r
417 this.setVisible(false);\r
418 }\r
419 }\r
420\r
421 if (arg0.getSource() == jButtonCancel) {\r
422 this.returnType = DataType.RETURN_TYPE_CANCEL;\r
423 this.setVisible(false);\r
424 }\r
5101eff9 425 }\r
06a19cee 426\r
a929458e 427 /**\r
428 * Data validation for all fields\r
429 * \r
430 * @retval true - All datas are valid\r
431 * @retval false - At least one data is invalid\r
432 * \r
433 */\r
434 public boolean checkAdd() {\r
435 //\r
436 // Check if all fields have correct data types\r
437 //\r
438\r
439 //\r
440 // Check Name\r
441 //\r
442 if (isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {\r
623db5ca 443 Log.wrn("Update Hobs", "Hob Guid C Name must be entered!");\r
a929458e 444 return false;\r
445 }\r
446\r
447 if (!isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {\r
448 if (!DataValidation.isC_NameType(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {\r
449 Log.wrn("Update Hobs", "Incorrect data type for Hob Name");\r
450 return false;\r
451 }\r
452 }\r
453\r
454 //\r
455 // Check FeatureFlag\r
456 //\r
457 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r
458 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r
459 Log.wrn("Update Hobs", "Incorrect data type for Feature Flag");\r
460 return false;\r
461 }\r
462 }\r
463\r
464 return true;\r
06a19cee 465 }\r
466\r
a929458e 467 private HobsIdentification getCurrentHobs() {\r
468 String arg0 = this.jComboBoxGuidC_Name.getSelectedItem().toString();\r
469 String arg1 = this.jComboBoxHobType.getSelectedItem().toString();\r
470 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();\r
471\r
472 String arg3 = this.jTextFieldFeatureFlag.getText();\r
473 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();\r
474 String arg5 = this.jTextAreaHelpText.getText();\r
475 id = new HobsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r
476 return id;\r
06a19cee 477 }\r
478\r
a929458e 479 public HobsIdentification getId() {\r
480 return id;\r
06a19cee 481 }\r
5101eff9 482\r
a929458e 483 public void setId(HobsIdentification id) {\r
484 this.id = id;\r
485 }\r
06a19cee 486}\r