2 <<The file is used to create, update Data Hub Record entries in a MSA file.>>
4 <<The DataHbsDlg is a dialog called to add or edit a Data Hub Record within a MSA file.>>
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
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.
16 Module Name: FrameworkWizard
20 package org
.tianocore
.frameworkwizard
.module
.ui
.dialog
;
22 import java
.awt
.event
.ActionEvent
;
23 import java
.util
.Vector
;
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
;
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
;
47 * The class is used to create, update DataHub of the MSA file
52 public class DataHubsDlg
extends IDialog
{
55 // / Define class Serial Version UID
57 private static final long serialVersionUID
= -3667906991966638892L;
60 // Define class members
62 private JPanel jContentPane
= null;
64 private JLabel jLabelUsage
= null;
66 private JComboBox jComboBoxUsage
= null;
68 private JLabel jLabelDataHubRecord
= null;
70 private JTextField jTextFieldDataHubRecord
= null;
72 private StarLabel jStarLabel1
= null;
74 private StarLabel jStarLabel2
= null;
76 private JLabel jLabelFeatureFlag
= null;
78 private JTextField jTextFieldFeatureFlag
= null;
80 private JLabel jLabelArch
= null;
82 private JScrollPane jScrollPane
= null;
84 private JLabel jLabelHelpText
= null;
86 private JTextArea jTextAreaHelpText
= null;
88 private JScrollPane jScrollPaneHelpText
= null;
90 private ArchCheckBox jArchCheckBox
= null;
92 private JButton jButtonOk
= null;
94 private JButton jButtonCancel
= null;
99 private DataHubsIdentification id
= null;
101 private EnumerationData ed
= new EnumerationData();
103 private WorkspaceTools wt
= new WorkspaceTools();
106 * This method initializes jTextFieldDataHubRecord
108 * @return javax.swing.JTextField jTextFieldDataHubRecord
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");
118 return jTextFieldDataHubRecord
;
122 * This method initializes jComboBoxUsage
124 * @return javax.swing.JComboBox jComboBoxUsage
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));
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>");
140 return jComboBoxUsage
;
144 * This method initializes jTextFieldFeatureFlag
146 * @return javax.swing.JTextField
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);
156 return jTextFieldFeatureFlag
;
160 * This method initializes jScrollPane
162 * @return javax.swing.JScrollPane
164 private JScrollPane
getJScrollPane() {
165 if (jScrollPane
== null) {
166 jScrollPane
= new JScrollPane();
167 jScrollPane
.setViewportView(getJContentPane());
173 * This method initializes jTextAreaHelpText
175 * @return javax.swing.JTextArea
178 private JTextArea
getJTextAreaHelpText() {
179 if (jTextAreaHelpText
== null) {
180 jTextAreaHelpText
= new JTextArea();
181 jTextAreaHelpText
.setLineWrap(true);
182 jTextAreaHelpText
.setWrapStyleWord(true);
184 return jTextAreaHelpText
;
188 * This method initializes jScrollPaneHelpText
190 * @return javax.swing.JScrollPane
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());
202 return jScrollPaneHelpText
;
206 * This method initializes jButtonOk
208 * @return javax.swing.JButton
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);
222 * This method initializes jButtonCancel
224 * @return javax.swing.JButton
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);
234 return jButtonCancel
;
237 public static void main(String
[] args
) {
242 * This method initializes this
245 private void init() {
246 this.setSize(505, 235);
247 this.setContentPane(getJScrollPane());
248 this.setTitle("Data Hubs");
250 this.setViewMode(false);
255 * This method initializes this Fill values to all fields if these values are
258 * @param inDataHubsId
261 private void init(DataHubsIdentification inDataHubsId
, ModuleIdentification mid
) {
263 this.id
= inDataHubsId
;
266 // Init arch with module's arch
268 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
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());
280 * This is the override edit constructor
282 * @param inDataHubsIdentification
286 public DataHubsDlg(DataHubsIdentification inDataHubsIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
288 init(inDataHubsIdentification
, mid
);
292 * Disable all components when the mode is view
295 * true - The view mode; false - The non-view mode
298 public void setViewMode(boolean isView
) {
300 this.jTextFieldDataHubRecord
.setEnabled(!isView
);
301 this.jComboBoxUsage
.setEnabled(!isView
);
306 * This method initializes jContentPane
308 * @return javax.swing.JPanel jContentPane
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));
337 jContentPane
= new JPanel();
338 jContentPane
.setLayout(null);
339 jContentPane
.setPreferredSize(new java
.awt
.Dimension(480, 180));
341 jContentPane
.add(jLabelDataHubRecord
, null);
342 jContentPane
.add(jLabelUsage
, null);
343 jContentPane
.add(jLabelFeatureFlag
, null);
344 jContentPane
.add(jLabelArch
, null);
346 jContentPane
.add(getJTextFieldDataHubRecord(), null);
347 jContentPane
.add(getJComboBoxUsage(), null);
348 jContentPane
.add(getJTextFieldFeatureFlag(), null);
350 jContentPane
.add(jStarLabel1
, null);
351 jContentPane
.add(jStarLabel2
, null);
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);
363 * This method initializes Usage type
366 private void initFrame() {
367 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVDataHubUsage());
373 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
375 * Override actionPerformed to listen all actions
378 public void actionPerformed(ActionEvent arg0
) {
379 if (arg0
.getSource() == jButtonOk
) {
381 getCurrentDataHubs();
382 this.returnType
= DataType
.RETURN_TYPE_OK
;
383 this.setVisible(false);
387 if (arg0
.getSource() == jButtonCancel
) {
388 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
389 this.setVisible(false);
394 * Data validation for all fields
396 * @retval true - All datas are valid
397 * @retval false - At least one data is invalid
400 public boolean checkAdd() {
402 // Check if all fields have correct data types
406 // Check DataHubRecord
408 if (isEmpty(this.jTextFieldDataHubRecord
.getText())) {
409 Log
.wrn("Update Hubs", "Data Hub Record must be entered!");
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");
423 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
424 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
425 Log
.wrn("Update Hubs", "Incorrect data type for Feature Flag");
433 private DataHubsIdentification
getCurrentDataHubs() {
434 String arg0
= this.jTextFieldDataHubRecord
.getText();
435 String arg1
= this.jComboBoxUsage
.getSelectedItem().toString();
437 String arg2
= this.jTextFieldFeatureFlag
.getText();
438 Vector
<String
> arg3
= this.jArchCheckBox
.getSelectedItemsVector();
439 String arg4
= this.jTextAreaHelpText
.getText();
441 id
= new DataHubsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
);
445 public DataHubsIdentification
getId() {
449 public void setId(DataHubsIdentification id
) {