]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/ProtocolsDlg.java
1. Change ToolCode from text field to drop down list, and user can enter their custom...
[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
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
117 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 130, 320, 20));\r
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
133 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 60, 320, 20));\r
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
170 jComboBoxProtocolType.setBounds(new java.awt.Rectangle(160, 10, 320, 20));\r
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
187 jComboBoxCName.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r
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
222 jScrollPaneHelpText.setLocation(new java.awt.Point(160, 85));\r
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
237 jButtonOk.setBounds(new java.awt.Rectangle(290, 182, 90, 20));\r
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
253 jButtonCancel.setBounds(new java.awt.Rectangle(390, 182, 90, 20));\r
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
269 this.setSize(500, 255);\r
270 this.setContentPane(getJScrollPane());\r
271 this.setTitle("Protocols");\r
272 initFrame();\r
273 this.setViewMode(false);\r
274 this.centerWindow();\r
06a19cee 275 }\r
a929458e 276\r
277 /**\r
278 * This method initializes this Fill values to all fields if these values are\r
279 * not empty\r
280 * \r
281 * @param inProtocolsId\r
282 * \r
283 */\r
284 private void init(ProtocolsIdentification inProtocolsId) {\r
285 init();\r
286 this.id = inProtocolsId;\r
287\r
288 if (this.id != null) {\r
289 this.jComboBoxCName.setSelectedItem(id.getName());\r
290 this.jComboBoxProtocolType.setSelectedItem(id.getType());\r
291 this.jComboBoxUsage.setSelectedItem(id.getUsage());\r
292 this.jTextAreaHelpText.setText(id.getHelp());\r
293 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());\r
294 this.jArchCheckBox.setSelectedItems(id.getSupArchList());\r
295 }\r
06a19cee 296 }\r
a929458e 297\r
298 /**\r
299 * This is the override edit constructor\r
300 * \r
301 * @param inProtocolsIdentification\r
302 * @param iFrame\r
303 * \r
304 */\r
305 public ProtocolsDlg(ProtocolsIdentification inProtocolsIdentification, IFrame iFrame) {\r
306 super(iFrame, true);\r
307 init(inProtocolsIdentification);\r
06a19cee 308 }\r
a929458e 309\r
310 /**\r
311 * Disable all components when the mode is view\r
312 * \r
313 * @param isView\r
314 * true - The view mode; false - The non-view mode\r
315 * \r
316 */\r
317 public void setViewMode(boolean isView) {\r
318 if (isView) {\r
319 this.jComboBoxUsage.setEnabled(!isView);\r
320 this.jTextFieldFeatureFlag.setEnabled(!isView);\r
321 }\r
06a19cee 322 }\r
a929458e 323\r
324 /**\r
325 * This method initializes jContentPane\r
326 * \r
327 * @return javax.swing.JPanel jContentPane\r
328 * \r
329 */\r
330 private JPanel getJContentPane() {\r
331 if (jContentPane == null) {\r
332 jStarLabel1 = new StarLabel();\r
333 jStarLabel1.setLocation(new java.awt.Point(2, 10));\r
334 jLabelProtocolType = new JLabel();\r
335 jLabelProtocolType.setBounds(new java.awt.Rectangle(15, 10, 145, 20));\r
336 jLabelProtocolType.setText("Select Protocol Type");\r
337\r
338 jStarLabel2 = new StarLabel();\r
339 jStarLabel2.setLocation(new java.awt.Point(2, 35));\r
340 jLabelC_Name = new JLabel();\r
341 jLabelC_Name.setText("Protocol Guid C Name");\r
342 jLabelC_Name.setBounds(new java.awt.Rectangle(15, 35, 145, 20));\r
343\r
344 jStarLabel3 = new StarLabel();\r
345 jStarLabel3.setLocation(new java.awt.Point(2, 60));\r
346 jLabelUsage = new JLabel();\r
347 jLabelUsage.setText("Usage");\r
348 jLabelUsage.setBounds(new java.awt.Rectangle(15, 60, 145, 20));\r
349\r
350 jLabelHelpText = new JLabel();\r
351 jLabelHelpText.setBounds(new java.awt.Rectangle(15, 85, 145, 20));\r
352 jLabelHelpText.setText("Help Text");\r
353\r
354 jLabelFeatureFlag = new JLabel();\r
355 jLabelFeatureFlag.setText("Feature Flag Expression");\r
356 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 130, 145, 20));\r
357\r
358 jLabelArch = new JLabel();\r
359 jLabelArch.setBounds(new java.awt.Rectangle(15, 155, 145, 20));\r
360 jLabelArch.setText("Supported Architectures");\r
361 jArchCheckBox = new ArchCheckBox();\r
362 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 155, 320, 20));\r
363 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));\r
364\r
365 jContentPane = new JPanel();\r
366 jContentPane.setLayout(null);\r
367 jContentPane.setPreferredSize(new java.awt.Dimension(485, 210));\r
368\r
369 jContentPane.add(jStarLabel1, null);\r
370 jContentPane.add(jLabelProtocolType, null);\r
371 jContentPane.add(getJComboBoxProtocolType(), null);\r
372 jContentPane.add(jStarLabel2, null);\r
373 jContentPane.add(jLabelC_Name, null);\r
374 jContentPane.add(getJComboBoxCName(), null);\r
375 jContentPane.add(jStarLabel3, null);\r
376 jContentPane.add(jLabelUsage, null);\r
377 jContentPane.add(getJComboBoxProtocolUsage(), null);\r
378 jContentPane.add(jLabelHelpText, null);\r
379 jContentPane.add(getJScrollPaneHelpText(), null);\r
380 jContentPane.add(jLabelFeatureFlag, null);\r
381 jContentPane.add(getJTextFieldFeatureFlag(), null);\r
382 jContentPane.add(jLabelArch, null);\r
383 jContentPane.add(jArchCheckBox, null);\r
384 jContentPane.add(getJButtonOk(), null);\r
385 jContentPane.add(getJButtonCancel(), null);\r
386 }\r
387 return jContentPane;\r
06a19cee 388 }\r
a929458e 389\r
390 /**\r
391 * This method initializes Usage type\r
392 * \r
393 */\r
394 private void initFrame() {\r
395 Tools.generateComboBoxByVector(jComboBoxProtocolType, ed.getVProtocolType());\r
396 Tools.generateComboBoxByVector(jComboBoxCName, wt.getAllProtocolDeclarationsFromWorkspace());\r
397 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVProtocolUsage());\r
06a19cee 398 }\r
399\r
a929458e 400 /*\r
401 * (non-Javadoc)\r
402 * \r
403 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
404 * \r
405 * Override actionPerformed to listen all actions\r
406 * \r
407 */\r
408 public void actionPerformed(ActionEvent arg0) {\r
409 if (arg0.getSource() == jButtonOk) {\r
410 if (checkAdd()) {\r
411 getCurrentProtocols();\r
412 this.returnType = DataType.RETURN_TYPE_OK;\r
413 this.setVisible(false);\r
414 }\r
415 }\r
416\r
417 if (arg0.getSource() == jButtonCancel) {\r
418 this.returnType = DataType.RETURN_TYPE_CANCEL;\r
419 this.setVisible(false);\r
420 }\r
06a19cee 421 }\r
422\r
a929458e 423 /**\r
424 * Data validation for all fields\r
425 * \r
426 * @retval true - All datas are valid\r
427 * @retval false - At least one data is invalid\r
428 * \r
429 */\r
430 public boolean checkAdd() {\r
431 //\r
432 // Check if all fields have correct data types\r
433 //\r
434\r
435 //\r
436 // Check Name\r
437 //\r
438 if (!isEmpty(this.jComboBoxCName.getSelectedItem().toString())) {\r
439 if (!DataValidation.isC_NameType(this.jComboBoxCName.getSelectedItem().toString())) {\r
440 Log.wrn("Update Protocols", "Incorrect data type for Protocol/ProtocolNotify Name");\r
441 return false;\r
442 }\r
443 }\r
444\r
445 //\r
446 // Check FeatureFlag\r
447 //\r
448 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r
449 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r
450 Log.wrn("Update Protocols", "Incorrect data type for Feature Flag");\r
451 return false;\r
452 }\r
453 }\r
454\r
455 return true;\r
06a19cee 456 }\r
457\r
a929458e 458 private ProtocolsIdentification getCurrentProtocols() {\r
459 String arg0 = this.jComboBoxCName.getSelectedItem().toString();\r
460 String arg1 = this.jComboBoxProtocolType.getSelectedItem().toString();\r
461 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();\r
462\r
463 String arg3 = this.jTextFieldFeatureFlag.getText();\r
464 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();\r
465 String arg5 = this.jTextAreaHelpText.getText();\r
466 id = new ProtocolsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r
467 return id;\r
06a19cee 468 }\r
469\r
a929458e 470 /*\r
471 * (non-Javadoc)\r
472 * \r
473 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)\r
474 * \r
475 * Reflesh the frame when selected item changed\r
476 * \r
477 */\r
478\r
479 public void itemStateChanged(ItemEvent arg0) {\r
480 if (arg0.getSource() == this.jComboBoxProtocolType && arg0.getStateChange() == ItemEvent.SELECTED) {\r
481 if (this.jComboBoxProtocolType.getSelectedItem().toString().equals(ed.getVProtocolType().get(0))) {\r
482 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVProtocolUsage());\r
483 } else {\r
484 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVProtocolNotifyUsage());\r
485 }\r
486 }\r
06a19cee 487 }\r
7ab6baa9 488\r
a929458e 489 public ProtocolsIdentification getId() {\r
490 return id;\r
491 }\r
7ab6baa9 492\r
a929458e 493 public void setId(ProtocolsIdentification id) {\r
494 this.id = id;\r
495 }\r
06a19cee 496}\r