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