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