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