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