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