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