]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/HiiPackagesDlg.java
Fixed grammar in messages.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / HiiPackagesDlg.java
... / ...
CommitLineData
1/** @file\r
2 \r
3 The file is used to create, update Hii Packages section of the MSA 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
15package org.tianocore.frameworkwizard.module.ui.dialog;\r
16\r
17import java.awt.event.ActionEvent;\r
18import java.util.Vector;\r
19\r
20import javax.swing.JButton;\r
21import javax.swing.JComboBox;\r
22import javax.swing.JLabel;\r
23import javax.swing.JPanel;\r
24import javax.swing.JScrollPane;\r
25import javax.swing.JTextField;\r
26import javax.swing.JTextArea;\r
27\r
28import org.tianocore.frameworkwizard.common.DataType;\r
29import org.tianocore.frameworkwizard.common.DataValidation;\r
30import org.tianocore.frameworkwizard.common.EnumerationData;\r
31import org.tianocore.frameworkwizard.common.Log;\r
32import org.tianocore.frameworkwizard.common.Tools;\r
33import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;\r
34import org.tianocore.frameworkwizard.common.ui.IDialog;\r
35import org.tianocore.frameworkwizard.common.ui.IFrame;\r
36import org.tianocore.frameworkwizard.common.ui.StarLabel;\r
37import org.tianocore.frameworkwizard.module.Identifications.HiiPackages.HiiPackagesIdentification;\r
38\r
39/**\r
40 * The class is used to create, update Hii Packages of the MSA file\r
41 * \r
42 * It extends IDialog\r
43 * \r
44 */\r
45public class HiiPackagesDlg extends IDialog {\r
46\r
47 // /\r
48 // / Define class Serial Version UID\r
49 // /\r
50 private static final long serialVersionUID = -6851574146786158116L;\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 JTextField jTextFieldName = 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 JLabel jLabelFeatureFlag = null;\r
70\r
71 private JTextField jTextFieldFeatureFlag = null;\r
72\r
73 private JLabel jLabelArch = null;\r
74\r
75 private JScrollPane jScrollPane = null;\r
76\r
77 private JLabel jLabelHelpText = null;\r
78\r
79 private JTextArea jTextAreaHelpText = null;\r
80\r
81 private JScrollPane jScrollPaneHelpText = null;\r
82\r
83 private ArchCheckBox jArchCheckBox = null;\r
84\r
85 private JButton jButtonOk = null;\r
86\r
87 private JButton jButtonCancel = null;\r
88\r
89 //\r
90 // Not used by UI\r
91 //\r
92 private HiiPackagesIdentification id = null;\r
93\r
94 private EnumerationData ed = new EnumerationData();\r
95\r
96 /**\r
97 * \r
98 * This method initializes jTextFieldName\r
99 * \r
100 * @return javax.swing.JTextField jTextFieldName\r
101 * \r
102 */\r
103 private JTextField getJTextFieldName() {\r
104 if (jTextFieldName == null) {\r
105 jTextFieldName = new JTextField();\r
106 jTextFieldName.setBounds(new java.awt.Rectangle(168, 12, 320, 20));\r
107 jTextFieldName.setPreferredSize(new java.awt.Dimension(320, 20));\r
108 jTextFieldName.setToolTipText("Enter the C Name of the HII Package");\r
109 }\r
110 return jTextFieldName;\r
111 }\r
112\r
113 /**\r
114 * \r
115 * This method initializes jComboBoxUsage\r
116 * \r
117 * @return javax.swing.JComboBox jComboBoxUsage\r
118 * \r
119 */\r
120 private JComboBox getJComboBoxUsage() {\r
121 if (jComboBoxUsage == null) {\r
122 jComboBoxUsage = new JComboBox();\r
123 jComboBoxUsage.setBounds(new java.awt.Rectangle(168, 37, 320, 20));\r
124 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));\r
125 jComboBoxUsage\r
126 .setToolTipText("<html><table>"\r
127 + "<tr><td>ALWAYS_PRODUCED</td><td>Hii is always registered</td></tr>"\r
128 + "<tr><td>SOMETIMES_PRODUCED</td><td>Some executions paths will require the Hii to be registered</td></tr>"\r
129 + "</table></html>");\r
130 }\r
131 return jComboBoxUsage;\r
132 }\r
133\r
134 /**\r
135 * \r
136 * This method initializes jTextFieldFeatureFlag\r
137 * \r
138 * @return javax.swing.JTextField\r
139 */\r
140 private JTextField getJTextFieldFeatureFlag() {\r
141 if (jTextFieldFeatureFlag == null) {\r
142 jTextFieldFeatureFlag = new JTextField();\r
143 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(168, 132, 320, 20));\r
144 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));\r
145 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");\r
146 jTextFieldFeatureFlag.setEnabled(false);\r
147 }\r
148 return jTextFieldFeatureFlag;\r
149 }\r
150\r
151 /**\r
152 * \r
153 * This method initializes jScrollPane\r
154 * \r
155 * @return javax.swing.JScrollPane\r
156 * \r
157 */\r
158 private JScrollPane getJScrollPane() {\r
159 if (jScrollPane == null) {\r
160 jScrollPane = new JScrollPane();\r
161 jScrollPane.setViewportView(getJContentPane());\r
162 }\r
163 return jScrollPane;\r
164 }\r
165\r
166 /**\r
167 * \r
168 * This method initializes jTextAreaHelpText\r
169 * \r
170 * @return javax.swing.JTextArea jTextAreaHelpText\r
171 * \r
172 */\r
173 private JTextArea getJTextAreaHelpText() {\r
174 if (jTextAreaHelpText == null) {\r
175 jTextAreaHelpText = new JTextArea();\r
176 jTextAreaHelpText.setLineWrap(true);\r
177 jTextAreaHelpText.setWrapStyleWord(true);\r
178 }\r
179 return jTextAreaHelpText;\r
180 }\r
181\r
182 /**\r
183 * \r
184 * This method initializes jScrollPaneHelpText\r
185 * \r
186 * @return javax.swing.JScrollPane\r
187 * \r
188 */\r
189 private JScrollPane getJScrollPaneHelpText() {\r
190 if (jScrollPaneHelpText == null) {\r
191 jScrollPaneHelpText = new JScrollPane();\r
192 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);\r
193 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));\r
194 jScrollPaneHelpText.setPreferredSize(new java.awt.Dimension(320, 40));\r
195 jScrollPaneHelpText.setLocation(new java.awt.Point(168, 62));\r
196 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());\r
197 }\r
198 return jScrollPaneHelpText;\r
199 }\r
200\r
201 /**\r
202 * \r
203 * This method initializes jButtonOk\r
204 * \r
205 * @return javax.swing.JButton\r
206 * \r
207 */\r
208 private JButton getJButtonOk() {\r
209 if (jButtonOk == null) {\r
210 jButtonOk = new JButton();\r
211 jButtonOk.setBounds(new java.awt.Rectangle(290, 162, 90, 20));\r
212 jButtonOk.setText("Ok");\r
213 jButtonOk.addActionListener(this);\r
214 }\r
215 return jButtonOk;\r
216 }\r
217\r
218 /**\r
219 *\r
220 * This method initializes jButtonCancel\r
221 * \r
222 * @return javax.swing.JButton\r
223 * \r
224 **/\r
225 private JButton getJButtonCancel() {\r
226 if (jButtonCancel == null) {\r
227 jButtonCancel = new JButton();\r
228 jButtonCancel.setBounds(new java.awt.Rectangle(390, 162, 90, 20));\r
229 jButtonCancel.setText("Cancel");\r
230 jButtonCancel.addActionListener(this);\r
231 }\r
232 return jButtonCancel;\r
233 }\r
234\r
235 public static void main(String[] args) {\r
236\r
237 }\r
238\r
239 /**\r
240 * \r
241 * This method initializes this\r
242 * \r
243 **/\r
244 private void init() {\r
245 this.setSize(505, 235);\r
246 this.setContentPane(getJScrollPane());\r
247 this.setTitle("Hii Packages");\r
248 initFrame();\r
249 this.setViewMode(false);\r
250 this.centerWindow();\r
251 }\r
252\r
253 /**\r
254 * This method initializes this Fill values to all fields if these values are\r
255 * not empty\r
256 * \r
257 * @param inHiiPackagesId\r
258 * \r
259 **/\r
260 private void init(HiiPackagesIdentification inHiiPackagesId) {\r
261 init();\r
262 this.id = inHiiPackagesId;\r
263\r
264 if (this.id != null) {\r
265 this.jTextFieldName.setText(id.getName());\r
266 this.jComboBoxUsage.setSelectedItem(id.getUsage());\r
267 this.jTextAreaHelpText.setText(id.getHelp());\r
268 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());\r
269 this.jArchCheckBox.setSelectedItems(id.getSupArchList());\r
270 }\r
271 }\r
272\r
273 /**\r
274 * This is the override edit constructor\r
275 * \r
276 * @param inHiiPackagesIdentification\r
277 * @param iFrame\r
278 * \r
279 **/\r
280 public HiiPackagesDlg(HiiPackagesIdentification inHiiPackagesIdentification, IFrame iFrame) {\r
281 super(iFrame, true);\r
282 init(inHiiPackagesIdentification);\r
283 }\r
284\r
285 /**\r
286 * \r
287 * Disable all components when the mode is view\r
288 * \r
289 * @param isView\r
290 * true - The view mode; false - The non-view mode\r
291 * \r
292 **/\r
293 public void setViewMode(boolean isView) {\r
294 if (isView) {\r
295 this.jTextFieldName.setEnabled(!isView);\r
296 this.jComboBoxUsage.setEnabled(!isView);\r
297 }\r
298 }\r
299\r
300 /**\r
301 * \r
302 * This method initializes jContentPane\r
303 * \r
304 * @return javax.swing.JPanel jContentPane\r
305 * \r
306 */\r
307 private JPanel getJContentPane() {\r
308 if (jContentPane == null) {\r
309 jStarLabel1 = new StarLabel();\r
310 jStarLabel1.setLocation(new java.awt.Point(2, 12));\r
311 jLabelName = new JLabel();\r
312 jLabelName.setText("Hii Package C Name");\r
313 jLabelName.setBounds(new java.awt.Rectangle(12, 12, 155, 20));\r
314 jStarLabel2 = new StarLabel();\r
315 jStarLabel2.setLocation(new java.awt.Point(2, 37));\r
316 jLabelUsage = new JLabel();\r
317 jLabelUsage.setText("Usage");\r
318 jLabelUsage.setBounds(new java.awt.Rectangle(12, 37, 155, 20));\r
319 jLabelHelpText = new JLabel();\r
320 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 62, 155, 20));\r
321 jLabelHelpText.setText("Help Text");\r
322 jLabelFeatureFlag = new JLabel();\r
323 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 132, 155, 20));\r
324 jLabelFeatureFlag.setText("Feature Flag Expression");\r
325 jLabelFeatureFlag.setEnabled(false);\r
326 jLabelArch = new JLabel();\r
327 jLabelArch.setBounds(new java.awt.Rectangle(12, 107, 155, 20));\r
328 jLabelArch.setText("Supported Architectures");\r
329 jArchCheckBox = new ArchCheckBox();\r
330 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 107, 320, 20));\r
331 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));\r
332\r
333 jContentPane = new JPanel();\r
334 jContentPane.setLayout(null);\r
335 jContentPane.setPreferredSize(new java.awt.Dimension(480, 180));\r
336\r
337 jContentPane.add(jStarLabel1, null);\r
338 jContentPane.add(jLabelName, null);\r
339 jContentPane.add(getJTextFieldName(), null);\r
340\r
341 jContentPane.add(jStarLabel2, null);\r
342 jContentPane.add(jLabelUsage, null);\r
343 jContentPane.add(getJComboBoxUsage(), null);\r
344\r
345 jContentPane.add(jLabelHelpText, null);\r
346 jContentPane.add(getJScrollPaneHelpText(), null);\r
347\r
348 jContentPane.add(jLabelFeatureFlag, null);\r
349 jContentPane.add(getJTextFieldFeatureFlag(), null);\r
350\r
351 jContentPane.add(jLabelArch, null);\r
352 jContentPane.add(jArchCheckBox, null);\r
353\r
354 jContentPane.add(getJButtonOk(), null);\r
355 jContentPane.add(getJButtonCancel(), null);\r
356 }\r
357 return jContentPane;\r
358 }\r
359\r
360 /**\r
361 * \r
362 * This method initializes Usage type\r
363 * \r
364 */\r
365 private void initFrame() {\r
366 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVHiiPackageUsage());\r
367 }\r
368\r
369 /*\r
370 * (non-Javadoc)\r
371 * \r
372 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
373 * \r
374 * Override actionPerformed to listen all actions\r
375 * \r
376 */\r
377 public void actionPerformed(ActionEvent arg0) {\r
378 if (arg0.getSource() == jButtonOk) {\r
379 if (checkAdd()) {\r
380 getCurrentHiiPackages();\r
381 this.returnType = DataType.RETURN_TYPE_OK;\r
382 this.setVisible(false);\r
383 }\r
384 }\r
385\r
386 if (arg0.getSource() == jButtonCancel) {\r
387 this.returnType = DataType.RETURN_TYPE_CANCEL;\r
388 this.setVisible(false);\r
389 }\r
390 }\r
391\r
392 /**\r
393 * \r
394 * Data validation for all fields\r
395 * \r
396 * @retval true - All datas are valid\r
397 * @retval false - At least one data is invalid\r
398 * \r
399 */\r
400 public boolean checkAdd() {\r
401 //\r
402 // Check if all fields have correct data types\r
403 //\r
404\r
405 //\r
406 // Check Hii Package Name\r
407 //\r
408 if (isEmpty(this.jTextFieldName.getText())) {\r
409 Log.wrn("Update Hii Packages", "Hii Package Name Record must be entered!");\r
410 return false;\r
411 }\r
412\r
413 if (!isEmpty(this.jTextFieldName.getText())) {\r
414 if (!DataValidation.isC_NameType(this.jTextFieldName.getText())) {\r
415 Log.wrn("Update Hii Packages", "Incorrect data type for Hii Package Name");\r
416 return false;\r
417 }\r
418 }\r
419\r
420 //\r
421 // Check FeatureFlag\r
422 //\r
423 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r
424 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r
425 Log.wrn("Update Hii Packages", "Incorrect data type for Feature Flag");\r
426 return false;\r
427 }\r
428 }\r
429\r
430 return true;\r
431 }\r
432\r
433 private HiiPackagesIdentification getCurrentHiiPackages() {\r
434 String arg0 = this.jTextFieldName.getText();\r
435 String arg1 = this.jComboBoxUsage.getSelectedItem().toString();\r
436\r
437 String arg2 = this.jTextFieldFeatureFlag.getText();\r
438 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();\r
439 String arg4 = this.jTextAreaHelpText.getText();\r
440\r
441 id = new HiiPackagesIdentification(arg0, arg1, arg2, arg3, arg4);\r
442 return id;\r
443 }\r
444\r
445 public HiiPackagesIdentification getId() {\r
446 return id;\r
447 }\r
448\r
449 public void setId(HiiPackagesIdentification id) {\r
450 this.id = id;\r
451 }\r
452}\r