]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/HiiPackagesDlg.java
1997ab4c8a68f12f558f5358ef0c74e85f80fa97
[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 Formset of MSA/MBD 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(160, 10, 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(160, 35, 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(160, 105, 320, 20));
144 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
145 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
146 }
147 return jTextFieldFeatureFlag;
148 }
149
150 /**
151 *
152 * This method initializes jScrollPane
153 *
154 * @return javax.swing.JScrollPane
155 *
156 */
157 private JScrollPane getJScrollPane() {
158 if (jScrollPane == null) {
159 jScrollPane = new JScrollPane();
160 jScrollPane.setViewportView(getJContentPane());
161 }
162 return jScrollPane;
163 }
164
165 /**
166 *
167 * This method initializes jTextAreaHelpText
168 *
169 * @return javax.swing.JTextArea jTextAreaHelpText
170 *
171 */
172 private JTextArea getJTextAreaHelpText() {
173 if (jTextAreaHelpText == null) {
174 jTextAreaHelpText = new JTextArea();
175 jTextAreaHelpText.setLineWrap(true);
176 jTextAreaHelpText.setWrapStyleWord(true);
177 }
178 return jTextAreaHelpText;
179 }
180
181 /**
182 *
183 * This method initializes jScrollPaneHelpText
184 *
185 * @return javax.swing.JScrollPane
186 *
187 */
188 private JScrollPane getJScrollPaneHelpText() {
189 if (jScrollPaneHelpText == null) {
190 jScrollPaneHelpText = new JScrollPane();
191 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
192 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));
193 jScrollPaneHelpText.setPreferredSize(new java.awt.Dimension(320, 40));
194 jScrollPaneHelpText.setLocation(new java.awt.Point(160, 60));
195 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
196 }
197 return jScrollPaneHelpText;
198 }
199
200 /**
201 *
202 * This method initializes jButtonOk
203 *
204 * @return javax.swing.JButton
205 *
206 */
207 private JButton getJButtonOk() {
208 if (jButtonOk == null) {
209 jButtonOk = new JButton();
210 jButtonOk.setBounds(new java.awt.Rectangle(290, 157, 90, 20));
211 jButtonOk.setText("Ok");
212 jButtonOk.addActionListener(this);
213 }
214 return jButtonOk;
215 }
216
217 /**
218 *
219 * This method initializes jButtonCancel
220 *
221 * @return javax.swing.JButton
222 *
223 **/
224 private JButton getJButtonCancel() {
225 if (jButtonCancel == null) {
226 jButtonCancel = new JButton();
227 jButtonCancel.setBounds(new java.awt.Rectangle(390, 157, 90, 20));
228 jButtonCancel.setText("Cancel");
229 jButtonCancel.addActionListener(this);
230 }
231 return jButtonCancel;
232 }
233
234 public static void main(String[] args) {
235
236 }
237
238 /**
239 *
240 * This method initializes this
241 *
242 **/
243 private void init() {
244 this.setSize(500, 230);
245 this.setContentPane(getJScrollPane());
246 this.setTitle("Hii Packages");
247 initFrame();
248 this.setViewMode(false);
249 this.centerWindow();
250 }
251
252 /**
253 * This method initializes this Fill values to all fields if these values are
254 * not empty
255 *
256 * @param inHiiPackagesId
257 *
258 **/
259 private void init(HiiPackagesIdentification inHiiPackagesId) {
260 init();
261 this.id = inHiiPackagesId;
262
263 if (this.id != null) {
264 this.jTextFieldName.setText(id.getName());
265 this.jComboBoxUsage.setSelectedItem(id.getUsage());
266 this.jTextAreaHelpText.setText(id.getHelp());
267 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
268 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
269 }
270 }
271
272 /**
273 * This is the override edit constructor
274 *
275 * @param inHiiPackagesIdentification
276 * @param iFrame
277 *
278 **/
279 public HiiPackagesDlg(HiiPackagesIdentification inHiiPackagesIdentification, IFrame iFrame) {
280 super(iFrame, true);
281 init(inHiiPackagesIdentification);
282 }
283
284 /**
285 *
286 * Disable all components when the mode is view
287 *
288 * @param isView
289 * true - The view mode; false - The non-view mode
290 *
291 **/
292 public void setViewMode(boolean isView) {
293 if (isView) {
294 this.jTextFieldName.setEnabled(!isView);
295 this.jComboBoxUsage.setEnabled(!isView);
296 }
297 }
298
299 /**
300 *
301 * This method initializes jContentPane
302 *
303 * @return javax.swing.JPanel jContentPane
304 *
305 */
306 private JPanel getJContentPane() {
307 if (jContentPane == null) {
308 jStarLabel1 = new StarLabel();
309 jStarLabel1.setLocation(new java.awt.Point(2, 10));
310 jLabelName = new JLabel();
311 jLabelName.setText("Hii Package C Name");
312 jLabelName.setBounds(new java.awt.Rectangle(15, 10, 145, 20));
313 jStarLabel2 = new StarLabel();
314 jStarLabel2.setLocation(new java.awt.Point(2, 35));
315 jLabelUsage = new JLabel();
316 jLabelUsage.setText("Usage");
317 jLabelUsage.setBounds(new java.awt.Rectangle(15, 35, 145, 20));
318 jLabelHelpText = new JLabel();
319 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 60, 145, 20));
320 jLabelHelpText.setText("Help Text");
321 jLabelFeatureFlag = new JLabel();
322 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 105, 145, 20));
323 jLabelFeatureFlag.setText("Feature Flag Expression");
324 jLabelArch = new JLabel();
325 jLabelArch.setBounds(new java.awt.Rectangle(15, 130, 145, 20));
326 jLabelArch.setText("Supported Architectures");
327 jArchCheckBox = new ArchCheckBox();
328 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 130, 320, 20));
329 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
330
331 jContentPane = new JPanel();
332 jContentPane.setLayout(null);
333 jContentPane.setPreferredSize(new java.awt.Dimension(485, 185));
334
335 jContentPane.add(jStarLabel1, null);
336 jContentPane.add(jLabelName, null);
337 jContentPane.add(getJTextFieldName(), null);
338
339 jContentPane.add(jStarLabel2, null);
340 jContentPane.add(jLabelUsage, null);
341 jContentPane.add(getJComboBoxUsage(), null);
342
343 jContentPane.add(jLabelHelpText, null);
344 jContentPane.add(getJScrollPaneHelpText(), null);
345
346 jContentPane.add(jLabelFeatureFlag, null);
347 jContentPane.add(getJTextFieldFeatureFlag(), null);
348
349 jContentPane.add(jLabelArch, null);
350 jContentPane.add(jArchCheckBox, null);
351
352 jContentPane.add(getJButtonOk(), null);
353 jContentPane.add(getJButtonCancel(), null);
354 }
355 return jContentPane;
356 }
357
358 /**
359 *
360 * This method initializes Usage type
361 *
362 */
363 private void initFrame() {
364 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVHiiPackageUsage());
365 }
366
367 /*
368 * (non-Javadoc)
369 *
370 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
371 *
372 * Override actionPerformed to listen all actions
373 *
374 */
375 public void actionPerformed(ActionEvent arg0) {
376 if (arg0.getSource() == jButtonOk) {
377 if (checkAdd()) {
378 getCurrentHiiPackages();
379 this.returnType = DataType.RETURN_TYPE_OK;
380 this.setVisible(false);
381 }
382 }
383
384 if (arg0.getSource() == jButtonCancel) {
385 this.returnType = DataType.RETURN_TYPE_CANCEL;
386 this.setVisible(false);
387 }
388 }
389
390 /**
391 *
392 * Data validation for all fields
393 *
394 * @retval true - All datas are valid
395 * @retval false - At least one data is invalid
396 *
397 */
398 public boolean checkAdd() {
399 //
400 // Check if all fields have correct data types
401 //
402
403 //
404 // Check Hii Package Name
405 //
406 if (isEmpty(this.jTextFieldName.getText())) {
407 Log.wrn("Update Hii Packages", "Hii Package Name Record must not be empty");
408 return false;
409 }
410
411 if (!isEmpty(this.jTextFieldName.getText())) {
412 if (!DataValidation.isC_NameType(this.jTextFieldName.getText())) {
413 Log.wrn("Update Hii Packages", "Incorrect data type for Hii Package Name");
414 return false;
415 }
416 }
417
418 //
419 // Check FeatureFlag
420 //
421 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
422 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
423 Log.wrn("Update Hii Packages", "Incorrect data type for Feature Flag");
424 return false;
425 }
426 }
427
428 return true;
429 }
430
431 private HiiPackagesIdentification getCurrentHiiPackages() {
432 String arg0 = this.jTextFieldName.getText();
433 String arg1 = this.jComboBoxUsage.getSelectedItem().toString();
434
435 String arg2 = this.jTextFieldFeatureFlag.getText();
436 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
437 String arg4 = this.jTextAreaHelpText.getText();
438
439 id = new HiiPackagesIdentification(arg0, arg1, arg2, arg3, arg4);
440 return id;
441 }
442
443 public HiiPackagesIdentification getId() {
444 return id;
445 }
446
447 public void setId(HiiPackagesIdentification id) {
448 this.id = id;
449 }
450 }