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