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