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