]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/DataHubsDlg.java
56a856e49d95e76d702fdff68d3340dda27f9045
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / DataHubsDlg.java
1 /** @file
2 <<The file is used to create, update Data Hub Record entries in a MSA file.>>
3
4 <<The DataHbsDlg is a dialog called to add or edit a Data Hub Record within a MSA file.>>
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 Package Name: Tools
16 Module Name: FrameworkWizard
17
18 **/
19
20 package org.tianocore.frameworkwizard.module.ui.dialog;
21
22 import java.awt.event.ActionEvent;
23 import java.util.Vector;
24
25 import javax.swing.JButton;
26 import javax.swing.JComboBox;
27 import javax.swing.JLabel;
28 import javax.swing.JPanel;
29 import javax.swing.JScrollPane;
30 import javax.swing.JTextField;
31 import javax.swing.JTextArea;
32
33 import org.tianocore.frameworkwizard.common.DataType;
34 import org.tianocore.frameworkwizard.common.DataValidation;
35 import org.tianocore.frameworkwizard.common.EnumerationData;
36 import org.tianocore.frameworkwizard.common.Log;
37 import org.tianocore.frameworkwizard.common.Tools;
38 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
39 import org.tianocore.frameworkwizard.common.ui.IDialog;
40 import org.tianocore.frameworkwizard.common.ui.IFrame;
41 import org.tianocore.frameworkwizard.common.ui.StarLabel;
42 import org.tianocore.frameworkwizard.module.Identifications.DataHubs.DataHubsIdentification;
43
44 /**
45 * The class is used to create, update DataHub of MSA/MBD file It extends
46 * IInternalFrame
47 *
48 *
49 *
50 */
51 public class DataHubsDlg extends IDialog {
52
53 // /
54 // / Define class Serial Version UID
55 // /
56 private static final long serialVersionUID = -3667906991966638892L;
57
58 //
59 // Define class members
60 //
61 private JPanel jContentPane = null;
62
63 private JLabel jLabelUsage = null;
64
65 private JComboBox jComboBoxUsage = null;
66
67 private JLabel jLabelDataHubRecord = null;
68
69 private JTextField jTextFieldDataHubRecord = null;
70
71 private StarLabel jStarLabel1 = null;
72
73 private StarLabel jStarLabel2 = null;
74
75 private JLabel jLabelFeatureFlag = null;
76
77 private JTextField jTextFieldFeatureFlag = null;
78
79 private JLabel jLabelArch = null;
80
81 private JScrollPane jScrollPane = null;
82
83 private JLabel jLabelHelpText = null;
84
85 private JTextArea jTextAreaHelpText = null;
86
87 private JScrollPane jScrollPaneHelpText = null;
88
89 private ArchCheckBox jArchCheckBox = null;
90
91 private JButton jButtonOk = null;
92
93 private JButton jButtonCancel = null;
94
95 //
96 // Not used by UI
97 //
98 private DataHubsIdentification id = null;
99
100 private EnumerationData ed = new EnumerationData();
101
102 /**
103 * This method initializes jTextFieldDataHubRecord
104 *
105 * @return javax.swing.JTextField jTextFieldDataHubRecord
106 *
107 */
108 private JTextField getJTextFieldDataHubRecord() {
109 if (jTextFieldDataHubRecord == null) {
110 jTextFieldDataHubRecord = new JTextField();
111 jTextFieldDataHubRecord
112 .setBounds(new java.awt.Rectangle(160, 10, 320, 20));
113 jTextFieldDataHubRecord.setPreferredSize(new java.awt.Dimension(320, 20));
114 jTextFieldDataHubRecord
115 .setToolTipText("Enter the C Name of the Data Hub Record");
116 }
117 return jTextFieldDataHubRecord;
118 }
119
120 /**
121 * This method initializes jComboBoxUsage
122 *
123 * @return javax.swing.JComboBox jComboBoxUsage
124 *
125 */
126 private JComboBox getJComboBoxUsage() {
127 if (jComboBoxUsage == null) {
128 jComboBoxUsage = new JComboBox();
129 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
130 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
131 jComboBoxUsage
132 .setToolTipText("<html><table><tr><td>ALWAYS_CONSUMED</td><td>Module always consumes a Data Hub Entry<br>via registering a filter driver.</td></tr><tr><td>SOMETIMES_CONSUMED</td><td>Module will use a Data Hub Entry if it exists<br>via registering a filter driver</td></tr><tr><td>ALWAYS_PRODUCED</td><td>Always logs data into the Data Hub</td></tr><tr><td>SOMETIMES_PRODUCED</td><td>Log data into the Data Hub under<br>certain circumstances</td></tr></table></html>");
133 }
134 return jComboBoxUsage;
135 }
136
137 /**
138 * This method initializes jTextFieldFeatureFlag
139 *
140 * @return javax.swing.JTextField
141 */
142 private JTextField getJTextFieldFeatureFlag() {
143 if (jTextFieldFeatureFlag == null) {
144 jTextFieldFeatureFlag = new JTextField();
145 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 105, 320, 20));
146 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
147 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
148 }
149 return jTextFieldFeatureFlag;
150 }
151
152 /**
153 * This method initializes jScrollPane
154 *
155 * @return javax.swing.JScrollPane
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 * This method initializes jTextAreaHelpText
167 *
168 * @return javax.swing.JTextArea
169 *
170 */
171 private JTextArea getJTextAreaHelpText() {
172 if (jTextAreaHelpText == null) {
173 jTextAreaHelpText = new JTextArea();
174 jTextAreaHelpText.setLineWrap(true);
175 jTextAreaHelpText.setWrapStyleWord(true);
176 }
177 return jTextAreaHelpText;
178 }
179
180 /**
181 * This method initializes jScrollPaneHelpText
182 *
183 * @return javax.swing.JScrollPane
184 *
185 */
186 private JScrollPane getJScrollPaneHelpText() {
187 if (jScrollPaneHelpText == null) {
188 jScrollPaneHelpText = new JScrollPane();
189 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
190 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));
191 jScrollPaneHelpText.setPreferredSize(new java.awt.Dimension(320,40));
192 jScrollPaneHelpText.setLocation(new java.awt.Point(160,60));
193 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
194 }
195 return jScrollPaneHelpText;
196 }
197 /**
198 * This method initializes jButtonOk
199 *
200 * @return javax.swing.JButton
201 *
202 */
203 private JButton getJButtonOk() {
204 if (jButtonOk == null) {
205 jButtonOk = new JButton();
206 jButtonOk.setBounds(new java.awt.Rectangle(290, 157, 90, 20));
207 jButtonOk.setText("Ok");
208 jButtonOk.addActionListener(this);
209 }
210 return jButtonOk;
211 }
212
213 /**
214 * This method initializes jButtonCancel
215 *
216 * @return javax.swing.JButton
217 *
218 */
219 private JButton getJButtonCancel() {
220 if (jButtonCancel == null) {
221 jButtonCancel = new JButton();
222 jButtonCancel.setBounds(new java.awt.Rectangle(390, 157, 90, 20));
223 jButtonCancel.setText("Cancel");
224 jButtonCancel.addActionListener(this);
225 }
226 return jButtonCancel;
227 }
228
229 public static void main(String[] args) {
230
231 }
232
233 /**
234 * This method initializes this
235 *
236 */
237 private void init() {
238 this.setSize(500, 230);
239 this.setContentPane(getJScrollPane());
240 this.setTitle("Data Hubs");
241 initFrame();
242 this.setViewMode(false);
243 this.centerWindow();
244 }
245
246 /**
247 * This method initializes this Fill values to all fields if these values are
248 * not empty
249 *
250 * @param inDataHubsId
251 *
252 */
253 private void init(DataHubsIdentification inDataHubsId) {
254 init();
255 this.id = inDataHubsId;
256
257 if (this.id != null) {
258 this.jTextFieldDataHubRecord.setText(id.getName());
259 this.jComboBoxUsage.setSelectedItem(id.getUsage());
260 this.jTextAreaHelpText.setText(id.getHelp());
261 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
262 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
263 }
264 }
265
266 /**
267 * This is the override edit constructor
268 *
269 * @param inDataHubsIdentification
270 * @param iFrame
271 *
272 */
273 public DataHubsDlg(DataHubsIdentification inDataHubsIdentification,
274 IFrame iFrame) {
275 super(iFrame, true);
276 init(inDataHubsIdentification);
277 }
278
279 /**
280 * Disable all components when the mode is view
281 *
282 * @param isView
283 * true - The view mode; false - The non-view mode
284 *
285 */
286 public void setViewMode(boolean isView) {
287 if (isView) {
288 this.jTextFieldDataHubRecord.setEnabled(!isView);
289 this.jComboBoxUsage.setEnabled(!isView);
290 }
291 }
292
293 /**
294 * This method initializes jContentPane
295 *
296 * @return javax.swing.JPanel jContentPane
297 *
298 */
299 private JPanel getJContentPane() {
300 if (jContentPane == null) {
301 jStarLabel1 = new StarLabel();
302 jStarLabel1.setLocation(new java.awt.Point(2, 10));
303 jLabelDataHubRecord = new JLabel();
304 jLabelDataHubRecord.setBounds(new java.awt.Rectangle(15, 10, 145, 20));
305 jLabelDataHubRecord.setText("Data Hub Record");
306 jStarLabel2 = new StarLabel();
307 jStarLabel2.setLocation(new java.awt.Point(2, 35));
308 jLabelUsage = new JLabel();
309 jLabelUsage.setText("Usage");
310 jLabelUsage.setBounds(new java.awt.Rectangle(15, 35, 145, 20));
311 jLabelHelpText = new JLabel();
312 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 60, 145, 20));
313 jLabelHelpText.setText("Help Text");
314 jLabelFeatureFlag = new JLabel();
315 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 105, 145, 20));
316 jLabelFeatureFlag.setText("Feature Flag Expression");
317 jLabelArch = new JLabel();
318 jLabelArch.setBounds(new java.awt.Rectangle(15, 130, 145, 20));
319 jLabelArch.setText("Supported Architectures");
320 jArchCheckBox = new ArchCheckBox();
321 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 130, 320, 20));
322 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
323
324 jContentPane = new JPanel();
325 jContentPane.setLayout(null);
326 jContentPane.setPreferredSize(new java.awt.Dimension(485, 185));
327
328 jContentPane.add(jLabelDataHubRecord, null);
329 jContentPane.add(jLabelUsage, null);
330 jContentPane.add(jLabelFeatureFlag, null);
331 jContentPane.add(jLabelArch, null);
332
333 jContentPane.add(getJTextFieldDataHubRecord(), null);
334 jContentPane.add(getJComboBoxUsage(), null);
335 jContentPane.add(getJTextFieldFeatureFlag(), null);
336
337 jContentPane.add(jStarLabel1, null);
338 jContentPane.add(jStarLabel2, null);
339
340 jContentPane.add(jLabelHelpText, null);
341 jContentPane.add(getJScrollPaneHelpText(), null);
342 jContentPane.add(jArchCheckBox, null);
343 jContentPane.add(getJButtonOk(), null);
344 jContentPane.add(getJButtonCancel(), null);
345 }
346 return jContentPane;
347 }
348
349 /**
350 * This method initializes Usage type
351 *
352 */
353 private void initFrame() {
354 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVDataHubUsage());
355 }
356
357 /*
358 * (non-Javadoc)
359 *
360 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
361 *
362 * Override actionPerformed to listen all actions
363 *
364 */
365 public void actionPerformed(ActionEvent arg0) {
366 if (arg0.getSource() == jButtonOk) {
367 if (checkAdd()) {
368 getCurrentDataHubs();
369 this.returnType = DataType.RETURN_TYPE_OK;
370 this.setVisible(false);
371 }
372 }
373
374 if (arg0.getSource() == jButtonCancel) {
375 this.returnType = DataType.RETURN_TYPE_CANCEL;
376 this.setVisible(false);
377 }
378 }
379
380 /**
381 * Data validation for all fields
382 *
383 * @retval true - All datas are valid
384 * @retval false - At least one data is invalid
385 *
386 */
387 public boolean checkAdd() {
388 //
389 // Check if all fields have correct data types
390 //
391
392 //
393 // Check DataHubRecord
394 //
395 if (isEmpty(this.jTextFieldDataHubRecord.getText())) {
396 Log.wrn("Update Hubs", "Data Hub Record must not be empty");
397 return false;
398 }
399
400 if (!isEmpty(this.jTextFieldDataHubRecord.getText())) {
401 if (!DataValidation.isC_NameType(this.jTextFieldDataHubRecord.getText())) {
402 Log.wrn("Update Hubs", "Incorrect data type for Data Hub Record");
403 return false;
404 }
405 }
406
407 //
408 // Check FeatureFlag
409 //
410 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
411 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
412 Log.wrn("Update Hubs", "Incorrect data type for Feature Flag");
413 return false;
414 }
415 }
416
417 return true;
418 }
419
420 private DataHubsIdentification getCurrentDataHubs() {
421 String arg0 = this.jTextFieldDataHubRecord.getText();
422 String arg1 = this.jComboBoxUsage.getSelectedItem().toString();
423
424 String arg2 = this.jTextFieldFeatureFlag.getText();
425 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
426 String arg4 = this.jTextAreaHelpText.getText();
427
428 id = new DataHubsIdentification(arg0, arg1, arg2, arg3, arg4);
429 return id;
430 }
431
432 public DataHubsIdentification getId() {
433 return id;
434 }
435
436 public void setId(DataHubsIdentification id) {
437 this.id = id;
438 }
439 }