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