]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/ExternsDlg.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 / ExternsDlg.java
1 /** @file
2
3 The file is used to create, update Externs section of the MSA 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.awt.event.ItemEvent;
19 import java.awt.event.ItemListener;
20 import java.util.Vector;
21
22 import javax.swing.JButton;
23 import javax.swing.JComboBox;
24 import javax.swing.JLabel;
25 import javax.swing.JPanel;
26 import javax.swing.JScrollPane;
27 import javax.swing.JTextField;
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.module.Identifications.Externs.ExternsIdentification;
38
39 /**
40 * The class is used to create, update Externs section of the MSA file
41 *
42 * It extends IDialog
43 *
44 */
45 public class ExternsDlg extends IDialog implements ItemListener {
46
47 ///
48 /// Define class Serial Version UID
49 ///
50 private static final long serialVersionUID = -7382008402932047191L;
51
52 //
53 //Define class members
54 //
55 private JPanel jContentPane = null;
56
57 private JLabel jLabelName = null;
58
59 private JComboBox jComboBoxType = null;
60
61 private JScrollPane jScrollPane = null;
62
63 private JComboBox jComboBoxPcdIsDriver = null;
64
65 private JLabel jLabelC_Name = null;
66
67 private JTextField jTextFieldC_Name = null;
68
69 private JLabel jLabelFeatureFlag = null;
70
71 private JLabel jLabelArch = null;
72
73 private JTextField jTextFieldFeatureFlag = null;
74
75 private ArchCheckBox jArchCheckBox = null;
76
77 private JButton jButtonOk = null;
78
79 private JButton jButtonCancel = null;
80
81 //
82 // Not used by UI
83 //
84 private ExternsIdentification id = null;
85
86 private EnumerationData ed = new EnumerationData();
87
88 /**
89 This method initializes jComboBoxType
90
91 @return javax.swing.JComboBox jComboBoxType
92
93 **/
94 private JComboBox getJComboBoxType() {
95 if (jComboBoxType == null) {
96 jComboBoxType = new JComboBox();
97 jComboBoxType.setBounds(new java.awt.Rectangle(168, 12, 320, 20));
98 jComboBoxType.setPreferredSize(new java.awt.Dimension(320, 20));
99 jComboBoxType.addItemListener(this);
100 }
101 return jComboBoxType;
102 }
103
104 /**
105 This method initializes jScrollPane
106
107 @return javax.swing.JScrollPane
108 */
109 private JScrollPane getJScrollPane() {
110 if (jScrollPane == null) {
111 jScrollPane = new JScrollPane();
112 jScrollPane.setViewportView(getJContentPane());
113 }
114 return jScrollPane;
115 }
116
117 /**
118 * This method initializes jComboBoxPcdIsDriver
119 *
120 * @return javax.swing.JComboBox
121 */
122 private JComboBox getJComboBoxPcdIsDriver() {
123 if (jComboBoxPcdIsDriver == null) {
124 jComboBoxPcdIsDriver = new JComboBox();
125 jComboBoxPcdIsDriver.setLocation(new java.awt.Point(168, 37));
126 jComboBoxPcdIsDriver.setPreferredSize(new java.awt.Dimension(320, 20));
127 jComboBoxPcdIsDriver.setSize(new java.awt.Dimension(320, 20));
128 jComboBoxPcdIsDriver.addItemListener(this);
129 }
130 return jComboBoxPcdIsDriver;
131 }
132
133 /**
134 This method initializes jTextFieldC_Name
135
136 @return javax.swing.JTextField
137
138 **/
139 private JTextField getJTextFieldC_Name() {
140 if (jTextFieldC_Name == null) {
141 jTextFieldC_Name = new JTextField();
142 jTextFieldC_Name.setBounds(new java.awt.Rectangle(168, 37, 320, 20));
143 jTextFieldC_Name.setPreferredSize(new java.awt.Dimension(320, 20));
144 }
145 return jTextFieldC_Name;
146 }
147
148 /**
149 This method initializes jTextFieldFeatureFlag
150
151 @return javax.swing.JTextField
152
153 **/
154 private JTextField getJTextFieldFeatureFlag() {
155 if (jTextFieldFeatureFlag == null) {
156 jTextFieldFeatureFlag = new JTextField();
157 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(168, 62, 320, 20));
158 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
159 }
160 return jTextFieldFeatureFlag;
161 }
162
163 /**
164 This method initializes jButtonOk
165
166 @return javax.swing.JButton
167
168 **/
169 private JButton getJButtonOk() {
170 if (jButtonOk == null) {
171 jButtonOk = new JButton();
172 jButtonOk.setBounds(new java.awt.Rectangle(300, 122, 90, 20));
173 jButtonOk.setText("Ok");
174 jButtonOk.addActionListener(this);
175 }
176 return jButtonOk;
177 }
178
179 /**
180 This method initializes jButtonCancel
181
182 @return javax.swing.JButton
183
184 **/
185 private JButton getJButtonCancel() {
186 if (jButtonCancel == null) {
187 jButtonCancel = new JButton();
188 jButtonCancel.setBounds(new java.awt.Rectangle(400, 122, 90, 20));
189 jButtonCancel.setText("Cancel");
190 jButtonCancel.addActionListener(this);
191 }
192 return jButtonCancel;
193 }
194
195 public static void main(String[] args) {
196
197 }
198
199 /**
200 This method initializes this
201
202 **/
203 private void init() {
204 this.setSize(515, 200);
205 this.setContentPane(getJScrollPane());
206 this.setTitle("Externs");
207 initFrame();
208 this.centerWindow();
209 }
210
211 /**
212 This method initializes this
213 Fill values to all fields if these values are not empty
214
215 @param inExternsId
216
217 **/
218 private void init(ExternsIdentification inExternsId) {
219 init();
220 this.id = inExternsId;
221
222 if (this.id != null) {
223 if (id.getType().equals(EnumerationData.EXTERNS_PCD_IS_DRIVER)) {
224 this.jComboBoxPcdIsDriver.setSelectedItem(id.getName());
225 } else {
226 this.jTextFieldC_Name.setText(id.getName());
227 }
228 this.jComboBoxType.setSelectedItem(id.getType());
229 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
230 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
231 }
232 }
233
234 /**
235 This is the override edit constructor
236
237 @param inBootModesIdentification
238 @param iFrame
239
240 **/
241 public ExternsDlg(ExternsIdentification inExternsIdentification, IFrame iFrame) {
242 super(iFrame, true);
243 init(inExternsIdentification);
244 }
245
246 /**
247 This method initializes jContentPane
248
249 @return javax.swing.JPanel jContentPane
250
251 **/
252 private JPanel getJContentPane() {
253 if (jContentPane == null) {
254 jArchCheckBox = new ArchCheckBox();
255 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 87, 320, 20));
256 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
257 jLabelC_Name = new JLabel();
258 jLabelC_Name.setBounds(new java.awt.Rectangle(12, 37, 140, 20));
259 jLabelC_Name.setText("Enter Value");
260 jLabelName = new JLabel();
261 jLabelName.setText("Choose Extern Type");
262 jLabelName.setBounds(new java.awt.Rectangle(12, 12, 168, 20));
263 jLabelArch = new JLabel();
264 jLabelArch.setBounds(new java.awt.Rectangle(12, 87, 168, 20));
265 jLabelArch.setText("Supported Architectures");
266 jLabelFeatureFlag = new JLabel();
267 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 62, 168, 20));
268 jLabelFeatureFlag.setText("Feature Flag Expression");
269
270 jContentPane = new JPanel();
271 jContentPane.setLayout(null);
272 jContentPane.setPreferredSize(new java.awt.Dimension(505, 155));
273
274 jContentPane.add(jLabelName, null);
275 jContentPane.add(getJComboBoxType(), null);
276 jContentPane.add(jLabelFeatureFlag, null);
277 jContentPane.add(jLabelArch, null);
278 jContentPane.add(getJTextFieldFeatureFlag(), null);
279
280 jContentPane.add(getJComboBoxPcdIsDriver(), null);
281 jContentPane.add(jLabelC_Name, null);
282 jContentPane.add(getJTextFieldC_Name(), null);
283 jContentPane.add(jArchCheckBox, null);
284 jContentPane.add(getJButtonOk(), null);
285 jContentPane.add(getJButtonCancel(), null);
286 }
287 return jContentPane;
288 }
289
290 /**
291 This method initializes Usage type and Externs type
292
293 **/
294 private void initFrame() {
295 Tools.generateComboBoxByVector(this.jComboBoxType, ed.getVExternTypes());
296 Tools.generateComboBoxByVector(this.jComboBoxPcdIsDriver, ed.getVPcdDriverTypes());
297 }
298
299 /* (non-Javadoc)
300 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
301 *
302 * Override actionPerformed to listen all actions
303 *
304 */
305 public void actionPerformed(ActionEvent arg0) {
306 if (arg0.getSource() == jButtonOk) {
307 if (checkAdd()) {
308 getCurrentExterns();
309 this.returnType = DataType.RETURN_TYPE_OK;
310 this.setVisible(false);
311 }
312 }
313
314 if (arg0.getSource() == jButtonCancel) {
315 this.returnType = DataType.RETURN_TYPE_CANCEL;
316 this.setVisible(false);
317 }
318 }
319
320 /**
321 Data validation for all fields
322
323 @retval true - All datas are valid
324 @retval false - At least one data is invalid
325
326 **/
327 public boolean checkAdd() {
328 //
329 // Check if all fields have correct data types
330 //
331
332 //
333 // When and only When type is not "Pcd Is Driver"
334 //
335 if (!this.jComboBoxType.getSelectedItem().toString().equals(EnumerationData.EXTERNS_PCD_IS_DRIVER)) {
336 //
337 // Check CName
338 //
339 if (isEmpty(this.jTextFieldC_Name.getText())) {
340 Log.wrn("Update Externs", "Value couldn't be empty");
341 return false;
342 }
343
344 if (!isEmpty(this.jTextFieldC_Name.getText())) {
345 if (this.jComboBoxType.getSelectedItem().toString().equals(EnumerationData.EXTERNS_SPECIFICATION)) {
346 if (!DataValidation.isSentence(this.jTextFieldC_Name.getText())) {
347 Log.wrn("Update Externs", "Incorrect data type for Specification");
348 return false;
349 }
350 } else {
351 if (!DataValidation.isC_NameType(this.jTextFieldC_Name.getText())) {
352 Log.wrn("Update Externs", "Incorrect data type for C Name");
353 return false;
354 }
355 }
356 }
357
358 //
359 // Check FeatureFlag
360 //
361 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
362 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
363 Log.wrn("Update Externs", "Incorrect data type for Feature Flag");
364 return false;
365 }
366 }
367 } else {
368 if (this.jComboBoxPcdIsDriver.getSelectedItem().toString().equals(DataType.EMPTY_SELECT_ITEM)) {
369 Log.wrn("Update Externs", "You must select one PCD DRIVER type");
370 return false;
371 }
372 }
373
374 return true;
375 }
376
377 private ExternsIdentification getCurrentExterns() {
378 String arg0 = "";
379 if (this.jComboBoxType.getSelectedItem().toString().equals(EnumerationData.EXTERNS_PCD_IS_DRIVER)) {
380 arg0 = this.jComboBoxPcdIsDriver.getSelectedItem().toString();
381 } else {
382 arg0 = this.jTextFieldC_Name.getText();
383 }
384 String arg1 = this.jComboBoxType.getSelectedItem().toString();
385
386 String arg2 = this.jTextFieldFeatureFlag.getText();
387 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
388
389 id = new ExternsIdentification(arg0, arg1, arg2, arg3);
390 return id;
391 }
392
393 /* (non-Javadoc)
394 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
395 *
396 * Reflesh the frame when selected item changed
397 *
398 */
399 public void itemStateChanged(ItemEvent arg0) {
400 if (arg0.getSource() == jComboBoxType && arg0.getStateChange() == ItemEvent.SELECTED) {
401 if (jComboBoxType.getSelectedItem().toString().equals(EnumerationData.EXTERNS_PCD_IS_DRIVER)) {
402 this.jComboBoxPcdIsDriver.setVisible(true);
403 this.jTextFieldC_Name.setVisible(false);
404 } else {
405 this.jComboBoxPcdIsDriver.setVisible(false);
406 this.jTextFieldC_Name.setVisible(true);
407 }
408 }
409 }
410
411 public ExternsIdentification getId() {
412 return id;
413 }
414
415 public void setId(ExternsIdentification id) {
416 this.id = id;
417 }
418 }