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