3 The file is used to create, update DataHub of MSA/MBD file
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.frameworkwizard
.module
.ui
.dialog
;
18 import java
.awt
.event
.ActionEvent
;
19 import java
.util
.Vector
;
21 import javax
.swing
.JButton
;
22 import javax
.swing
.JComboBox
;
23 import javax
.swing
.JLabel
;
24 import javax
.swing
.JPanel
;
25 import javax
.swing
.JScrollPane
;
26 import javax
.swing
.JTextField
;
28 import org
.tianocore
.frameworkwizard
.common
.DataType
;
29 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
30 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
31 import org
.tianocore
.frameworkwizard
.common
.Log
;
32 import org
.tianocore
.frameworkwizard
.common
.Tools
;
33 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
34 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
37 import org
.tianocore
.frameworkwizard
.module
.Identifications
.DataHubs
.DataHubsIdentification
;
40 The class is used to create, update DataHub of MSA/MBD file
41 It extends IInternalFrame
46 public class DataHubsDlg
extends IDialog
{
49 /// Define class Serial Version UID
51 private static final long serialVersionUID
= -3667906991966638892L;
54 //Define class members
56 private JPanel jContentPane
= null;
58 private JLabel jLabelUsage
= null;
60 private JComboBox jComboBoxUsage
= null;
62 private JLabel jLabelDataHubRecord
= null;
64 private JTextField jTextFieldDataHubRecord
= null;
66 private StarLabel jStarLabel1
= null;
68 private StarLabel jStarLabel2
= null;
70 private JLabel jLabelFeatureFlag
= null;
72 private JTextField jTextFieldFeatureFlag
= null;
74 private JLabel jLabelArch
= null;
76 private JScrollPane jScrollPane
= null;
78 private JLabel jLabelHelpText
= null;
80 private JTextField jTextFieldHelpText
= null;
82 private ArchCheckBox jArchCheckBox
= null;
84 private JButton jButtonOk
= null;
86 private JButton jButtonCancel
= null;
91 private DataHubsIdentification id
= null;
93 private EnumerationData ed
= new EnumerationData();
96 This method initializes jComboBoxUsage
98 @return javax.swing.JComboBox jComboBoxUsage
101 private JComboBox
getJComboBoxUsage() {
102 if (jComboBoxUsage
== null) {
103 jComboBoxUsage
= new JComboBox();
104 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
105 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
107 return jComboBoxUsage
;
111 This method initializes jTextFieldDataHubRecord
113 @return javax.swing.JTextField jTextFieldDataHubRecord
116 private JTextField
getJTextFieldDataHubRecord() {
117 if (jTextFieldDataHubRecord
== null) {
118 jTextFieldDataHubRecord
= new JTextField();
119 jTextFieldDataHubRecord
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
120 jTextFieldDataHubRecord
.setPreferredSize(new java
.awt
.Dimension(320, 20));
121 jTextFieldDataHubRecord
.setToolTipText("Enter the C Name of the Data Hub Record");
123 return jTextFieldDataHubRecord
;
127 * This method initializes jTextFieldFeatureFlag
129 * @return javax.swing.JTextField
131 private JTextField
getJTextFieldFeatureFlag() {
132 if (jTextFieldFeatureFlag
== null) {
133 jTextFieldFeatureFlag
= new JTextField();
134 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
135 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
137 return jTextFieldFeatureFlag
;
141 This method initializes jScrollPane
143 @return javax.swing.JScrollPane
145 private JScrollPane
getJScrollPane() {
146 if (jScrollPane
== null) {
147 jScrollPane
= new JScrollPane();
148 jScrollPane
.setViewportView(getJContentPane());
154 This method initializes jTextFieldHelpText
156 @return javax.swing.JTextField
159 private JTextField
getJTextFieldHelpText() {
160 if (jTextFieldHelpText
== null) {
161 jTextFieldHelpText
= new JTextField();
162 jTextFieldHelpText
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
163 jTextFieldHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 20));
165 return jTextFieldHelpText
;
169 This method initializes jButtonOk
171 @return javax.swing.JButton
174 private JButton
getJButtonOk() {
175 if (jButtonOk
== null) {
176 jButtonOk
= new JButton();
177 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 140, 90, 20));
178 jButtonOk
.setText("Ok");
179 jButtonOk
.addActionListener(this);
185 This method initializes jButtonCancel
187 @return javax.swing.JButton
190 private JButton
getJButtonCancel() {
191 if (jButtonCancel
== null) {
192 jButtonCancel
= new JButton();
193 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 140, 90, 20));
194 jButtonCancel
.setText("Cancel");
195 jButtonCancel
.addActionListener(this);
197 return jButtonCancel
;
200 public static void main(String
[] args
) {
205 This method initializes this
208 private void init() {
209 this.setSize(500, 200);
210 this.setContentPane(getJScrollPane());
211 this.setTitle("Data Hubs");
213 this.setViewMode(false);
218 This method initializes this
219 Fill values to all fields if these values are not empty
224 private void init(DataHubsIdentification inDataHubsId
) {
226 this.id
= inDataHubsId
;
228 if (this.id
!= null) {
229 this.jTextFieldDataHubRecord
.setText(id
.getName());
230 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
231 this.jTextFieldHelpText
.setText(id
.getHelp());
232 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
233 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
238 This is the override edit constructor
240 @param inDataHubsIdentification
244 public DataHubsDlg(DataHubsIdentification inDataHubsIdentification
, IFrame iFrame
) {
246 init(inDataHubsIdentification
);
250 Disable all components when the mode is view
252 @param isView true - The view mode; false - The non-view mode
255 public void setViewMode(boolean isView
) {
257 this.jTextFieldDataHubRecord
.setEnabled(!isView
);
258 this.jComboBoxUsage
.setEnabled(!isView
);
263 This method initializes jContentPane
265 @return javax.swing.JPanel jContentPane
268 private JPanel
getJContentPane() {
269 if (jContentPane
== null) {
270 jArchCheckBox
= new ArchCheckBox();
271 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 110, 320, 20));
272 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
273 jLabelDataHubRecord
= new JLabel();
274 jLabelDataHubRecord
.setBounds(new java
.awt
.Rectangle(15, 10, 140, 20));
275 jLabelDataHubRecord
.setText("Data Hub Record");
276 jLabelUsage
= new JLabel();
277 jLabelUsage
.setText("Usage");
278 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
279 jLabelArch
= new JLabel();
280 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 110, 140, 20));
281 jLabelArch
.setText("Arch");
282 jLabelFeatureFlag
= new JLabel();
283 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 85, 140, 20));
284 jLabelFeatureFlag
.setText("Feature Flag");
285 jLabelHelpText
= new JLabel();
286 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(14, 60, 140, 20));
287 jLabelHelpText
.setText("Help Text");
289 jContentPane
= new JPanel();
290 jContentPane
.setLayout(null);
291 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 165));
293 jContentPane
.add(jLabelDataHubRecord
, null);
294 jContentPane
.add(jLabelUsage
, null);
295 jContentPane
.add(jLabelFeatureFlag
, null);
296 jContentPane
.add(jLabelArch
, null);
298 jContentPane
.add(getJTextFieldDataHubRecord(), null);
299 jContentPane
.add(getJComboBoxUsage(), null);
300 jContentPane
.add(getJTextFieldFeatureFlag(), null);
302 jStarLabel1
= new StarLabel();
303 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
304 jStarLabel2
= new StarLabel();
305 jStarLabel2
.setLocation(new java
.awt
.Point(0, 35));
307 jContentPane
.add(jStarLabel1
, null);
308 jContentPane
.add(jStarLabel2
, null);
310 jContentPane
.add(jLabelHelpText
, null);
311 jContentPane
.add(getJTextFieldHelpText(), null);
312 jContentPane
.add(jArchCheckBox
, null);
313 jContentPane
.add(getJButtonOk(), null);
314 jContentPane
.add(getJButtonCancel(), null);
320 This method initializes Usage type
323 private void initFrame() {
324 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVDataHubUsage());
328 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
330 * Override actionPerformed to listen all actions
333 public void actionPerformed(ActionEvent arg0
) {
334 if (arg0
.getSource() == jButtonOk
) {
336 getCurrentDataHubs();
337 this.returnType
= DataType
.RETURN_TYPE_OK
;
338 this.setVisible(false);
342 if (arg0
.getSource() == jButtonCancel
) {
343 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
344 this.setVisible(false);
349 Data validation for all fields
351 @retval true - All datas are valid
352 @retval false - At least one data is invalid
355 public boolean checkAdd() {
357 // Check if all fields have correct data types
361 // Check DataHubRecord
363 if (isEmpty(this.jTextFieldDataHubRecord
.getText())) {
364 Log
.err("Data Hub Record couldn't be empty");
368 if (!isEmpty(this.jTextFieldDataHubRecord
.getText())) {
369 if (!DataValidation
.isC_NameType(this.jTextFieldDataHubRecord
.getText())) {
370 Log
.err("Incorrect data type for Data Hub Record");
378 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
379 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
380 Log
.err("Incorrect data type for Feature Flag");
388 private DataHubsIdentification
getCurrentDataHubs() {
389 String arg0
= this.jTextFieldDataHubRecord
.getText();
390 String arg1
= this.jComboBoxUsage
.getSelectedItem().toString();
392 String arg2
= this.jTextFieldFeatureFlag
.getText();
393 Vector
<String
> arg3
= this.jArchCheckBox
.getSelectedItemsVector();
394 String arg4
= this.jTextFieldHelpText
.getText();
396 id
= new DataHubsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
);
400 public DataHubsIdentification
getId() {
404 public void setId(DataHubsIdentification id
) {