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