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