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