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