]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/ProtocolsDlg.java
remove unnecessary check for NULL pointer.
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / ProtocolsDlg.java
1 /** @file
2
3 The file is used to create, update Protocol of 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
16 package org.tianocore.frameworkwizard.module.ui.dialog;
17
18 import java.awt.event.ActionEvent;
19 import java.awt.event.ItemEvent;
20 import java.awt.event.ItemListener;
21 import java.util.Vector;
22
23 import javax.swing.JButton;
24 import javax.swing.JComboBox;
25 import javax.swing.JLabel;
26 import javax.swing.JPanel;
27 import javax.swing.JScrollPane;
28 import javax.swing.JTextField;
29 import javax.swing.JTextArea;
30
31 import org.tianocore.frameworkwizard.common.DataType;
32 import org.tianocore.frameworkwizard.common.DataValidation;
33 import org.tianocore.frameworkwizard.common.EnumerationData;
34 import org.tianocore.frameworkwizard.common.Log;
35 import org.tianocore.frameworkwizard.common.Tools;
36 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
37 import org.tianocore.frameworkwizard.common.ui.IComboBox;
38 import org.tianocore.frameworkwizard.common.ui.IDialog;
39 import org.tianocore.frameworkwizard.common.ui.IFrame;
40 import org.tianocore.frameworkwizard.common.ui.StarLabel;
41 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
42 import org.tianocore.frameworkwizard.module.Identifications.Protocols.ProtocolsIdentification;
43 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
44 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
45
46 /**
47 * The class is used to create, update Protocol of MSA file
48 *
49 * It extends IDialog
50 *
51 */
52 public class ProtocolsDlg extends IDialog implements ItemListener {
53
54 // /
55 // / Define class Serial Version UID
56 // /
57 private static final long serialVersionUID = -9084913640747858848L;
58
59 //
60 // Define class members
61 //
62 private JPanel jContentPane = null;
63
64 private JLabel jLabelC_Name = null;
65
66 private JLabel jLabelFeatureFlag = null;
67
68 private JTextField jTextFieldFeatureFlag = null;
69
70 private JLabel jLabelUsage = null;
71
72 private JComboBox jComboBoxUsage = null;
73
74 private StarLabel jStarLabel1 = null;
75
76 private StarLabel jStarLabel2 = null;
77
78 private StarLabel jStarLabel3 = null;
79
80 private JLabel jLabelProtocolType = null;
81
82 private JLabel jLabelArch = null;
83
84 private JScrollPane jScrollPane = null;
85
86 private JComboBox jComboBoxProtocolType = null;
87
88 private IComboBox iComboBoxCName = null;
89
90 private JLabel jLabelHelpText = null;
91
92 private JTextArea jTextAreaHelpText = null;
93
94 private JScrollPane jScrollPaneHelpText = null;
95
96 private ArchCheckBox jArchCheckBox = null;
97
98 private JButton jButtonOk = null;
99
100 private JButton jButtonCancel = null;
101
102 //
103 // Not used by UI
104 //
105 private ProtocolsIdentification id = null;
106
107 private WorkspaceTools wt = new WorkspaceTools();
108
109 private EnumerationData ed = new EnumerationData();
110
111 /**
112 * This method initializes jTextFieldFeatureFlag
113 *
114 * @return javax.swing.JTextField jTextFieldFeatureFlag
115 *
116 */
117 private JTextField getJTextFieldFeatureFlag() {
118 if (jTextFieldFeatureFlag == null) {
119 jTextFieldFeatureFlag = new JTextField();
120 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(168, 157, 320, 20));
121 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
122 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
123 jTextFieldFeatureFlag.setEnabled(false);
124 }
125 return jTextFieldFeatureFlag;
126 }
127
128 /**
129 * This method initializes jComboBoxUsage
130 *
131 * @return javax.swing.JComboBox jComboBoxUsage
132 *
133 */
134 private JComboBox getJComboBoxProtocolUsage() {
135 if (jComboBoxUsage == null) {
136 jComboBoxUsage = new JComboBox();
137 jComboBoxUsage.setBounds(new java.awt.Rectangle(168, 62, 320, 20));
138 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
139 jComboBoxUsage
140 .setToolTipText("<html><table><tr><td colspan=2 align=center><b>Protocol</b></td></tr>"
141 + "<tr><td>ALWAYS_CONSUMED</td><td>Module always consumes the protocol</td></tr>"
142 + "<tr><td>SOMETIMES_CONSUMES</td><td>Module sometimes consumes the protocol</td></tr>"
143 + "<tr><td>ALWAYS_PRODUCED</td><td>Module always produces the protocol</td></tr>"
144 + "<tr><td>SOMETIMES_PRODUCED</td><td>Module sometimes produces the protocol</td></tr>"
145 + "<tr><td>TO_START</td><td>The protocol is consumed by a Driver Binding protocol <b>Start</b><br>function. The protocol is used in EFI 1.10 driver model</td></tr>"
146 + "<tr><td>BY_START</td><td>Protocol is produced by a Driver Binding protocol <b>Start</b><br>function. The protocol is used in EFI 1.10 driver model</td></tr>"
147 + "<tr><td colspan=2 align=center><b>Protocol Notify</b></td></tr>"
148 + "<tr><td>SOMETIMES_CONSUMED</td><td>Module will consume the protocol if it is produced.<br>Consumption is defined by executing the protocol notify<br>function.</td></tr></table></html>");
149 }
150 return jComboBoxUsage;
151 }
152
153 /**
154 * This method initializes jScrollPane
155 *
156 * @return javax.swing.JScrollPane
157 */
158 private JScrollPane getJScrollPane() {
159 if (jScrollPane == null) {
160 jScrollPane = new JScrollPane();
161 jScrollPane.setViewportView(getJContentPane());
162 }
163 return jScrollPane;
164 }
165
166 /**
167 * This method initializes jComboBoxProtocolType
168 *
169 * @return javax.swing.JComboBox
170 */
171 private JComboBox getJComboBoxProtocolType() {
172 if (jComboBoxProtocolType == null) {
173 jComboBoxProtocolType = new JComboBox();
174 jComboBoxProtocolType.setBounds(new java.awt.Rectangle(168, 12, 320, 20));
175 jComboBoxProtocolType.setPreferredSize(new java.awt.Dimension(320, 20));
176 jComboBoxProtocolType.addItemListener(this);
177 jComboBoxProtocolType
178 .setToolTipText("<html>Select Protocol Type<br>Protocol Notify is a register protocol notify mechanism.");
179 }
180 return jComboBoxProtocolType;
181 }
182
183 /**
184 * This method initializes iComboBoxCName
185 *
186 * @return javax.swing.JComboBox
187 */
188 private IComboBox getIComboBoxCName() {
189 if (iComboBoxCName == null) {
190 iComboBoxCName = new IComboBox();
191 iComboBoxCName.setBounds(new java.awt.Rectangle(168, 37, 320, 20));
192 iComboBoxCName.setPreferredSize(new java.awt.Dimension(320, 20));
193 iComboBoxCName.setToolTipText("Select Guid C Name of the Protocol");
194
195 }
196 return iComboBoxCName;
197 }
198
199 /**
200 * This method initializes jTextAreaHelpText
201 *
202 * @return javax.swing.JTextArea
203 *
204 */
205 private JTextArea getJTextAreaHelpText() {
206 if (jTextAreaHelpText == null) {
207 jTextAreaHelpText = new JTextArea();
208 jTextAreaHelpText.setLineWrap(true);
209 jTextAreaHelpText.setWrapStyleWord(true);
210 }
211 return jTextAreaHelpText;
212 }
213
214 /**
215 * This method initializes jScrollPaneHelpText
216 *
217 * @return javax.swing.JScrollPane
218 *
219 */
220 private JScrollPane getJScrollPaneHelpText() {
221 if (jScrollPaneHelpText == null) {
222 jScrollPaneHelpText = new JScrollPane();
223 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
224 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));
225 jScrollPaneHelpText.setPreferredSize(new java.awt.Dimension(320, 40));
226 jScrollPaneHelpText.setLocation(new java.awt.Point(168, 87));
227 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
228 }
229 return jScrollPaneHelpText;
230 }
231
232 /**
233 * This method initializes jButtonOk
234 *
235 * @return javax.swing.JButton
236 *
237 */
238 private JButton getJButtonOk() {
239 if (jButtonOk == null) {
240 jButtonOk = new JButton();
241 jButtonOk.setBounds(new java.awt.Rectangle(290, 187, 90, 20));
242 jButtonOk.setText("Ok");
243 jButtonOk.addActionListener(this);
244 }
245 return jButtonOk;
246 }
247
248 /**
249 * This method initializes jButtonCancel
250 *
251 * @return javax.swing.JButton
252 *
253 */
254 private JButton getJButtonCancel() {
255 if (jButtonCancel == null) {
256 jButtonCancel = new JButton();
257 jButtonCancel.setBounds(new java.awt.Rectangle(390, 187, 90, 20));
258 jButtonCancel.setText("Cancel");
259 jButtonCancel.addActionListener(this);
260 }
261 return jButtonCancel;
262 }
263
264 public static void main(String[] args) {
265
266 }
267
268 /**
269 * This method initializes this
270 *
271 */
272 private void init() {
273 // Width must be 20 larger than Content Pane PreferredSize width for MSFT
274 // Height must be 45 larger than ContentPane PreferredSize height for MSFT
275 this.setSize(505, 260);
276 this.setContentPane(getJScrollPane());
277 this.setTitle("Protocols");
278 initFrame();
279 this.setViewMode(false);
280 this.centerWindow();
281 }
282
283 /**
284 * This method initializes this Fill values to all fields if these values are
285 * not empty
286 *
287 * @param inProtocolsId
288 *
289 */
290 private void init(ProtocolsIdentification inProtocolsId, ModuleIdentification mid) {
291 init();
292 this.id = inProtocolsId;
293
294 //
295 // Init arch with module's arch
296 //
297 this.jArchCheckBox.setEnabledItems(wt.getModuleArch(mid));
298
299 //
300 // Get defined protocols from dependent packages
301 //
302 Vector<PackageIdentification> vpid = wt.getPackageDependenciesOfModule(mid);
303 if (vpid.size() <= 0) {
304 Log.wrn("Init Protocol", "This module hasn't defined any package dependency, so there is no protocol can be added");
305 }
306
307 Tools.generateComboBoxByVector(this.iComboBoxCName,
308 wt.getAllProtocolDeclarationsFromPackages(wt.getPackageDependenciesOfModule(mid)));
309
310 if (this.id != null) {
311 this.iComboBoxCName.setSelectedItem(id.getName());
312 this.jComboBoxProtocolType.setSelectedItem(id.getType());
313 this.jComboBoxUsage.setSelectedItem(id.getUsage());
314 this.jTextAreaHelpText.setText(id.getHelp());
315 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
316 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
317 }
318 }
319
320 /**
321 * This is the override edit constructor
322 *
323 * @param inProtocolsIdentification
324 * @param iFrame
325 *
326 */
327 public ProtocolsDlg(ProtocolsIdentification inProtocolsIdentification, IFrame iFrame, ModuleIdentification mid) {
328 super(iFrame, true);
329 init(inProtocolsIdentification, mid);
330 }
331
332 /**
333 * Disable all components when the mode is view
334 *
335 * @param isView
336 * true - The view mode; false - The non-view mode
337 *
338 */
339 public void setViewMode(boolean isView) {
340 if (isView) {
341 this.jComboBoxUsage.setEnabled(!isView);
342 this.jTextFieldFeatureFlag.setEnabled(!isView);
343 }
344 }
345
346 /**
347 * This method initializes jContentPane
348 *
349 * @return javax.swing.JPanel jContentPane
350 *
351 */
352 private JPanel getJContentPane() {
353 if (jContentPane == null) {
354 jStarLabel1 = new StarLabel();
355 jStarLabel1.setLocation(new java.awt.Point(2, 12));
356 jLabelProtocolType = new JLabel();
357 jLabelProtocolType.setBounds(new java.awt.Rectangle(12, 12, 155, 20));
358 jLabelProtocolType.setText("Select Protocol Type");
359
360 jStarLabel2 = new StarLabel();
361 jStarLabel2.setLocation(new java.awt.Point(2, 37));
362 jLabelC_Name = new JLabel();
363 jLabelC_Name.setText("Protocol Guid C Name");
364 jLabelC_Name.setBounds(new java.awt.Rectangle(12, 37, 155, 20));
365
366 jStarLabel3 = new StarLabel();
367 jStarLabel3.setLocation(new java.awt.Point(2, 62));
368 jLabelUsage = new JLabel();
369 jLabelUsage.setText("Usage");
370 jLabelUsage.setBounds(new java.awt.Rectangle(12, 62, 155, 20));
371
372 jLabelHelpText = new JLabel();
373 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 87, 155, 20));
374 jLabelHelpText.setText("Help Text");
375
376 jLabelFeatureFlag = new JLabel();
377 jLabelFeatureFlag.setText("Feature Flag Expression");
378 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 157, 155, 20));
379 jLabelFeatureFlag.setEnabled(false);
380
381 jLabelArch = new JLabel();
382 jLabelArch.setBounds(new java.awt.Rectangle(12, 132, 155, 20));
383 jLabelArch.setText("Supported Architectures");
384 jArchCheckBox = new ArchCheckBox();
385 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 132, 320, 20));
386 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
387
388 jContentPane = new JPanel();
389 jContentPane.setLayout(null);
390 jContentPane.setPreferredSize(new java.awt.Dimension(485, 215));
391
392 jContentPane.add(jStarLabel1, null);
393 jContentPane.add(jLabelProtocolType, null);
394 jContentPane.add(getJComboBoxProtocolType(), null);
395 jContentPane.add(jStarLabel2, null);
396 jContentPane.add(jLabelC_Name, null);
397 jContentPane.add(getIComboBoxCName(), null);
398 jContentPane.add(jStarLabel3, null);
399 jContentPane.add(jLabelUsage, null);
400 jContentPane.add(getJComboBoxProtocolUsage(), null);
401 jContentPane.add(jLabelHelpText, null);
402 jContentPane.add(getJScrollPaneHelpText(), null);
403 jContentPane.add(jLabelFeatureFlag, null);
404 jContentPane.add(getJTextFieldFeatureFlag(), null);
405 jContentPane.add(jLabelArch, null);
406 jContentPane.add(jArchCheckBox, null);
407 jContentPane.add(getJButtonOk(), null);
408 jContentPane.add(getJButtonCancel(), null);
409 }
410 return jContentPane;
411 }
412
413 /**
414 * This method initializes Usage type
415 *
416 */
417 private void initFrame() {
418 Tools.generateComboBoxByVector(jComboBoxProtocolType, ed.getVProtocolType());
419 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVProtocolUsage());
420 }
421
422 /*
423 * (non-Javadoc)
424 *
425 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
426 *
427 * Override actionPerformed to listen all actions
428 *
429 */
430 public void actionPerformed(ActionEvent arg0) {
431 if (arg0.getSource() == jButtonOk) {
432 if (checkAdd()) {
433 getCurrentProtocols();
434 this.returnType = DataType.RETURN_TYPE_OK;
435 this.setVisible(false);
436 }
437 }
438
439 if (arg0.getSource() == jButtonCancel) {
440 this.returnType = DataType.RETURN_TYPE_CANCEL;
441 this.setVisible(false);
442 }
443 }
444
445 /**
446 * Data validation for all fields
447 *
448 * @retval true - All datas are valid
449 * @retval false - At least one data is invalid
450 *
451 */
452 public boolean checkAdd() {
453 //
454 // Check if all fields have correct data types
455 //
456
457 //
458 // Check Name
459 //
460 if (this.iComboBoxCName.getSelectedItem() == null) {
461 Log.wrn("Update protocols", "Please select one Protocol/ProtocolNotify Name");
462 return false;
463 }
464
465 if (!isEmpty(this.iComboBoxCName.getSelectedItem().toString())) {
466 if (!DataValidation.isC_NameType(this.iComboBoxCName.getSelectedItem().toString())) {
467 Log.wrn("Update Protocols", "Incorrect data type for Protocol/ProtocolNotify Name");
468 return false;
469 }
470 }
471
472 //
473 // Check FeatureFlag
474 //
475 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
476 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
477 Log.wrn("Update Protocols", "Incorrect data type for Feature Flag");
478 return false;
479 }
480 }
481
482 return true;
483 }
484
485 private ProtocolsIdentification getCurrentProtocols() {
486 String arg0 = this.iComboBoxCName.getSelectedItem().toString();
487 String arg1 = this.jComboBoxProtocolType.getSelectedItem().toString();
488 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();
489
490 String arg3 = this.jTextFieldFeatureFlag.getText();
491 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
492 String arg5 = this.jTextAreaHelpText.getText();
493 id = new ProtocolsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
494 return id;
495 }
496
497 /*
498 * (non-Javadoc)
499 *
500 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
501 *
502 * Reflesh the frame when selected item changed
503 *
504 */
505
506 public void itemStateChanged(ItemEvent arg0) {
507 if (arg0.getSource() == this.jComboBoxProtocolType && arg0.getStateChange() == ItemEvent.SELECTED) {
508 if (this.jComboBoxProtocolType.getSelectedItem().toString().equals(ed.getVProtocolType().get(0))) {
509 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVProtocolUsage());
510 } else {
511 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVProtocolNotifyUsage());
512 }
513 }
514 }
515
516 public ProtocolsIdentification getId() {
517 return id;
518 }
519
520 public void setId(ProtocolsIdentification id) {
521 this.id = id;
522 }
523 }