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