]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/ProtocolsDlg.java
Restructuring for better separation of Tool packages.
[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.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 //
294 // Init arch with module's arch
295 //
296 this.jArchCheckBox.setEnabledItems(wt.getModuleArch(mid));
297
298 //
299 // Get defined protocols from dependent packages
300 //
301 Vector<PackageIdentification> vpid = wt.getPackageDependenciesOfModule(mid);
302 if (vpid.size() <= 0) {
303 Log.wrn("Init Protocol", "This module hasn't defined any package dependency, so there is no protocol can be added");
304 }
305
306 Tools.generateComboBoxByVector(this.jComboBoxCName,
307 wt.getAllProtocolDeclarationsFromPackages(wt.getPackageDependenciesOfModule(mid)));
308
309 if (this.id != null) {
310 this.jComboBoxCName.setSelectedItem(id.getName());
311 this.jComboBoxProtocolType.setSelectedItem(id.getType());
312 this.jComboBoxUsage.setSelectedItem(id.getUsage());
313 this.jTextAreaHelpText.setText(id.getHelp());
314 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
315 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
316 }
317 }
318
319 /**
320 * This is the override edit constructor
321 *
322 * @param inProtocolsIdentification
323 * @param iFrame
324 *
325 */
326 public ProtocolsDlg(ProtocolsIdentification inProtocolsIdentification, IFrame iFrame, ModuleIdentification mid) {
327 super(iFrame, true);
328 init(inProtocolsIdentification, mid);
329 }
330
331 /**
332 * Disable all components when the mode is view
333 *
334 * @param isView
335 * true - The view mode; false - The non-view mode
336 *
337 */
338 public void setViewMode(boolean isView) {
339 if (isView) {
340 this.jComboBoxUsage.setEnabled(!isView);
341 this.jTextFieldFeatureFlag.setEnabled(!isView);
342 }
343 }
344
345 /**
346 * This method initializes jContentPane
347 *
348 * @return javax.swing.JPanel jContentPane
349 *
350 */
351 private JPanel getJContentPane() {
352 if (jContentPane == null) {
353 jStarLabel1 = new StarLabel();
354 jStarLabel1.setLocation(new java.awt.Point(2, 12));
355 jLabelProtocolType = new JLabel();
356 jLabelProtocolType.setBounds(new java.awt.Rectangle(12, 12, 155, 20));
357 jLabelProtocolType.setText("Select Protocol Type");
358
359 jStarLabel2 = new StarLabel();
360 jStarLabel2.setLocation(new java.awt.Point(2, 37));
361 jLabelC_Name = new JLabel();
362 jLabelC_Name.setText("Protocol Guid C Name");
363 jLabelC_Name.setBounds(new java.awt.Rectangle(12, 37, 155, 20));
364
365 jStarLabel3 = new StarLabel();
366 jStarLabel3.setLocation(new java.awt.Point(2, 62));
367 jLabelUsage = new JLabel();
368 jLabelUsage.setText("Usage");
369 jLabelUsage.setBounds(new java.awt.Rectangle(12, 62, 155, 20));
370
371 jLabelHelpText = new JLabel();
372 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 87, 155, 20));
373 jLabelHelpText.setText("Help Text");
374
375 jLabelFeatureFlag = new JLabel();
376 jLabelFeatureFlag.setText("Feature Flag Expression");
377 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 157, 155, 20));
378 jLabelFeatureFlag.setEnabled(false);
379
380 jLabelArch = new JLabel();
381 jLabelArch.setBounds(new java.awt.Rectangle(12, 132, 155, 20));
382 jLabelArch.setText("Supported Architectures");
383 jArchCheckBox = new ArchCheckBox();
384 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 132, 320, 20));
385 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
386
387 jContentPane = new JPanel();
388 jContentPane.setLayout(null);
389 jContentPane.setPreferredSize(new java.awt.Dimension(485, 215));
390
391 jContentPane.add(jStarLabel1, null);
392 jContentPane.add(jLabelProtocolType, null);
393 jContentPane.add(getJComboBoxProtocolType(), null);
394 jContentPane.add(jStarLabel2, null);
395 jContentPane.add(jLabelC_Name, null);
396 jContentPane.add(getJComboBoxCName(), null);
397 jContentPane.add(jStarLabel3, null);
398 jContentPane.add(jLabelUsage, null);
399 jContentPane.add(getJComboBoxProtocolUsage(), null);
400 jContentPane.add(jLabelHelpText, null);
401 jContentPane.add(getJScrollPaneHelpText(), null);
402 jContentPane.add(jLabelFeatureFlag, null);
403 jContentPane.add(getJTextFieldFeatureFlag(), null);
404 jContentPane.add(jLabelArch, null);
405 jContentPane.add(jArchCheckBox, null);
406 jContentPane.add(getJButtonOk(), null);
407 jContentPane.add(getJButtonCancel(), null);
408 }
409 return jContentPane;
410 }
411
412 /**
413 * This method initializes Usage type
414 *
415 */
416 private void initFrame() {
417 Tools.generateComboBoxByVector(jComboBoxProtocolType, ed.getVProtocolType());
418 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVProtocolUsage());
419 }
420
421 /*
422 * (non-Javadoc)
423 *
424 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
425 *
426 * Override actionPerformed to listen all actions
427 *
428 */
429 public void actionPerformed(ActionEvent arg0) {
430 if (arg0.getSource() == jButtonOk) {
431 if (checkAdd()) {
432 getCurrentProtocols();
433 this.returnType = DataType.RETURN_TYPE_OK;
434 this.setVisible(false);
435 }
436 }
437
438 if (arg0.getSource() == jButtonCancel) {
439 this.returnType = DataType.RETURN_TYPE_CANCEL;
440 this.setVisible(false);
441 }
442 }
443
444 /**
445 * Data validation for all fields
446 *
447 * @retval true - All datas are valid
448 * @retval false - At least one data is invalid
449 *
450 */
451 public boolean checkAdd() {
452 //
453 // Check if all fields have correct data types
454 //
455
456 //
457 // Check Name
458 //
459 if (this.jComboBoxCName.getSelectedItem() == null) {
460 Log.wrn("Update protocols", "Please select one Protocol/ProtocolNotify Name");
461 return false;
462 }
463
464 if (!isEmpty(this.jComboBoxCName.getSelectedItem().toString())) {
465 if (!DataValidation.isC_NameType(this.jComboBoxCName.getSelectedItem().toString())) {
466 Log.wrn("Update Protocols", "Incorrect data type for Protocol/ProtocolNotify Name");
467 return false;
468 }
469 }
470
471 //
472 // Check FeatureFlag
473 //
474 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
475 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
476 Log.wrn("Update Protocols", "Incorrect data type for Feature Flag");
477 return false;
478 }
479 }
480
481 return true;
482 }
483
484 private ProtocolsIdentification getCurrentProtocols() {
485 String arg0 = this.jComboBoxCName.getSelectedItem().toString();
486 String arg1 = this.jComboBoxProtocolType.getSelectedItem().toString();
487 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();
488
489 String arg3 = this.jTextFieldFeatureFlag.getText();
490 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
491 String arg5 = this.jTextAreaHelpText.getText();
492 id = new ProtocolsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
493 return id;
494 }
495
496 /*
497 * (non-Javadoc)
498 *
499 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
500 *
501 * Reflesh the frame when selected item changed
502 *
503 */
504
505 public void itemStateChanged(ItemEvent arg0) {
506 if (arg0.getSource() == this.jComboBoxProtocolType && arg0.getStateChange() == ItemEvent.SELECTED) {
507 if (this.jComboBoxProtocolType.getSelectedItem().toString().equals(ed.getVProtocolType().get(0))) {
508 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVProtocolUsage());
509 } else {
510 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVProtocolNotifyUsage());
511 }
512 }
513 }
514
515 public ProtocolsIdentification getId() {
516 return id;
517 }
518
519 public void setId(ProtocolsIdentification id) {
520 this.id = id;
521 }
522 }