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