]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/SystemTablesDlg.java
Use table and popup window to add/edit all elements of module instead of original...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / SystemTablesDlg.java
1 /** @file
2
3 The file is used to create, update SystemTable of MSA/MBD file
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15 package org.tianocore.frameworkwizard.module.ui.dialog;
16
17 import java.awt.event.ActionEvent;
18 import java.util.Vector;
19
20 import javax.swing.JButton;
21 import javax.swing.JComboBox;
22 import javax.swing.JLabel;
23 import javax.swing.JPanel;
24 import javax.swing.JScrollPane;
25 import javax.swing.JTextField;
26
27 import org.tianocore.frameworkwizard.common.DataType;
28 import org.tianocore.frameworkwizard.common.DataValidation;
29 import org.tianocore.frameworkwizard.common.EnumerationData;
30 import org.tianocore.frameworkwizard.common.Log;
31 import org.tianocore.frameworkwizard.common.Tools;
32 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
33 import org.tianocore.frameworkwizard.common.ui.IDialog;
34 import org.tianocore.frameworkwizard.common.ui.IFrame;
35 import org.tianocore.frameworkwizard.common.ui.StarLabel;
36 import org.tianocore.frameworkwizard.module.Identifications.SystemTables.SystemTablesIdentification;
37 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
38
39 /**
40 The class is used to create, update SystemTable of MSA/MBD file
41 It extends IInternalFrame
42
43
44
45 **/
46 public class SystemTablesDlg extends IDialog {
47
48 ///
49 /// Define class Serial Version UID
50 ///
51 private static final long serialVersionUID = 7488769180379442276L;
52
53 //
54 //Define class members
55 //
56 private JPanel jContentPane = null;
57
58 private JLabel jLabelEntry = null;
59
60 private JLabel jLabelUsage = null;
61
62 private JComboBox jComboBoxUsage = null;
63
64 private StarLabel jStarLabel1 = null;
65
66 private StarLabel jStarLabel2 = null;
67
68 private JComboBox jComboBoxGuidC_Name = null;
69
70 private JLabel jLabelFeatureFlag = null;
71
72 private JTextField jTextFieldFeatureFlag = null;
73
74 private JLabel jLabelArch = null;
75
76 private JScrollPane jScrollPane = null;
77
78 private JLabel jLabelHelpText = null;
79
80 private JTextField jTextFieldHelpText = null;
81
82 private ArchCheckBox jArchCheckBox = null;
83
84 private JButton jButtonOk = null;
85
86 private JButton jButtonCancel = null;
87
88 //
89 // Not used by UI
90 //
91 private SystemTablesIdentification id = null;
92
93 private EnumerationData ed = new EnumerationData();
94
95 private WorkspaceTools wt = new WorkspaceTools();
96
97 /**
98 This method initializes jComboBoxUsage
99
100 @return javax.swing.JComboBox jComboBoxUsage
101
102 **/
103 private JComboBox getJComboBoxUsage() {
104 if (jComboBoxUsage == null) {
105 jComboBoxUsage = new JComboBox();
106 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
107 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
108 }
109 return jComboBoxUsage;
110 }
111
112 /**
113 This method initializes jTextField
114
115 @return javax.swing.JTextField jTextFieldC_Name
116
117 **/
118 private JComboBox getJComboBoxGuidC_Name() {
119 if (jComboBoxGuidC_Name == null) {
120 jComboBoxGuidC_Name = new JComboBox();
121 jComboBoxGuidC_Name.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
122 jComboBoxGuidC_Name.setPreferredSize(new java.awt.Dimension(320, 20));
123 jComboBoxGuidC_Name.setToolTipText("Select the GUID C Name of the Hob");
124 }
125 return jComboBoxGuidC_Name;
126 }
127
128 /**
129 * This method initializes jTextFieldFeatureFlag
130 *
131 * @return javax.swing.JTextField
132 */
133 private JTextField getJTextFieldFeatureFlag() {
134 if (jTextFieldFeatureFlag == null) {
135 jTextFieldFeatureFlag = new JTextField();
136 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
137 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
138 }
139 return jTextFieldFeatureFlag;
140 }
141
142 /**
143 This method initializes jScrollPane
144
145 @return javax.swing.JScrollPane
146 */
147 private JScrollPane getJScrollPane() {
148 if (jScrollPane == null) {
149 jScrollPane = new JScrollPane();
150 jScrollPane.setViewportView(getJContentPane());
151 }
152 return jScrollPane;
153 }
154
155 /**
156 This method initializes jTextFieldHelpText
157
158 @return javax.swing.JTextField
159
160 **/
161 private JTextField getJTextFieldHelpText() {
162 if (jTextFieldHelpText == null) {
163 jTextFieldHelpText = new JTextField();
164 jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
165 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));
166 }
167 return jTextFieldHelpText;
168 }
169
170 /**
171 This method initializes jButtonOk
172
173 @return javax.swing.JButton
174
175 **/
176 private JButton getJButtonOk() {
177 if (jButtonOk == null) {
178 jButtonOk = new JButton();
179 jButtonOk.setBounds(new java.awt.Rectangle(290, 140, 90, 20));
180 jButtonOk.setText("Ok");
181 jButtonOk.addActionListener(this);
182 }
183 return jButtonOk;
184 }
185
186 /**
187 This method initializes jButtonCancel
188
189 @return javax.swing.JButton
190
191 **/
192 private JButton getJButtonCancel() {
193 if (jButtonCancel == null) {
194 jButtonCancel = new JButton();
195 jButtonCancel.setBounds(new java.awt.Rectangle(390, 140, 90, 20));
196 jButtonCancel.setText("Cancel");
197 jButtonCancel.addActionListener(this);
198 }
199 return jButtonCancel;
200 }
201
202 public static void main(String[] args) {
203
204 }
205
206 /**
207 This method initializes this
208
209 **/
210 private void init() {
211 this.setSize(500, 200);
212 this.setContentPane(getJScrollPane());
213 this.setTitle("System Tables");
214 initFrame();
215 this.setViewMode(false);
216 this.centerWindow();
217 }
218
219 /**
220 This method initializes this
221 Fill values to all fields if these values are not empty
222
223 @param inSystemTablesId
224
225 **/
226 private void init(SystemTablesIdentification inSystemTablesId) {
227 init();
228 this.id = inSystemTablesId;
229
230 if (this.id != null) {
231 this.jComboBoxGuidC_Name.setSelectedItem(id.getName());
232 this.jComboBoxUsage.setSelectedItem(id.getUsage());
233 this.jTextFieldHelpText.setText(id.getHelp());
234 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
235 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
236 }
237 }
238
239 /**
240 This is the override edit constructor
241
242 @param inBootModesIdentification
243 @param iFrame
244
245 **/
246 public SystemTablesDlg(SystemTablesIdentification inSystemTablesIdentification, IFrame iFrame) {
247 super(iFrame, true);
248 init(inSystemTablesIdentification);
249 }
250
251 /**
252 Disable all components when the mode is view
253
254 @param isView true - The view mode; false - The non-view mode
255
256 **/
257 public void setViewMode(boolean isView) {
258 if (isView) {
259 this.jComboBoxUsage.setEnabled(!isView);
260 }
261 }
262
263 /**
264 This method initializes jContentPane
265
266 @return javax.swing.JPanel jContentPane
267
268 **/
269 private JPanel getJContentPane() {
270 if (jContentPane == null) {
271 jLabelArch = new JLabel();
272 jLabelArch.setBounds(new java.awt.Rectangle(15, 110, 140, 20));
273 jLabelArch.setText("Arch");
274 jArchCheckBox = new ArchCheckBox();
275 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
276 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
277 jLabelFeatureFlag = new JLabel();
278 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
279 jLabelFeatureFlag.setText("Feature Flag");
280 jLabelUsage = new JLabel();
281 jLabelUsage.setText("Usage");
282 jLabelUsage.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
283 jLabelEntry = new JLabel();
284 jLabelEntry.setText("Guid C_Name");
285 jLabelEntry.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
286 jLabelHelpText = new JLabel();
287 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 60, 140, 20));
288 jLabelHelpText.setText("Help Text");
289
290 jContentPane = new JPanel();
291 jContentPane.setLayout(null);
292 jContentPane.setPreferredSize(new java.awt.Dimension(490, 165));
293
294 jContentPane.add(jLabelEntry, null);
295 jContentPane.add(jLabelFeatureFlag, null);
296 jContentPane.add(getJTextFieldFeatureFlag(), null);
297 jContentPane.add(getJComboBoxGuidC_Name(), null);
298 jContentPane.add(jLabelArch, null);
299 jContentPane.add(jLabelUsage, null);
300 jContentPane.add(getJComboBoxUsage(), null);
301 jStarLabel1 = new StarLabel();
302 jStarLabel1.setBounds(new java.awt.Rectangle(0, 10, 10, 20));
303 jStarLabel2 = new StarLabel();
304 jStarLabel2.setBounds(new java.awt.Rectangle(0, 35, 10, 20));
305
306 jContentPane.add(jStarLabel1, null);
307 jContentPane.add(jStarLabel2, null);
308
309 jContentPane.add(jLabelHelpText, null);
310 jContentPane.add(getJTextFieldHelpText(), null);
311 jContentPane.add(jArchCheckBox, null);
312 jContentPane.add(getJButtonOk(), null);
313 jContentPane.add(getJButtonCancel(), null);
314 }
315 return jContentPane;
316 }
317
318 /**
319 This method initializes Usage type
320
321 **/
322 private void initFrame() {
323 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVSystemTableUsage());
324 Tools.generateComboBoxByVector(jComboBoxGuidC_Name, wt.getAllGuidDeclarationsFromWorkspace());
325 }
326
327 /* (non-Javadoc)
328 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
329 *
330 * Override actionPerformed to listen all actions
331 *
332 */
333 public void actionPerformed(ActionEvent arg0) {
334 if (arg0.getSource() == jButtonOk) {
335 if (checkAdd()) {
336 getCurrentSystemTables();
337 this.returnType = DataType.RETURN_TYPE_OK;
338 this.setVisible(false);
339 }
340 }
341
342 if (arg0.getSource() == jButtonCancel) {
343 this.returnType = DataType.RETURN_TYPE_CANCEL;
344 this.setVisible(false);
345 }
346 }
347
348 /**
349 Data validation for all fields
350
351 @retval true - All datas are valid
352 @retval false - At least one data is invalid
353
354 **/
355 public boolean checkAdd() {
356 //
357 // Check if all fields have correct data types
358 //
359
360 //
361 // Check FeatureFlag
362 //
363 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
364 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
365 Log.err("Incorrect data type for Feature Flag");
366 return false;
367 }
368 }
369
370 return true;
371 }
372
373 private SystemTablesIdentification getCurrentSystemTables() {
374 String arg0 = this.jComboBoxGuidC_Name.getSelectedItem().toString();
375 String arg1 = this.jComboBoxUsage.getSelectedItem().toString();
376
377 String arg2 = this.jTextFieldFeatureFlag.getText();
378 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
379 String arg4 = this.jTextFieldHelpText.getText();
380
381 id = new SystemTablesIdentification(arg0, arg1, arg2, arg3, arg4);
382 return id;
383 }
384
385 public SystemTablesIdentification getId() {
386 return id;
387 }
388
389 public void setId(SystemTablesIdentification id) {
390 this.id = id;
391 }
392 }