]>
Commit | Line | Data |
---|---|---|
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 | |
130 | }\r | |
131 | return jComboBoxUsage;\r | |
132 | }\r | |
133 | \r | |
134 | /**\r | |
135 | This method initializes jScrollPane \r | |
136 | \r | |
137 | @return javax.swing.JScrollPane \r | |
138 | */\r | |
139 | private JScrollPane getJScrollPane() {\r | |
140 | if (jScrollPane == null) {\r | |
141 | jScrollPane = new JScrollPane();\r | |
142 | jScrollPane.setViewportView(getJContentPane());\r | |
143 | }\r | |
144 | return jScrollPane;\r | |
145 | }\r | |
146 | \r | |
147 | /**\r | |
148 | * This method initializes jComboBoxProtocolType \r | |
149 | * \r | |
150 | * @return javax.swing.JComboBox \r | |
151 | */\r | |
152 | private JComboBox getJComboBoxProtocolType() {\r | |
153 | if (jComboBoxProtocolType == null) {\r | |
154 | jComboBoxProtocolType = new JComboBox();\r | |
155 | jComboBoxProtocolType.setBounds(new java.awt.Rectangle(160, 10, 320, 20));\r | |
156 | jComboBoxProtocolType.setPreferredSize(new java.awt.Dimension(320, 20));\r | |
157 | jComboBoxProtocolType.addItemListener(this);\r | |
158 | jComboBoxProtocolType.setToolTipText("Select Protocol Type");\r | |
159 | }\r | |
160 | return jComboBoxProtocolType;\r | |
161 | }\r | |
162 | \r | |
163 | /**\r | |
164 | * This method initializes jComboBoxCName \r | |
165 | * \r | |
166 | * @return javax.swing.JComboBox \r | |
167 | */\r | |
168 | private JComboBox getJComboBoxCName() {\r | |
169 | if (jComboBoxCName == null) {\r | |
170 | jComboBoxCName = new JComboBox();\r | |
171 | jComboBoxCName.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r | |
172 | jComboBoxCName.setPreferredSize(new java.awt.Dimension(320, 20));\r | |
173 | \r | |
174 | }\r | |
175 | return jComboBoxCName;\r | |
176 | }\r | |
177 | \r | |
178 | /**\r | |
179 | This method initializes jTextFieldHelpText \r | |
180 | \r | |
181 | @return javax.swing.JTextField \r | |
182 | \r | |
183 | **/\r | |
184 | private JTextField getJTextFieldHelpText() {\r | |
185 | if (jTextFieldHelpText == null) {\r | |
186 | jTextFieldHelpText = new JTextField();\r | |
187 | jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 85, 320, 20));\r | |
188 | jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));\r | |
189 | }\r | |
190 | return jTextFieldHelpText;\r | |
191 | }\r | |
192 | \r | |
193 | /**\r | |
194 | This method initializes jButtonOk \r | |
195 | \r | |
196 | @return javax.swing.JButton \r | |
197 | \r | |
198 | **/\r | |
199 | private JButton getJButtonOk() {\r | |
200 | if (jButtonOk == null) {\r | |
201 | jButtonOk = new JButton();\r | |
202 | jButtonOk.setBounds(new java.awt.Rectangle(290, 165, 90, 20));\r | |
203 | jButtonOk.setText("Ok");\r | |
204 | jButtonOk.addActionListener(this);\r | |
205 | }\r | |
206 | return jButtonOk;\r | |
207 | }\r | |
208 | \r | |
209 | /**\r | |
210 | This method initializes jButtonCancel \r | |
211 | \r | |
212 | @return javax.swing.JButton \r | |
213 | \r | |
214 | **/\r | |
215 | private JButton getJButtonCancel() {\r | |
216 | if (jButtonCancel == null) {\r | |
217 | jButtonCancel = new JButton();\r | |
218 | jButtonCancel.setBounds(new java.awt.Rectangle(390, 165, 90, 20));\r | |
219 | jButtonCancel.setText("Cancel");\r | |
220 | jButtonCancel.addActionListener(this);\r | |
221 | }\r | |
222 | return jButtonCancel;\r | |
223 | }\r | |
224 | \r | |
225 | public static void main(String[] args) {\r | |
226 | \r | |
227 | }\r | |
228 | \r | |
229 | /**\r | |
230 | This method initializes this\r | |
231 | \r | |
232 | **/\r | |
233 | private void init() {\r | |
f51ee52b | 234 | this.setSize(510, 240);\r |
06a19cee | 235 | this.setContentPane(getJScrollPane());\r |
236 | this.setTitle("Protocols");\r | |
237 | initFrame();\r | |
238 | this.setViewMode(false);\r | |
239 | this.centerWindow();\r | |
240 | }\r | |
241 | \r | |
242 | /**\r | |
243 | This method initializes this\r | |
244 | Fill values to all fields if these values are not empty\r | |
245 | \r | |
246 | @param inProtocolsId\r | |
247 | \r | |
248 | **/\r | |
249 | private void init(ProtocolsIdentification inProtocolsId) {\r | |
250 | init();\r | |
251 | this.id = inProtocolsId;\r | |
252 | \r | |
253 | if (this.id != null) {\r | |
254 | this.jComboBoxCName.setSelectedItem(id.getName());\r | |
255 | this.jComboBoxProtocolType.setSelectedItem(id.getType());\r | |
256 | this.jComboBoxUsage.setSelectedItem(id.getUsage());\r | |
257 | this.jTextFieldHelpText.setText(id.getHelp());\r | |
258 | \r | |
259 | jTextFieldFeatureFlag.setText(id.getFeatureFlag());\r | |
260 | this.jArchCheckBox.setSelectedItems(id.getSupArchList());\r | |
261 | }\r | |
262 | }\r | |
263 | \r | |
264 | /**\r | |
265 | This is the override edit constructor\r | |
266 | \r | |
267 | @param inProtocolsIdentification\r | |
268 | @param iFrame\r | |
269 | \r | |
270 | **/\r | |
271 | public ProtocolsDlg(ProtocolsIdentification inProtocolsIdentification, IFrame iFrame) {\r | |
272 | super(iFrame, true);\r | |
273 | init(inProtocolsIdentification);\r | |
274 | }\r | |
275 | \r | |
276 | /**\r | |
277 | Disable all components when the mode is view\r | |
278 | \r | |
279 | @param isView true - The view mode; false - The non-view mode\r | |
280 | \r | |
281 | **/\r | |
282 | public void setViewMode(boolean isView) {\r | |
283 | if (isView) {\r | |
284 | this.jComboBoxUsage.setEnabled(!isView);\r | |
285 | this.jTextFieldFeatureFlag.setEnabled(!isView);\r | |
286 | }\r | |
287 | }\r | |
288 | \r | |
289 | /**\r | |
290 | This method initializes jContentPane\r | |
291 | \r | |
292 | @return javax.swing.JPanel jContentPane\r | |
293 | \r | |
294 | **/\r | |
295 | private JPanel getJContentPane() {\r | |
296 | if (jContentPane == null) {\r | |
297 | jArchCheckBox = new ArchCheckBox();\r | |
298 | jArchCheckBox.setBounds(new java.awt.Rectangle(160, 135, 320, 20));\r | |
299 | jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));\r | |
300 | jLabelHelpText = new JLabel();\r | |
301 | jLabelHelpText.setBounds(new java.awt.Rectangle(14, 85, 140, 20));\r | |
302 | jLabelHelpText.setText("Help Text");\r | |
303 | jLabelArch = new JLabel();\r | |
304 | jLabelArch.setBounds(new java.awt.Rectangle(15, 135, 140, 20));\r | |
305 | jLabelArch.setText("Arch Type");\r | |
306 | jLabelProtocolType = new JLabel();\r | |
307 | jLabelProtocolType.setBounds(new java.awt.Rectangle(15, 10, 140, 20));\r | |
308 | jLabelProtocolType.setText("Protocol Type");\r | |
309 | jLabelUsage = new JLabel();\r | |
310 | jLabelUsage.setText("Usage");\r | |
311 | jLabelUsage.setBounds(new java.awt.Rectangle(15, 60, 140, 20));\r | |
312 | jLabelFeatureFlag = new JLabel();\r | |
313 | jLabelFeatureFlag.setText("Feature Flag");\r | |
314 | jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 110, 140, 20));\r | |
315 | jLabelC_Name = new JLabel();\r | |
f51ee52b | 316 | jLabelC_Name.setText("C Name Type");\r |
06a19cee | 317 | jLabelC_Name.setBounds(new java.awt.Rectangle(15, 35, 140, 20));\r |
318 | \r | |
319 | jContentPane = new JPanel();\r | |
320 | jContentPane.setLayout(null);\r | |
321 | jContentPane.setPreferredSize(new java.awt.Dimension(490, 190));\r | |
322 | \r | |
323 | jContentPane.add(jLabelC_Name, null);\r | |
324 | jContentPane.add(jLabelFeatureFlag, null);\r | |
325 | jContentPane.add(getJTextFieldFeatureFlag(), null);\r | |
326 | jContentPane.add(jLabelUsage, null);\r | |
327 | jContentPane.add(getJComboBoxProtocolUsage(), null);\r | |
328 | jContentPane.add(jLabelProtocolType, null);\r | |
329 | \r | |
330 | jStarLabel1 = new StarLabel();\r | |
331 | jStarLabel1.setBounds(new java.awt.Rectangle(0, 10, 10, 20));\r | |
332 | jStarLabel2 = new StarLabel();\r | |
333 | jStarLabel2.setBounds(new java.awt.Rectangle(0, 35, 10, 20));\r | |
334 | \r | |
335 | jContentPane.add(jStarLabel1, null);\r | |
336 | jContentPane.add(jStarLabel2, null);\r | |
337 | jContentPane.add(jLabelArch, null);\r | |
338 | jContentPane.add(getJComboBoxProtocolType(), null);\r | |
339 | jContentPane.add(getJComboBoxCName(), null);\r | |
340 | jContentPane.add(jLabelHelpText, null);\r | |
341 | jContentPane.add(getJTextFieldHelpText(), null);\r | |
342 | jContentPane.add(jArchCheckBox, null);\r | |
343 | jContentPane.add(getJButtonOk(), null);\r | |
344 | jContentPane.add(getJButtonCancel(), null);\r | |
345 | }\r | |
346 | return jContentPane;\r | |
347 | }\r | |
348 | \r | |
349 | /**\r | |
350 | This method initializes Usage type\r | |
351 | \r | |
352 | **/\r | |
353 | private void initFrame() {\r | |
354 | Tools.generateComboBoxByVector(jComboBoxProtocolType, ed.getVProtocolType());\r | |
355 | Tools.generateComboBoxByVector(jComboBoxCName, wt.getAllProtocolDeclarationsFromWorkspace());\r | |
356 | Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVProtocolUsage());\r | |
357 | }\r | |
358 | \r | |
359 | /* (non-Javadoc)\r | |
360 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r | |
361 | *\r | |
362 | * Override actionPerformed to listen all actions\r | |
363 | * \r | |
364 | */\r | |
365 | public void actionPerformed(ActionEvent arg0) {\r | |
366 | if (arg0.getSource() == jButtonOk) {\r | |
367 | if (checkAdd()) {\r | |
368 | getCurrentProtocols();\r | |
369 | this.returnType = DataType.RETURN_TYPE_OK;\r | |
370 | this.setVisible(false);\r | |
371 | }\r | |
372 | }\r | |
373 | \r | |
374 | if (arg0.getSource() == jButtonCancel) {\r | |
375 | this.returnType = DataType.RETURN_TYPE_CANCEL;\r | |
376 | this.setVisible(false);\r | |
377 | }\r | |
378 | }\r | |
379 | \r | |
380 | /**\r | |
381 | Data validation for all fields\r | |
382 | \r | |
383 | @retval true - All datas are valid\r | |
384 | @retval false - At least one data is invalid\r | |
385 | \r | |
386 | **/\r | |
387 | public boolean checkAdd() {\r | |
388 | //\r | |
389 | // Check if all fields have correct data types \r | |
390 | //\r | |
391 | \r | |
392 | //\r | |
393 | // Check Name \r | |
394 | //\r | |
395 | if (!isEmpty(this.jComboBoxCName.getSelectedItem().toString())) {\r | |
396 | if (!DataValidation.isC_NameType(this.jComboBoxCName.getSelectedItem().toString())) {\r | |
ed1665f2 | 397 | Log.wrn("Update Protocols", "Incorrect data type for Protocol/ProtocolNotify Name");\r |
06a19cee | 398 | return false;\r |
399 | }\r | |
400 | }\r | |
401 | \r | |
402 | //\r | |
403 | // Check FeatureFlag\r | |
404 | //\r | |
405 | if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r | |
406 | if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r | |
ed1665f2 | 407 | Log.wrn("Update Protocols", "Incorrect data type for Feature Flag");\r |
06a19cee | 408 | return false;\r |
409 | }\r | |
410 | }\r | |
411 | \r | |
412 | return true;\r | |
413 | }\r | |
414 | \r | |
415 | private ProtocolsIdentification getCurrentProtocols() {\r | |
416 | String arg0 = this.jComboBoxCName.getSelectedItem().toString();\r | |
417 | String arg1 = this.jComboBoxProtocolType.getSelectedItem().toString();\r | |
418 | String arg2 = this.jComboBoxUsage.getSelectedItem().toString();\r | |
419 | \r | |
420 | String arg3 = this.jTextFieldFeatureFlag.getText();\r | |
421 | Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();\r | |
422 | String arg5 = this.jTextFieldHelpText.getText();\r | |
423 | id = new ProtocolsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r | |
424 | return id;\r | |
425 | }\r | |
426 | \r | |
427 | /* (non-Javadoc)\r | |
428 | * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)\r | |
429 | *\r | |
430 | * Reflesh the frame when selected item changed\r | |
431 | * \r | |
432 | */\r | |
433 | public void itemStateChanged(ItemEvent arg0) {\r | |
434 | if (arg0.getSource() == this.jComboBoxProtocolType && arg0.getStateChange() == ItemEvent.SELECTED) {\r | |
435 | if (this.jComboBoxProtocolType.getSelectedItem().toString().equals(ed.getVProtocolType().get(0))) {\r | |
436 | Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVProtocolUsage());\r | |
437 | } else {\r | |
438 | Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVProtocolNotifyUsage());\r | |
439 | }\r | |
440 | }\r | |
441 | }\r | |
442 | \r | |
443 | public ProtocolsIdentification getId() {\r | |
444 | return id;\r | |
445 | }\r | |
446 | \r | |
447 | public void setId(ProtocolsIdentification id) {\r | |
448 | this.id = id;\r | |
449 | }\r | |
450 | }\r |