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