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