]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/ProtocolsDlg.java
8b303dee0d7ce4f1c8cbc21a839abcda55c7452b
[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 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
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
118 .setBounds(new java.awt.Rectangle(160, 130, 320, 20));
119 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
120 jTextFieldFeatureFlag
121 .setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
122 }
123 return jTextFieldFeatureFlag;
124 }
125
126 /**
127 * This method initializes jComboBoxUsage
128 *
129 * @return javax.swing.JComboBox jComboBoxUsage
130 *
131 */
132 private JComboBox getJComboBoxProtocolUsage() {
133 if (jComboBoxUsage == null) {
134 jComboBoxUsage = new JComboBox();
135 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
136 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
137 jComboBoxUsage
138 .setToolTipText("<html><table><tr><td colspan=2 align=center><b>Protocol</b></td></tr>"
139 + "<tr><td>ALWAYS_CONSUMED</td><td>Module always consumes the protocol</td></tr>"
140 + "<tr><td>SOMETIMES_CONSUMES</td><td>Module sometimes consumes the protocol</td></tr>"
141 + "<tr><td>ALWAYS_PRODUCED</td><td>Module always produces the protocol</td></tr>"
142 + "<tr><td>SOMETIMES_PRODUCED</td><td>Module sometimes produces the protocol</td></tr>"
143 + "<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>"
144 + "<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>"
145 + "<tr><td colspan=2 align=center><b>Protocol Notify</b></td></tr>"
146 + "<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>");
147 }
148 return jComboBoxUsage;
149 }
150
151 /**
152 * This method initializes jScrollPane
153 *
154 * @return javax.swing.JScrollPane
155 */
156 private JScrollPane getJScrollPane() {
157 if (jScrollPane == null) {
158 jScrollPane = new JScrollPane();
159 jScrollPane.setViewportView(getJContentPane());
160 }
161 return jScrollPane;
162 }
163
164 /**
165 * This method initializes jComboBoxProtocolType
166 *
167 * @return javax.swing.JComboBox
168 */
169 private JComboBox getJComboBoxProtocolType() {
170 if (jComboBoxProtocolType == null) {
171 jComboBoxProtocolType = new JComboBox();
172 jComboBoxProtocolType.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
173 jComboBoxProtocolType.setPreferredSize(new java.awt.Dimension(320, 20));
174 jComboBoxProtocolType.addItemListener(this);
175 jComboBoxProtocolType
176 .setToolTipText("<html>Select Protocol Type<br>Protocol Notify is a register protocol notify mechanism.");
177 }
178 return jComboBoxProtocolType;
179 }
180
181 /**
182 * This method initializes jComboBoxCName
183 *
184 * @return javax.swing.JComboBox
185 */
186 private JComboBox getJComboBoxCName() {
187 if (jComboBoxCName == null) {
188 jComboBoxCName = new JComboBox();
189 jComboBoxCName.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
190 jComboBoxCName.setPreferredSize(new java.awt.Dimension(320, 20));
191 jComboBoxCName.setToolTipText("Select Guid C Name of the Protocol");
192
193 }
194 return jComboBoxCName;
195 }
196
197 /**
198 * This method initializes jTextAreaHelpText
199 *
200 * @return javax.swing.JTextArea
201 *
202 */
203 private JTextArea getJTextAreaHelpText() {
204 if (jTextAreaHelpText == null) {
205 jTextAreaHelpText = new JTextArea();
206 jTextAreaHelpText.setLineWrap(true);
207 jTextAreaHelpText.setWrapStyleWord(true);
208 }
209 return jTextAreaHelpText;
210 }
211
212 /**
213 * This method initializes jScrollPaneHelpText
214 *
215 * @return javax.swing.JScrollPane
216 *
217 */
218 private JScrollPane getJScrollPaneHelpText() {
219 if (jScrollPaneHelpText == null) {
220 jScrollPaneHelpText = new JScrollPane();
221 jScrollPaneHelpText
222 .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(160, 85));
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, 182, 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, 182, 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 this.setSize(500, 255);
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,
309 IFrame iFrame) {
310 super(iFrame, true);
311 init(inProtocolsIdentification);
312 }
313
314 /**
315 * Disable all components when the mode is view
316 *
317 * @param isView
318 * true - The view mode; false - The non-view mode
319 *
320 */
321 public void setViewMode(boolean isView) {
322 if (isView) {
323 this.jComboBoxUsage.setEnabled(!isView);
324 this.jTextFieldFeatureFlag.setEnabled(!isView);
325 }
326 }
327
328 /**
329 * This method initializes jContentPane
330 *
331 * @return javax.swing.JPanel jContentPane
332 *
333 */
334 private JPanel getJContentPane() {
335 if (jContentPane == null) {
336 jStarLabel1 = new StarLabel();
337 jStarLabel1.setLocation(new java.awt.Point(2, 10));
338 jLabelProtocolType = new JLabel();
339 jLabelProtocolType.setBounds(new java.awt.Rectangle(15, 10, 145, 20));
340 jLabelProtocolType.setText("Select Protocol Type");
341
342 jStarLabel2 = new StarLabel();
343 jStarLabel2.setLocation(new java.awt.Point(2, 35));
344 jLabelC_Name = new JLabel();
345 jLabelC_Name.setText("Protocol Guid C Name");
346 jLabelC_Name.setBounds(new java.awt.Rectangle(15, 35, 145, 20));
347
348 jStarLabel3 = new StarLabel();
349 jStarLabel3.setLocation(new java.awt.Point(2, 60));
350 jLabelUsage = new JLabel();
351 jLabelUsage.setText("Usage");
352 jLabelUsage.setBounds(new java.awt.Rectangle(15, 60, 145, 20));
353
354 jLabelHelpText = new JLabel();
355 jLabelHelpText.setBounds(new java.awt.Rectangle(15, 85, 145, 20));
356 jLabelHelpText.setText("Help Text");
357
358 jLabelFeatureFlag = new JLabel();
359 jLabelFeatureFlag.setText("Feature Flag Expression");
360 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 130, 145, 20));
361
362 jLabelArch = new JLabel();
363 jLabelArch.setBounds(new java.awt.Rectangle(15, 155, 145, 20));
364 jLabelArch.setText("Supported Architectures");
365 jArchCheckBox = new ArchCheckBox();
366 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 155, 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, 210));
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
400 .generateComboBoxByVector(jComboBoxProtocolType, ed.getVProtocolType());
401 Tools.generateComboBoxByVector(jComboBoxCName, wt
402 .getAllProtocolDeclarationsFromWorkspace());
403 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVProtocolUsage());
404 }
405
406 /*
407 * (non-Javadoc)
408 *
409 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
410 *
411 * Override actionPerformed to listen all actions
412 *
413 */
414 public void actionPerformed(ActionEvent arg0) {
415 if (arg0.getSource() == jButtonOk) {
416 if (checkAdd()) {
417 getCurrentProtocols();
418 this.returnType = DataType.RETURN_TYPE_OK;
419 this.setVisible(false);
420 }
421 }
422
423 if (arg0.getSource() == jButtonCancel) {
424 this.returnType = DataType.RETURN_TYPE_CANCEL;
425 this.setVisible(false);
426 }
427 }
428
429 /**
430 * Data validation for all fields
431 *
432 * @retval true - All datas are valid
433 * @retval false - At least one data is invalid
434 *
435 */
436 public boolean checkAdd() {
437 //
438 // Check if all fields have correct data types
439 //
440
441 //
442 // Check Name
443 //
444 if (!isEmpty(this.jComboBoxCName.getSelectedItem().toString())) {
445 if (!DataValidation.isC_NameType(this.jComboBoxCName.getSelectedItem()
446 .toString())) {
447 Log.wrn("Update Protocols",
448 "Incorrect data type for Protocol/ProtocolNotify Name");
449 return false;
450 }
451 }
452
453 //
454 // Check FeatureFlag
455 //
456 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
457 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
458 Log.wrn("Update Protocols", "Incorrect data type for Feature Flag");
459 return false;
460 }
461 }
462
463 return true;
464 }
465
466 private ProtocolsIdentification getCurrentProtocols() {
467 String arg0 = this.jComboBoxCName.getSelectedItem().toString();
468 String arg1 = this.jComboBoxProtocolType.getSelectedItem().toString();
469 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();
470
471 String arg3 = this.jTextFieldFeatureFlag.getText();
472 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
473 String arg5 = this.jTextAreaHelpText.getText();
474 id = new ProtocolsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
475 return id;
476 }
477
478 /*
479 * (non-Javadoc)
480 *
481 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
482 *
483 * Reflesh the frame when selected item changed
484 *
485 */
486
487 public void itemStateChanged(ItemEvent arg0) {
488 if (arg0.getSource() == this.jComboBoxProtocolType
489 && arg0.getStateChange() == ItemEvent.SELECTED) {
490 if (this.jComboBoxProtocolType.getSelectedItem().toString().equals(
491 ed.getVProtocolType().get(0))) {
492 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed
493 .getVProtocolUsage());
494 } else {
495 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed
496 .getVProtocolNotifyUsage());
497 }
498 }
499 }
500
501 public ProtocolsIdentification getId() {
502 return id;
503 }
504
505 public void setId(ProtocolsIdentification id) {
506 this.id = id;
507 }
508 }