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