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