]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/GuidsDlg.java
remove unnecessary check for NULL pointer.
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / GuidsDlg.java
1 /** @file
2 <<The file is used to create, update Guids of the MSA file>>
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14 package org.tianocore.frameworkwizard.module.ui.dialog;
15
16 import java.awt.event.ActionEvent;
17 import java.util.Vector;
18
19 import javax.swing.JButton;
20 import javax.swing.JComboBox;
21 import javax.swing.JLabel;
22 import javax.swing.JPanel;
23 import javax.swing.JScrollPane;
24 import javax.swing.JTextField;
25 import javax.swing.JTextArea;
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.IComboBox;
34 import org.tianocore.frameworkwizard.common.ui.IDialog;
35 import org.tianocore.frameworkwizard.common.ui.IFrame;
36 import org.tianocore.frameworkwizard.common.ui.StarLabel;
37 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
38 import org.tianocore.frameworkwizard.module.Identifications.Guids.GuidsIdentification;
39 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
40 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
41
42 /**
43 * The class is used to create, update Guids of the MSA file
44 *
45 * It extends IDialog
46 *
47 */
48 public class GuidsDlg extends IDialog {
49
50 // /
51 // / Define class Serial Version UID
52 // /
53 private static final long serialVersionUID = 6710858997766979803L;
54
55 //
56 // Define class members
57 //
58 private JPanel jContentPane = null;
59
60 private JLabel jLabelC_Name = null;
61
62 private IComboBox iComboBoxCName = null;
63
64 private JLabel jLabelUsage = null;
65
66 private JComboBox jComboBoxUsage = null;
67
68 private StarLabel jStarLabel1 = null;
69
70 private StarLabel jStarLabel2 = 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 GuidsIdentification id = null;
96
97 private EnumerationData ed = new EnumerationData();
98
99 private WorkspaceTools wt = new WorkspaceTools();
100
101 /**
102 * This method initializes jTextFieldC_Name
103 *
104 * @return javax.swing.JTextField jTextFieldC_Name
105 *
106 */
107 private IComboBox getIComboBoxCName() {
108 if (iComboBoxCName == null) {
109 iComboBoxCName = new IComboBox();
110 iComboBoxCName.setBounds(new java.awt.Rectangle(168, 12, 320, 20));
111 iComboBoxCName.setPreferredSize(new java.awt.Dimension(320, 20));
112 iComboBoxCName.setToolTipText("Select the C Name of the GUID");
113 }
114 return iComboBoxCName;
115 }
116
117 /**
118 * This method initializes jComboBoxUsage
119 *
120 * @return javax.swing.JComboBox jComboBoxUsage
121 *
122 */
123 private JComboBox getJComboBoxUsage() {
124 if (jComboBoxUsage == null) {
125 jComboBoxUsage = new JComboBox();
126 jComboBoxUsage.setBounds(new java.awt.Rectangle(168, 37, 320, 20));
127 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
128 jComboBoxUsage
129 .setToolTipText("<html><table>"
130 + "<tr><td>ALWAYS_CONSUMED</td><td>Module always consumes the GUID</td></tr>"
131 + "<tr><td>SOMETIMES_CONSUMED</td><td>Module will use the GUID only if it is present</td></tr>"
132 + "<tr><td>ALWAYS_PRODUCED</td><td>Module always produces the GUID</td></tr>"
133 + "<tr><td>SOMETIMES_PRODUCED</td><td>Module will sometimes produce the GUID</td></tr>"
134 + "<tr><td>DEFAULT</td><td>Default is the the GUID that specified the<br>instance of the package</td></tr>"
135 + "</table></html>");
136 }
137 return jComboBoxUsage;
138 }
139
140 /**
141 * This method initializes jTextFieldFeatureFlag
142 *
143 * @return javax.swing.JTextField
144 *
145 */
146 private JTextField getJTextFieldFeatureFlag() {
147 if (jTextFieldFeatureFlag == null) {
148 jTextFieldFeatureFlag = new JTextField();
149 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(168, 132, 320, 20));
150 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
151 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
152 jTextFieldFeatureFlag.setEnabled(false);
153 }
154 return jTextFieldFeatureFlag;
155 }
156
157 /**
158 * This method initializes jScrollPane
159 *
160 * @return javax.swing.JScrollPane
161 */
162 private JScrollPane getJScrollPane() {
163 if (jScrollPane == null) {
164 jScrollPane = new JScrollPane();
165 jScrollPane.setViewportView(getJContentPane());
166 }
167 return jScrollPane;
168 }
169
170 /**
171 * This method initializes jTextAreaHelpText
172 *
173 * @return javax.swing.JTextArea
174 *
175 */
176 private JTextArea getJTextAreaHelpText() {
177 if (jTextAreaHelpText == null) {
178 jTextAreaHelpText = new JTextArea();
179 jTextAreaHelpText.setLineWrap(true);
180 jTextAreaHelpText.setWrapStyleWord(true);
181 }
182 return jTextAreaHelpText;
183 }
184
185 /**
186 *
187 * This method initializes jScrollPaneHelpText
188 *
189 * @return javax.swing.JScrollPane jScrollPaneHelpText
190 *
191 **/
192 private JScrollPane getJScrollPaneHelpText() {
193 if (jScrollPaneHelpText == null) {
194 jScrollPaneHelpText = new JScrollPane();
195 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
196 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));
197 jScrollPaneHelpText.setLocation(new java.awt.Point(168, 62));
198 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
199 }
200 return jScrollPaneHelpText;
201 }
202
203 /**
204 * This method initializes jButtonOk
205 *
206 * @return javax.swing.JButton
207 *
208 */
209 private JButton getJButtonOk() {
210 if (jButtonOk == null) {
211 jButtonOk = new JButton();
212 jButtonOk.setBounds(new java.awt.Rectangle(290, 162, 90, 20));
213 jButtonOk.setText("Ok");
214 jButtonOk.addActionListener(this);
215 }
216 return jButtonOk;
217 }
218
219 /**
220 * This method initializes jButtonCancel
221 *
222 * @return javax.swing.JButton
223 *
224 */
225 private JButton getJButtonCancel() {
226 if (jButtonCancel == null) {
227 jButtonCancel = new JButton();
228 jButtonCancel.setBounds(new java.awt.Rectangle(390, 162, 90, 20));
229 jButtonCancel.setText("Cancel");
230 jButtonCancel.addActionListener(this);
231 }
232 return jButtonCancel;
233 }
234
235 public static void main(String[] args) {
236
237 }
238
239 /**
240 *
241 * This method initializes this
242 *
243 */
244 private void init() {
245 this.setSize(505, 235);
246 this.setContentPane(getJScrollPane());
247 this.setTitle("Guids");
248 initFrame();
249 this.setViewMode(false);
250 this.centerWindow();
251 }
252
253 /**
254 *
255 * This method initializes this Fill values to all fields if these values are
256 * not empty
257 *
258 * @param inGuidsId
259 *
260 */
261 private void init(GuidsIdentification inGuidsId, ModuleIdentification mid) {
262 init();
263 this.id = inGuidsId;
264
265 //
266 // Init arch with module's arch
267 //
268 this.jArchCheckBox.setEnabledItems(wt.getModuleArch(mid));
269
270 //
271 // Get defined guids from dependent packages
272 //
273 Vector<PackageIdentification> vpid = wt.getPackageDependenciesOfModule(mid);
274 if (vpid.size() <= 0) {
275 Log.wrn("Init Guid", "This module hasn't defined any package dependency, so there is no guid can be added");
276 }
277
278 Tools.generateComboBoxByVector(this.iComboBoxCName,
279 wt.getAllGuidDeclarationsFromPackages(wt.getPackageDependenciesOfModule(mid),
280 EnumerationData.GUID_TYPE_GUID));
281
282
283 if (this.id != null) {
284 this.iComboBoxCName.setSelectedItem(id.getName());
285 this.jComboBoxUsage.setSelectedItem(id.getUsage());
286 this.jTextAreaHelpText.setText(id.getHelp());
287 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
288 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
289 }
290 }
291
292 /**
293 * This is the override edit constructor
294 *
295 * @param inGuidsIdentification
296 * @param iFrame
297 *
298 */
299 public GuidsDlg(GuidsIdentification inGuidsIdentification, IFrame iFrame, ModuleIdentification mid) {
300 super(iFrame, true);
301 init(inGuidsIdentification, mid);
302 }
303
304 /**
305 * Disable all components when the mode is view
306 *
307 * @param isView
308 * true - The view mode; false - The non-view mode
309 *
310 */
311 public void setViewMode(boolean isView) {
312 if (isView) {
313 this.jComboBoxUsage.setEnabled(!isView);
314 }
315 }
316
317 /**
318 * This method initializes jContentPane
319 *
320 * @return javax.swing.JPanel jContentPane
321 *
322 */
323 private JPanel getJContentPane() {
324 if (jContentPane == null) {
325 jStarLabel1 = new StarLabel();
326 jStarLabel1.setLocation(new java.awt.Point(2, 12));
327 jLabelC_Name = new JLabel();
328 jLabelC_Name.setText("Select GUID's C Name");
329 jLabelC_Name.setBounds(new java.awt.Rectangle(12, 12, 155, 20));
330
331 jStarLabel2 = new StarLabel();
332 jStarLabel2.setLocation(new java.awt.Point(2, 37));
333 jLabelUsage = new JLabel();
334 jLabelUsage.setText("Usage");
335 jLabelUsage.setBounds(new java.awt.Rectangle(12, 37, 155, 20));
336
337 jLabelHelpText = new JLabel();
338 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 62, 155, 20));
339 jLabelHelpText.setText("Help Text");
340
341 jLabelFeatureFlag = new JLabel();
342 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 132, 155, 20));
343 jLabelFeatureFlag.setText("Feature Flag Expression");
344 jLabelFeatureFlag.setEnabled(false);
345
346 jLabelArch = new JLabel();
347 jLabelArch.setBounds(new java.awt.Rectangle(12, 107, 155, 20));
348 jLabelArch.setText("Supported Architectures");
349 jArchCheckBox = new ArchCheckBox();
350 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 107, 320, 20));
351 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
352
353 jContentPane = new JPanel();
354 jContentPane.setLayout(null);
355 jContentPane.setPreferredSize(new java.awt.Dimension(480, 180));
356
357 jContentPane.add(jStarLabel1, null);
358 jContentPane.add(jLabelC_Name, null);
359 jContentPane.add(getIComboBoxCName(), null);
360 jContentPane.add(jStarLabel2, null);
361 jContentPane.add(jLabelUsage, null);
362 jContentPane.add(getJComboBoxUsage(), null);
363 jContentPane.add(jLabelHelpText, null);
364 jContentPane.add(getJScrollPaneHelpText(), null);
365 jContentPane.add(jLabelFeatureFlag, null);
366 jContentPane.add(getJTextFieldFeatureFlag(), null);
367 jContentPane.add(jLabelArch, null);
368 jContentPane.add(jArchCheckBox, null);
369 jContentPane.add(getJButtonOk(), null);
370 jContentPane.add(getJButtonCancel(), null);
371 }
372 return jContentPane;
373 }
374
375 /**
376 * This method initializes Usage type
377 *
378 */
379 private void initFrame() {
380 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVGuidUsage());
381 }
382
383 /*
384 * (non-Javadoc)
385 *
386 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
387 *
388 * Override actionPerformed to listen all actions
389 *
390 */
391 public void actionPerformed(ActionEvent arg0) {
392 if (arg0.getSource() == jButtonOk) {
393 if (checkAdd()) {
394 getCurrentGuids();
395 this.returnType = DataType.RETURN_TYPE_OK;
396 this.setVisible(false);
397 }
398 }
399
400 if (arg0.getSource() == jButtonCancel) {
401 this.returnType = DataType.RETURN_TYPE_CANCEL;
402 this.setVisible(false);
403 }
404 }
405
406 /**
407 * Data validation for all fields
408 *
409 * @retval true - All datas are valid
410 * @retval false - At least one data is invalid
411 *
412 */
413 public boolean checkAdd() {
414 //
415 // Check if all fields have correct data types
416 //
417
418 //
419 // Check Name
420 //
421 if (this.iComboBoxCName.getSelectedItem() == null) {
422 Log.wrn("Update Guids", "Please select one Guid Name");
423 return false;
424 }
425
426 if (!isEmpty(this.iComboBoxCName.getSelectedItem().toString())) {
427 if (!DataValidation.isC_NameType(this.iComboBoxCName.getSelectedItem().toString())) {
428 Log.wrn("Update Guids", "Incorrect data type for Guid Name");
429 return false;
430 }
431 }
432
433 //
434 // Check FeatureFlag
435 //
436 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
437 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
438 Log.wrn("Update Guids", "Incorrect data type for Feature Flag");
439 return false;
440 }
441 }
442
443 return true;
444 }
445
446 private GuidsIdentification getCurrentGuids() {
447 String arg0 = this.iComboBoxCName.getSelectedItem().toString();
448 String arg1 = this.jComboBoxUsage.getSelectedItem().toString();
449
450 String arg2 = this.jTextFieldFeatureFlag.getText();
451 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
452 String arg4 = this.jTextAreaHelpText.getText();
453
454 id = new GuidsIdentification(arg0, arg1, arg2, arg3, arg4);
455 return id;
456 }
457
458 public GuidsIdentification getId() {
459 return id;
460 }
461
462 public void setId(GuidsIdentification id) {
463 this.id = id;
464 }
465 }