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