]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/HiiPackagesDlg.java
Use table and popup window to add/edit all elements of module instead of original...
[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
27 import org.tianocore.frameworkwizard.common.DataType;
28 import org.tianocore.frameworkwizard.common.DataValidation;
29 import org.tianocore.frameworkwizard.common.EnumerationData;
30 import org.tianocore.frameworkwizard.common.Log;
31 import org.tianocore.frameworkwizard.common.Tools;
32 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
33 import org.tianocore.frameworkwizard.common.ui.IDialog;
34 import org.tianocore.frameworkwizard.common.ui.IFrame;
35 import org.tianocore.frameworkwizard.common.ui.StarLabel;
36 import org.tianocore.frameworkwizard.module.Identifications.HiiPackages.HiiPackagesIdentification;
37
38 /**
39 The class is used to create, update Formset of MSA/MBD file
40 It extends IInternalFrame
41
42
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 JTextField jTextFieldHelpText = null;
80
81 private ArchCheckBox jArchCheckBox = null;
82
83 private JButton jButtonOk = null;
84
85 private JButton jButtonCancel = null;
86
87 //
88 // Not used by UI
89 //
90 private HiiPackagesIdentification id = null;
91
92 private EnumerationData ed = new EnumerationData();
93
94 /**
95 This method initializes jTextFieldName
96
97 @return javax.swing.JTextField jTextFieldName
98
99 **/
100 private JTextField getJTextFieldName() {
101 if (jTextFieldName == null) {
102 jTextFieldName = new JTextField();
103 jTextFieldName.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
104 jTextFieldName.setPreferredSize(new java.awt.Dimension(320, 20));
105 jTextFieldName.setToolTipText("Enter the C Name of the HII Package");
106 }
107 return jTextFieldName;
108 }
109
110 /**
111 This method initializes jComboBoxUsage
112
113 @return javax.swing.JComboBox jComboBoxUsage
114
115 **/
116 private JComboBox getJComboBoxUsage() {
117 if (jComboBoxUsage == null) {
118 jComboBoxUsage = new JComboBox();
119 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
120 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
121 }
122 return jComboBoxUsage;
123 }
124
125 /**
126 * This method initializes jTextFieldFeatureFlag
127 *
128 * @return javax.swing.JTextField
129 */
130 private JTextField getJTextFieldFeatureFlag() {
131 if (jTextFieldFeatureFlag == null) {
132 jTextFieldFeatureFlag = new JTextField();
133 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
134 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
135 }
136 return jTextFieldFeatureFlag;
137 }
138
139 /**
140 This method initializes jScrollPane
141
142 @return javax.swing.JScrollPane
143 */
144 private JScrollPane getJScrollPane() {
145 if (jScrollPane == null) {
146 jScrollPane = new JScrollPane();
147 jScrollPane.setViewportView(getJContentPane());
148 }
149 return jScrollPane;
150 }
151
152 /**
153 This method initializes jTextFieldHelpText
154
155 @return javax.swing.JTextField
156
157 **/
158 private JTextField getJTextFieldHelpText() {
159 if (jTextFieldHelpText == null) {
160 jTextFieldHelpText = new JTextField();
161 jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
162 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));
163 }
164 return jTextFieldHelpText;
165 }
166
167 /**
168 This method initializes jButtonOk
169
170 @return javax.swing.JButton
171
172 **/
173 private JButton getJButtonOk() {
174 if (jButtonOk == null) {
175 jButtonOk = new JButton();
176 jButtonOk.setBounds(new java.awt.Rectangle(290, 140, 90, 20));
177 jButtonOk.setText("Ok");
178 jButtonOk.addActionListener(this);
179 }
180 return jButtonOk;
181 }
182
183 /**
184 This method initializes jButtonCancel
185
186 @return javax.swing.JButton
187
188 **/
189 private JButton getJButtonCancel() {
190 if (jButtonCancel == null) {
191 jButtonCancel = new JButton();
192 jButtonCancel.setBounds(new java.awt.Rectangle(390, 140, 90, 20));
193 jButtonCancel.setText("Cancel");
194 jButtonCancel.addActionListener(this);
195 }
196 return jButtonCancel;
197 }
198
199 public static void main(String[] args) {
200
201 }
202
203 /**
204 This method initializes this
205
206 **/
207 private void init() {
208 this.setSize(500, 200);
209 this.setContentPane(getJScrollPane());
210 this.setTitle("Hii Packages");
211 initFrame();
212 this.setViewMode(false);
213 this.centerWindow();
214 }
215
216 /**
217 This method initializes this
218 Fill values to all fields if these values are not empty
219
220 @param inHiiPackagesId
221
222 **/
223 private void init(HiiPackagesIdentification inHiiPackagesId) {
224 init();
225 this.id = inHiiPackagesId;
226
227 if (this.id != null) {
228 this.jTextFieldName.setText(id.getName());
229 this.jComboBoxUsage.setSelectedItem(id.getUsage());
230 this.jTextFieldHelpText.setText(id.getHelp());
231 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
232 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
233 }
234 }
235
236 /**
237 This is the override edit constructor
238
239 @param inHiiPackagesIdentification
240 @param iFrame
241
242 **/
243 public HiiPackagesDlg(HiiPackagesIdentification inHiiPackagesIdentification, IFrame iFrame) {
244 super(iFrame, true);
245 init(inHiiPackagesIdentification);
246 }
247
248 /**
249 Disable all components when the mode is view
250
251 @param isView true - The view mode; false - The non-view mode
252
253 **/
254 public void setViewMode(boolean isView) {
255 if (isView) {
256 this.jTextFieldName.setEnabled(!isView);
257 this.jComboBoxUsage.setEnabled(!isView);
258 }
259 }
260
261 /**
262 This method initializes jContentPane
263
264 @return javax.swing.JPanel jContentPane
265
266 **/
267 private JPanel getJContentPane() {
268 if (jContentPane == null) {
269 jArchCheckBox = new ArchCheckBox();
270 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
271 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
272 jLabelUsage = new JLabel();
273 jLabelUsage.setText("Usage");
274 jLabelUsage.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
275 jLabelName = new JLabel();
276 jLabelName.setText("Name");
277 jLabelName.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
278 jLabelArch = new JLabel();
279 jLabelArch.setBounds(new java.awt.Rectangle(15, 110, 140, 20));
280 jLabelArch.setText("Arch");
281 jLabelFeatureFlag = new JLabel();
282 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
283 jLabelFeatureFlag.setText("Feature Flag");
284 jLabelHelpText = new JLabel();
285 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 60, 140, 20));
286 jLabelHelpText.setText("Help Text");
287
288 jContentPane = new JPanel();
289 jContentPane.setLayout(null);
290 jContentPane.setPreferredSize(new java.awt.Dimension(490, 165));
291
292 jContentPane.add(jLabelName, null);
293 jContentPane.add(jLabelUsage, null);
294 jContentPane.add(getJTextFieldName(), null);
295 jContentPane.add(getJComboBoxUsage(), null);
296
297 jContentPane.add(jLabelFeatureFlag, null);
298 jContentPane.add(jLabelArch, null);
299 jContentPane.add(getJTextFieldFeatureFlag(), null);
300
301 jStarLabel1 = new StarLabel();
302 jStarLabel1.setLocation(new java.awt.Point(0, 10));
303 jStarLabel2 = new StarLabel();
304 jStarLabel2.setLocation(new java.awt.Point(0, 35));
305
306 jContentPane.add(jStarLabel1, null);
307 jContentPane.add(jStarLabel2, null);
308
309 jContentPane.add(jLabelHelpText, null);
310 jContentPane.add(getJTextFieldHelpText(), null);
311 jContentPane.add(jArchCheckBox, null);
312 jContentPane.add(getJButtonOk(), null);
313 jContentPane.add(getJButtonCancel(), null);
314 }
315 return jContentPane;
316 }
317
318 /**
319 This method initializes Usage type
320
321 **/
322 private void initFrame() {
323 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVHiiPackageUsage());
324 }
325
326 /* (non-Javadoc)
327 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
328 *
329 * Override actionPerformed to listen all actions
330 *
331 */
332 public void actionPerformed(ActionEvent arg0) {
333 if (arg0.getSource() == jButtonOk) {
334 if (checkAdd()) {
335 getCurrentHiiPackages();
336 this.returnType = DataType.RETURN_TYPE_OK;
337 this.setVisible(false);
338 }
339 }
340
341 if (arg0.getSource() == jButtonCancel) {
342 this.returnType = DataType.RETURN_TYPE_CANCEL;
343 this.setVisible(false);
344 }
345 }
346
347 /**
348 Data validation for all fields
349
350 @retval true - All datas are valid
351 @retval false - At least one data is invalid
352
353 **/
354 public boolean checkAdd() {
355 //
356 // Check if all fields have correct data types
357 //
358
359 //
360 // Check Hii Package Name
361 //
362 if (isEmpty(this.jTextFieldName.getText())) {
363 Log.err("Hii Package Name Record couldn't be empty");
364 return false;
365 }
366
367 if (!isEmpty(this.jTextFieldName.getText())) {
368 if (!DataValidation.isC_NameType(this.jTextFieldName.getText())) {
369 Log.err("Incorrect data type for Hii Package Name");
370 return false;
371 }
372 }
373
374 //
375 // Check FeatureFlag
376 //
377 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
378 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
379 Log.err("Incorrect data type for Feature Flag");
380 return false;
381 }
382 }
383
384 return true;
385 }
386
387 private HiiPackagesIdentification getCurrentHiiPackages() {
388 String arg0 = this.jTextFieldName.getText();
389 String arg1 = this.jComboBoxUsage.getSelectedItem().toString();
390
391 String arg2 = this.jTextFieldFeatureFlag.getText();
392 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
393 String arg4 = this.jTextFieldHelpText.getText();
394
395 id = new HiiPackagesIdentification(arg0, arg1, arg2, arg3, arg4);
396 return id;
397 }
398
399 public HiiPackagesIdentification getId() {
400 return id;
401 }
402
403 public void setId(HiiPackagesIdentification id) {
404 this.id = id;
405 }
406 }