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