]>
Commit | Line | Data |
---|---|---|
06a19cee | 1 | /** @file\r |
2 | \r | |
3 | The file is used to create, update Variable 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.util.Vector;\r | |
20 | \r | |
21 | import javax.swing.JButton;\r | |
22 | import javax.swing.JComboBox;\r | |
23 | import javax.swing.JLabel;\r | |
24 | import javax.swing.JPanel;\r | |
25 | import javax.swing.JScrollPane;\r | |
26 | import javax.swing.JTextField;\r | |
27 | \r | |
28 | import org.tianocore.frameworkwizard.common.DataType;\r | |
29 | import org.tianocore.frameworkwizard.common.DataValidation;\r | |
30 | import org.tianocore.frameworkwizard.common.EnumerationData;\r | |
31 | import org.tianocore.frameworkwizard.common.Log;\r | |
32 | import org.tianocore.frameworkwizard.common.Tools;\r | |
33 | import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;\r | |
34 | import org.tianocore.frameworkwizard.common.ui.IDialog;\r | |
35 | import org.tianocore.frameworkwizard.common.ui.IFrame;\r | |
36 | import org.tianocore.frameworkwizard.common.ui.StarLabel;\r | |
37 | import org.tianocore.frameworkwizard.module.Identifications.Variables.VariablesIdentification;\r | |
38 | import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r | |
39 | \r | |
40 | /**\r | |
41 | The class is used to create, update Variable of MSA/MBD file\r | |
42 | It extends IInternalFrame\r | |
43 | \r | |
44 | **/\r | |
45 | public class VariablesDlg extends IDialog {\r | |
46 | \r | |
47 | ///\r | |
48 | /// Define class Serial Version UID\r | |
49 | ///\r | |
50 | private static final long serialVersionUID = -6998982978030439446L;\r | |
51 | \r | |
52 | //\r | |
53 | //Define class members\r | |
54 | //\r | |
55 | private JPanel jContentPane = null;\r | |
56 | \r | |
57 | private JLabel jLabelVariableName = null;\r | |
58 | \r | |
59 | private JTextField jTextFieldVariableName = null;\r | |
60 | \r | |
61 | private JLabel jLabelUsage = null;\r | |
62 | \r | |
63 | private JComboBox jComboBoxUsage = null;\r | |
64 | \r | |
65 | private StarLabel jStarLabel1 = null;\r | |
66 | \r | |
67 | private StarLabel jStarLabel2 = null;\r | |
68 | \r | |
69 | private JScrollPane jScrollPane = null;\r | |
70 | \r | |
71 | private JLabel jLabelGuidCName = null;\r | |
72 | \r | |
73 | private JComboBox jComboBoxGuidC_Name = null;\r | |
74 | \r | |
75 | private JTextField jTextFieldFeatureFlag = null;\r | |
76 | \r | |
77 | private JLabel jLabelFeatureFlag = null;\r | |
78 | \r | |
79 | private JLabel jLabelArch = null;\r | |
80 | \r | |
81 | private JLabel jLabelHelpText = null;\r | |
82 | \r | |
83 | private JTextField jTextFieldHelpText = null;\r | |
84 | \r | |
85 | private ArchCheckBox jArchCheckBox = null;\r | |
86 | \r | |
87 | private JButton jButtonOk = null;\r | |
88 | \r | |
89 | private JButton jButtonCancel = null;\r | |
90 | \r | |
91 | //\r | |
92 | // Not used by UI\r | |
93 | //\r | |
94 | private VariablesIdentification id = null;\r | |
95 | \r | |
96 | private EnumerationData ed = new EnumerationData();\r | |
97 | \r | |
98 | private WorkspaceTools wt = new WorkspaceTools();\r | |
99 | \r | |
100 | /**\r | |
101 | This method initializes jTextFieldString \r | |
102 | \r | |
103 | @return javax.swing.JTextField jTextFieldString\r | |
104 | \r | |
105 | **/\r | |
106 | private JTextField getJTextFieldString() {\r | |
107 | if (jTextFieldVariableName == null) {\r | |
108 | jTextFieldVariableName = new JTextField();\r | |
109 | jTextFieldVariableName.setSize(new java.awt.Dimension(320, 20));\r | |
110 | jTextFieldVariableName.setPreferredSize(new java.awt.Dimension(320, 20));\r | |
111 | jTextFieldVariableName.setLocation(new java.awt.Point(160, 10));\r | |
112 | jTextFieldVariableName\r | |
f51ee52b | 113 | .setToolTipText("Enter a Hex Word Array, you must provide leading Zeros. 0x000a, 0x0010, 0x00FF");\r |
06a19cee | 114 | }\r |
115 | return jTextFieldVariableName;\r | |
116 | }\r | |
117 | \r | |
118 | /**\r | |
119 | This method initializes jComboBoxUsage \r | |
120 | \r | |
121 | @return javax.swing.JComboBox jComboBoxUsage\r | |
122 | \r | |
123 | **/\r | |
124 | private JComboBox getJComboBoxUsage() {\r | |
125 | if (jComboBoxUsage == null) {\r | |
126 | jComboBoxUsage = new JComboBox();\r | |
127 | jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 60, 320, 20));\r | |
128 | jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));\r | |
129 | }\r | |
130 | return jComboBoxUsage;\r | |
131 | }\r | |
132 | \r | |
133 | /**\r | |
134 | This method initializes jScrollPane \r | |
135 | \r | |
136 | @return javax.swing.JScrollPane \r | |
137 | */\r | |
138 | private JScrollPane getJScrollPane() {\r | |
139 | if (jScrollPane == null) {\r | |
140 | jScrollPane = new JScrollPane();\r | |
141 | jScrollPane.setViewportView(getJContentPane());\r | |
142 | }\r | |
143 | return jScrollPane;\r | |
144 | }\r | |
145 | \r | |
146 | /**\r | |
147 | This method initializes jTextFieldFeatureFlag \r | |
148 | \r | |
149 | @return javax.swing.JTextField jTextFieldFeatureFlag\r | |
150 | \r | |
151 | **/\r | |
152 | private JTextField getJTextFieldFeatureFlag() {\r | |
153 | if (jTextFieldFeatureFlag == null) {\r | |
154 | jTextFieldFeatureFlag = new JTextField();\r | |
155 | jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 110, 320, 20));\r | |
156 | jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));\r | |
157 | }\r | |
158 | return jTextFieldFeatureFlag;\r | |
159 | }\r | |
160 | \r | |
161 | /**\r | |
162 | This method initializes jTextFieldHelpText \r | |
163 | \r | |
164 | @return javax.swing.JTextField \r | |
165 | \r | |
166 | **/\r | |
167 | private JTextField getJTextFieldHelpText() {\r | |
168 | if (jTextFieldHelpText == null) {\r | |
169 | jTextFieldHelpText = new JTextField();\r | |
170 | jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 85, 320, 20));\r | |
171 | jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));\r | |
f51ee52b | 172 | jTextFieldHelpText.setToolTipText("Enter information on how to use this Variable.");\r |
06a19cee | 173 | }\r |
174 | return jTextFieldHelpText;\r | |
175 | }\r | |
176 | \r | |
177 | /**\r | |
178 | This method initializes jTextField \r | |
179 | \r | |
180 | @return javax.swing.JTextField jTextFieldC_Name\r | |
181 | \r | |
182 | **/\r | |
183 | private JComboBox getJComboBoxGuidC_Name() {\r | |
184 | if (jComboBoxGuidC_Name == null) {\r | |
185 | jComboBoxGuidC_Name = new JComboBox();\r | |
186 | jComboBoxGuidC_Name.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r | |
187 | jComboBoxGuidC_Name.setPreferredSize(new java.awt.Dimension(320, 20));\r | |
f51ee52b | 188 | jComboBoxGuidC_Name.setToolTipText("Select the GUID C Name of the Variable.");\r |
06a19cee | 189 | }\r |
190 | return jComboBoxGuidC_Name;\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("Variables");\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 inVariablesId\r | |
247 | \r | |
248 | **/\r | |
249 | private void init(VariablesIdentification inVariablesId) {\r | |
250 | init();\r | |
251 | this.id = inVariablesId;\r | |
252 | \r | |
253 | if (this.id != null) {\r | |
254 | this.jTextFieldVariableName.setText(id.getName());\r | |
255 | this.jComboBoxGuidC_Name.setSelectedItem(id.getGuid());\r | |
256 | this.jComboBoxUsage.setSelectedItem(id.getUsage());\r | |
257 | this.jTextFieldHelpText.setText(id.getHelp());\r | |
258 | this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());\r | |
259 | this.jArchCheckBox.setSelectedItems(id.getSupArchList());\r | |
260 | }\r | |
261 | }\r | |
262 | \r | |
263 | /**\r | |
264 | This is the override edit constructor\r | |
265 | \r | |
f51ee52b | 266 | @param inVariablesIdentification\r |
06a19cee | 267 | @param iFrame\r |
268 | \r | |
269 | **/\r | |
270 | public VariablesDlg(VariablesIdentification inVariablesIdentification, IFrame iFrame) {\r | |
271 | super(iFrame, true);\r | |
272 | init(inVariablesIdentification);\r | |
273 | }\r | |
274 | \r | |
275 | /**\r | |
276 | Disable all components when the mode is view\r | |
277 | \r | |
278 | @param isView true - The view mode; false - The non-view mode\r | |
279 | \r | |
280 | **/\r | |
281 | public void setViewMode(boolean isView) {\r | |
282 | if (isView) {\r | |
283 | this.jTextFieldVariableName.setEnabled(!isView);\r | |
284 | this.jComboBoxUsage.setEnabled(!isView);\r | |
285 | }\r | |
286 | }\r | |
287 | \r | |
288 | /**\r | |
289 | This method initializes jContentPane\r | |
290 | \r | |
291 | @return javax.swing.JPanel jContentPane\r | |
292 | \r | |
293 | **/\r | |
294 | private JPanel getJContentPane() {\r | |
295 | if (jContentPane == null) {\r | |
296 | jArchCheckBox = new ArchCheckBox();\r | |
297 | jArchCheckBox.setBounds(new java.awt.Rectangle(160, 135, 320, 20));\r | |
298 | jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));\r | |
299 | jLabelGuidCName = new JLabel();\r | |
300 | jLabelGuidCName.setBounds(new java.awt.Rectangle(15, 35, 140, 20));\r | |
f51ee52b | 301 | jLabelGuidCName.setText("Guid C Name");\r |
06a19cee | 302 | jLabelUsage = new JLabel();\r |
303 | jLabelUsage.setText("Usage");\r | |
304 | jLabelUsage.setBounds(new java.awt.Rectangle(15, 60, 140, 20));\r | |
305 | jLabelVariableName = new JLabel();\r | |
306 | jLabelVariableName.setText("Variable Name");\r | |
307 | jLabelVariableName.setLocation(new java.awt.Point(15, 10));\r | |
308 | jLabelVariableName.setSize(new java.awt.Dimension(140, 20));\r | |
309 | jLabelArch = new JLabel();\r | |
310 | jLabelArch.setBounds(new java.awt.Rectangle(15, 135, 140, 20));\r | |
311 | jLabelArch.setText("Arch");\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 | \r | |
316 | jContentPane = new JPanel();\r | |
317 | jContentPane.setLayout(null);\r | |
318 | jContentPane.setPreferredSize(new java.awt.Dimension(490, 190));\r | |
319 | \r | |
320 | jContentPane.add(jLabelVariableName, null);\r | |
321 | jContentPane.add(jLabelGuidCName, null);\r | |
322 | jContentPane.add(getJComboBoxGuidC_Name(), null);\r | |
323 | jContentPane.add(getJTextFieldString(), null);\r | |
324 | jContentPane.add(jLabelUsage, null);\r | |
325 | jContentPane.add(getJComboBoxUsage(), null);\r | |
326 | jStarLabel1 = new StarLabel();\r | |
327 | jStarLabel1.setLocation(new java.awt.Point(0, 10));\r | |
328 | jStarLabel2 = new StarLabel();\r | |
329 | jStarLabel2.setLocation(new java.awt.Point(0, 35));\r | |
330 | jLabelHelpText = new JLabel();\r | |
331 | jLabelHelpText.setBounds(new java.awt.Rectangle(14, 85, 140, 20));\r | |
332 | jLabelHelpText.setText("Help Text");\r | |
333 | \r | |
334 | jContentPane.add(jStarLabel1, null);\r | |
335 | jContentPane.add(jStarLabel2, null);\r | |
336 | \r | |
337 | jContentPane.add(jLabelArch, null);\r | |
338 | jContentPane.add(jLabelFeatureFlag, null);\r | |
339 | jContentPane.add(getJTextFieldFeatureFlag(), 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 | /* (non-Javadoc)\r | |
350 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r | |
351 | *\r | |
352 | * Override actionPerformed to listen all actions\r | |
353 | * \r | |
354 | */\r | |
355 | public void actionPerformed(ActionEvent arg0) {\r | |
356 | if (arg0.getSource() == jButtonOk) {\r | |
357 | if (checkAdd()) {\r | |
358 | getCurrentVariables();\r | |
359 | this.returnType = DataType.RETURN_TYPE_OK;\r | |
360 | this.setVisible(false);\r | |
361 | }\r | |
362 | }\r | |
363 | \r | |
364 | if (arg0.getSource() == jButtonCancel) {\r | |
365 | this.returnType = DataType.RETURN_TYPE_CANCEL;\r | |
366 | this.setVisible(false);\r | |
367 | }\r | |
368 | }\r | |
369 | \r | |
370 | /**\r | |
371 | This method initializes Usage type\r | |
372 | \r | |
373 | **/\r | |
374 | private void initFrame() {\r | |
375 | Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPpiUsage());\r | |
376 | Tools.generateComboBoxByVector(jComboBoxGuidC_Name, wt.getAllGuidDeclarationsFromWorkspace());\r | |
377 | }\r | |
378 | \r | |
379 | /**\r | |
380 | Data validation for all fields\r | |
381 | \r | |
382 | @retval true - All datas are valid\r | |
383 | @retval false - At least one data is invalid\r | |
384 | \r | |
385 | **/\r | |
386 | public boolean checkAdd() {\r | |
387 | //\r | |
388 | // Check if all fields have correct data types \r | |
389 | //\r | |
390 | \r | |
391 | //\r | |
392 | // Check VariableName \r | |
393 | //\r | |
394 | if (isEmpty(this.jTextFieldVariableName.getText())) {\r | |
ed1665f2 | 395 | Log.wrn("Update Variables", "Variable Name couldn't be empty");\r |
06a19cee | 396 | return false;\r |
397 | }\r | |
398 | \r | |
399 | if (!isEmpty(this.jTextFieldVariableName.getText())) {\r | |
400 | if (!DataValidation.isHexWordArrayType(this.jTextFieldVariableName.getText())) {\r | |
ed1665f2 | 401 | Log.wrn("Update Variables", "Incorrect data type for Variable Name");\r |
06a19cee | 402 | return false;\r |
403 | }\r | |
404 | }\r | |
405 | \r | |
406 | //\r | |
407 | // Check FeatureFlag\r | |
408 | //\r | |
409 | if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r | |
410 | if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r | |
ed1665f2 | 411 | Log.wrn("Update Variables", "Incorrect data type for Feature Flag");\r |
06a19cee | 412 | return false;\r |
413 | }\r | |
414 | }\r | |
415 | \r | |
416 | return true;\r | |
417 | }\r | |
418 | \r | |
419 | private VariablesIdentification getCurrentVariables() {\r | |
420 | String arg0 = this.jTextFieldVariableName.getText();\r | |
421 | String arg1 = this.jComboBoxGuidC_Name.getSelectedItem().toString();\r | |
422 | String arg2 = this.jComboBoxUsage.getSelectedItem().toString();\r | |
423 | \r | |
424 | String arg3 = this.jTextFieldFeatureFlag.getText();\r | |
425 | Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();\r | |
426 | String arg5 = this.jTextFieldHelpText.getText();\r | |
427 | \r | |
428 | id = new VariablesIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r | |
429 | return id;\r | |
430 | }\r | |
431 | \r | |
432 | public VariablesIdentification getId() {\r | |
433 | return id;\r | |
434 | }\r | |
435 | \r | |
436 | public void setId(VariablesIdentification id) {\r | |
437 | this.id = id;\r | |
438 | }\r | |
439 | }\r |