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