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