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