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