Fixed grammar in messages.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / PackageDepDlg.java
CommitLineData
06a19cee 1/** @file\r
2 \r
18916b63 3 The file is used to create, update Package Dependencies section of the MSA file\r
06a19cee 4 \r
5 Copyright (c) 2006, Intel Corporation\r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13 \r
14 **/\r
15package org.tianocore.frameworkwizard.module.ui.dialog;\r
16\r
17import java.awt.event.ActionEvent;\r
18import java.awt.event.ItemEvent;\r
19import java.awt.event.ItemListener;\r
20import java.util.Vector;\r
21\r
22import javax.swing.JButton;\r
23import javax.swing.JComboBox;\r
24import javax.swing.JLabel;\r
25import javax.swing.JPanel;\r
26import javax.swing.JScrollPane;\r
27import javax.swing.JTextField;\r
28\r
29import org.tianocore.frameworkwizard.common.DataType;\r
30import org.tianocore.frameworkwizard.common.DataValidation;\r
31import org.tianocore.frameworkwizard.common.Log;\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
36import org.tianocore.frameworkwizard.module.Identifications.PackageDependencies.PackageDependenciesIdentification;\r
37import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r
38import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r
39\r
40/**\r
18916b63 41 * The class is used to create, update Package Dependencies section of the MSA file\r
ccb063b1 42 * \r
9e857952 43 * It extends IDialog\r
ccb063b1 44 * \r
45 */\r
06a19cee 46public class PackageDepDlg extends IDialog implements ItemListener {\r
a929458e 47 // /\r
48 // / Define class Serial Version UID\r
49 // /\r
50 private static final long serialVersionUID = 3465193035145152131L;\r
06a19cee 51\r
a929458e 52 //\r
53 // Define class members\r
54 //\r
55 private JPanel jContentPane = null;\r
06a19cee 56\r
a929458e 57 private JLabel jLabelPackageName = null;\r
06a19cee 58\r
a929458e 59 private StarLabel jStarLabel1 = null;\r
06a19cee 60\r
a929458e 61 private JComboBox jComboBoxPackageName = null;\r
06a19cee 62\r
a929458e 63 private JLabel jLabelPackageGuid = null;\r
06a19cee 64\r
a929458e 65 private JTextField jTextFieldPackageGuid = null;\r
06a19cee 66\r
a929458e 67 private JLabel jLabelPackageVersion = null;\r
06a19cee 68\r
a929458e 69 private JTextField jTextFieldPackageVersion = 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 JScrollPane jScrollPane = null;\r
06a19cee 76\r
a929458e 77 private JLabel jLabelArch = null;\r
06a19cee 78\r
a929458e 79 private ArchCheckBox jArchCheckBox = null;\r
06a19cee 80\r
a929458e 81 private JButton jButtonOk = null;\r
06a19cee 82\r
a929458e 83 private JButton jButtonCancel = null;\r
06a19cee 84\r
a929458e 85 //\r
86 // Not used by UI\r
87 //\r
88 private PackageDependenciesIdentification pdid = null;\r
06a19cee 89\r
a929458e 90 private WorkspaceTools wt = new WorkspaceTools();\r
06a19cee 91\r
a929458e 92 private Vector<PackageIdentification> vPackage = wt.getAllPackages();\r
06a19cee 93\r
a929458e 94 /**\r
95 * This method initializes jComboBoxPackageName\r
96 * \r
97 * @return javax.swing.JComboBox\r
98 */\r
06a19cee 99 private JComboBox getJComboBoxPackageName() {\r
a929458e 100 if (jComboBoxPackageName == null) {\r
101 jComboBoxPackageName = new JComboBox();\r
18916b63 102 jComboBoxPackageName.setBounds(new java.awt.Rectangle(168, 12, 320, 20));\r
a929458e 103 jComboBoxPackageName.setPreferredSize(new java.awt.Dimension(320, 20));\r
623db5ca 104 jComboBoxPackageName.setToolTipText("If your Module requires a package, list that here.");\r
a929458e 105 jComboBoxPackageName.addItemListener(this);\r
106 }\r
107 return jComboBoxPackageName;\r
06a19cee 108 }\r
109\r
110 /**\r
ccb063b1 111 * This method initializes jTextFieldPackageGuid\r
112 * \r
113 * @return javax.swing.JTextField\r
06a19cee 114 */\r
115 private JTextField getJTextFieldPackageGuid() {\r
116 if (jTextFieldPackageGuid == null) {\r
117 jTextFieldPackageGuid = new JTextField();\r
18916b63 118 jTextFieldPackageGuid.setBounds(new java.awt.Rectangle(168, 37, 320, 20));\r
06a19cee 119 jTextFieldPackageGuid.setPreferredSize(new java.awt.Dimension(320, 20));\r
120 jTextFieldPackageGuid.setEditable(false);\r
121 jTextFieldPackageGuid.setVisible(false);\r
122 }\r
123 return jTextFieldPackageGuid;\r
124 }\r
125\r
06a19cee 126 /**\r
ccb063b1 127 * This method initializes jTextFieldPackageVersion\r
128 * \r
129 * @return javax.swing.JTextField\r
06a19cee 130 */\r
131 private JTextField getJTextFieldPackageVersion() {\r
132 if (jTextFieldPackageVersion == null) {\r
133 jTextFieldPackageVersion = new JTextField();\r
18916b63 134 jTextFieldPackageVersion.setBounds(new java.awt.Rectangle(168, 37, 320, 20));\r
06a19cee 135 jTextFieldPackageVersion.setPreferredSize(new java.awt.Dimension(320, 20));\r
136 jTextFieldPackageVersion\r
9e857952 137 .setToolTipText("<html>If this module depends on a specific version of a package, <br>"\r
138 + "enter the package version here. <br>"\r
139 + "If the module can use the latest version <br>"\r
140 + "that does not break backward compatibility, <br>"\r
141 + "leave this field blank</html>");\r
06a19cee 142 }\r
143 return jTextFieldPackageVersion;\r
144 }\r
145\r
146 /**\r
ccb063b1 147 * This method initializes jTextFieldFeatureFlag\r
148 * \r
149 * @return javax.swing.JTextField\r
06a19cee 150 */\r
151 private JTextField getJTextFieldFeatureFlag() {\r
152 if (jTextFieldFeatureFlag == null) {\r
153 jTextFieldFeatureFlag = new JTextField();\r
21b42c66 154 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(168, 87, 320, 20));\r
06a19cee 155 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));\r
21b42c66 156 jTextFieldFeatureFlag.setEnabled(false);\r
06a19cee 157 }\r
158 return jTextFieldFeatureFlag;\r
159 }\r
160\r
161 /**\r
ccb063b1 162 * This method initializes jScrollPane\r
163 * \r
164 * @return javax.swing.JScrollPane\r
06a19cee 165 */\r
166 private JScrollPane getJScrollPane() {\r
167 if (jScrollPane == null) {\r
168 jScrollPane = new JScrollPane();\r
169 jScrollPane.setViewportView(getJContentPane());\r
170 }\r
171 return jScrollPane;\r
172 }\r
173\r
174 /**\r
ccb063b1 175 * This method initializes jButtonOk\r
176 * \r
177 * @return javax.swing.JButton\r
178 * \r
179 */\r
06a19cee 180 private JButton getJButtonOk() {\r
181 if (jButtonOk == null) {\r
182 jButtonOk = new JButton();\r
18916b63 183 jButtonOk.setBounds(new java.awt.Rectangle(290, 122, 90, 20));\r
06a19cee 184 jButtonOk.setText("Ok");\r
185 jButtonOk.addActionListener(this);\r
186 }\r
187 return jButtonOk;\r
188 }\r
189\r
190 /**\r
ccb063b1 191 * This method initializes jButtonCancel\r
192 * \r
193 * @return javax.swing.JButton\r
194 * \r
195 */\r
06a19cee 196 private JButton getJButtonCancel() {\r
197 if (jButtonCancel == null) {\r
198 jButtonCancel = new JButton();\r
18916b63 199 jButtonCancel.setBounds(new java.awt.Rectangle(390, 122, 90, 20));\r
06a19cee 200 jButtonCancel.setText("Cancel");\r
201 jButtonCancel.addActionListener(this);\r
202 }\r
203 return jButtonCancel;\r
204 }\r
205\r
206 public static void main(String[] args) {\r
207\r
208 }\r
209\r
210 /**\r
ccb063b1 211 * This method initializes this\r
212 * \r
213 */\r
06a19cee 214 private void init() {\r
18916b63 215 this.setSize(505, 216);\r
06a19cee 216 this.setContentPane(getJScrollPane());\r
217 this.setTitle("Package Dependencies");\r
218 initFrame();\r
219 this.setViewMode(false);\r
220 this.centerWindow();\r
221 }\r
222\r
223 /**\r
ccb063b1 224 * This method initializes this\r
225 * \r
226 */\r
06a19cee 227 private void init(PackageDependenciesIdentification inPackageDependenciesIdentification) {\r
228 init();\r
229 this.pdid = inPackageDependenciesIdentification;\r
230 if (pdid != null) {\r
231 this.jComboBoxPackageName.setSelectedItem(pdid.getName());\r
232 this.jTextFieldPackageVersion.setText(pdid.getVersion());\r
233 this.jTextFieldPackageGuid.setText(pdid.getGuid());\r
234 jTextFieldFeatureFlag.setText(pdid.getFeatureFlag());\r
235 this.jArchCheckBox.setSelectedItems(pdid.getSupArchList());\r
236 }\r
237 }\r
238\r
239 /**\r
ccb063b1 240 * This is the default constructor\r
241 * \r
242 */\r
06a19cee 243 public PackageDepDlg(PackageDependenciesIdentification inPackageDependenciesIdentification, IFrame iFrame) {\r
244 super(iFrame, true);\r
245 init(inPackageDependenciesIdentification);\r
246 }\r
247\r
248 /**\r
ccb063b1 249 * Disable all components when the mode is view\r
250 * \r
251 * @param isView\r
252 * true - The view mode; false - The non-view mode\r
253 * \r
254 */\r
06a19cee 255 public void setViewMode(boolean isView) {\r
256 if (isView) {\r
257 this.jComboBoxPackageName.setEnabled(!isView);\r
258 }\r
259 }\r
260\r
261 /**\r
ccb063b1 262 * This method initializes jContentPane\r
263 * \r
264 * @return javax.swing.JPanel jContentPane\r
265 * \r
266 */\r
06a19cee 267 private JPanel getJContentPane() {\r
268 if (jContentPane == null) {\r
a929458e 269 jStarLabel1 = new StarLabel();\r
18916b63 270 jStarLabel1.setLocation(new java.awt.Point(2, 12));\r
a929458e 271 jLabelPackageName = new JLabel();\r
18916b63 272 jLabelPackageName.setBounds(new java.awt.Rectangle(12, 12, 168, 20));\r
a929458e 273 jLabelPackageName.setText("Package Name");\r
274\r
275 jLabelPackageVersion = new JLabel();\r
18916b63 276 jLabelPackageVersion.setBounds(new java.awt.Rectangle(12, 37, 168, 20));\r
a929458e 277 jLabelPackageVersion.setText("Package Version");\r
278\r
279 jLabelPackageGuid = new JLabel();\r
18916b63 280 jLabelPackageGuid.setBounds(new java.awt.Rectangle(12, 37, 168, 20));\r
a929458e 281 jLabelPackageGuid.setText("Package Guid");\r
282 jLabelPackageGuid.setVisible(false);\r
283\r
284 jLabelFeatureFlag = new JLabel();\r
21b42c66 285 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 87, 168, 20));\r
a929458e 286 jLabelFeatureFlag.setText("Feature Flag Expression");\r
21b42c66 287 jLabelFeatureFlag.setEnabled(false);\r
a929458e 288\r
289 jLabelArch = new JLabel();\r
21b42c66 290 jLabelArch.setBounds(new java.awt.Rectangle(12, 62, 168, 20));\r
a929458e 291 jLabelArch.setText("Supported Architectures");\r
292 jArchCheckBox = new ArchCheckBox();\r
21b42c66 293 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 62, 320, 20));\r
a929458e 294 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));\r
06a19cee 295\r
296 jContentPane = new JPanel();\r
297 jContentPane.setLayout(null);\r
18916b63 298 jContentPane.setPreferredSize(new java.awt.Dimension(485, 170));\r
a929458e 299\r
06a19cee 300 jContentPane.add(jStarLabel1, null);\r
ccb063b1 301 jContentPane.add(jLabelPackageName, null);\r
06a19cee 302 jContentPane.add(getJComboBoxPackageName(), null);\r
303 jContentPane.add(jLabelPackageGuid, null);\r
304 jContentPane.add(getJTextFieldPackageGuid(), null);\r
06a19cee 305 jContentPane.add(jLabelPackageVersion, null);\r
306 jContentPane.add(getJTextFieldPackageVersion(), null);\r
ccb063b1 307 // LAH Not Used here\r
308 // jContentPane.add(getJButtonGenerateGuid(), null);\r
06a19cee 309 jContentPane.add(jLabelFeatureFlag, null);\r
310 jContentPane.add(getJTextFieldFeatureFlag(), null);\r
06a19cee 311 jContentPane.add(jLabelArch, null);\r
312 jContentPane.add(jArchCheckBox, null);\r
313 jContentPane.add(getJButtonOk(), null);\r
314 jContentPane.add(getJButtonCancel(), null);\r
315 }\r
316 return jContentPane;\r
317 }\r
318\r
ccb063b1 319 /*\r
320 * (non-Javadoc)\r
321 * \r
06a19cee 322 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
ccb063b1 323 * \r
06a19cee 324 * Override actionPerformed to listen all actions\r
325 * \r
326 */\r
327 public void actionPerformed(ActionEvent arg0) {\r
328 if (arg0.getSource() == jButtonOk) {\r
329 if (checkAdd()) {\r
330 getCurrentPackageDependencies();\r
331 this.returnType = DataType.RETURN_TYPE_OK;\r
332 this.setVisible(false);\r
333 }\r
334 }\r
335\r
336 if (arg0.getSource() == jButtonCancel) {\r
337 this.returnType = DataType.RETURN_TYPE_CANCEL;\r
338 this.setVisible(false);\r
339 }\r
340 }\r
341\r
342 /**\r
ccb063b1 343 * This method initializes Usage type, Package type and Arch type\r
344 * \r
345 */\r
06a19cee 346 private void initFrame() {\r
347 for (int index = 0; index < vPackage.size(); index++) {\r
348 jComboBoxPackageName.addItem(vPackage.elementAt(index).getName());\r
349 }\r
350 }\r
351\r
352 /**\r
ccb063b1 353 * Data validation for all fields before add current item to Vector\r
354 * \r
355 * @retval true - All datas are valid\r
356 * @retval false - At least one data is invalid\r
357 * \r
358 */\r
06a19cee 359 public boolean checkAdd() {\r
360 //\r
ccb063b1 361 // Check if all fields have correct data types\r
06a19cee 362 //\r
363\r
364 //\r
ccb063b1 365 // Check PackageGuid\r
06a19cee 366 //\r
a929458e 367 // if (!isEmpty(this.jTextFieldPackageGuid.getText())) {\r
368 // if (!DataValidation.isGuid(this.jTextFieldPackageGuid.getText())) {\r
369 // Log.err("Incorrect data type for Package Guid");\r
370 // return false;\r
371 // }\r
372 // }\r
06a19cee 373\r
374 //\r
ccb063b1 375 // Check PackageVersion\r
06a19cee 376 //\r
377 if (!isEmpty(this.jTextFieldPackageVersion.getText())) {\r
378 if (!DataValidation.isVersion(this.jTextFieldPackageVersion.getText())) {\r
ed1665f2 379 Log.wrn("Update Package Dependencies", "Incorrect data type for Package Version");\r
06a19cee 380 return false;\r
381 }\r
382 }\r
383\r
384 //\r
385 // Check FeatureFlag\r
386 //\r
387 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r
388 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r
ed1665f2 389 Log.wrn("Update Package Dependencies", "Incorrect data type for Feature Flag");\r
06a19cee 390 return false;\r
391 }\r
392 }\r
393\r
394 return true;\r
395 }\r
06a19cee 396\r
397 private PackageDependenciesIdentification getCurrentPackageDependencies() {\r
398 String arg0 = this.jComboBoxPackageName.getSelectedItem().toString();\r
399 String arg1 = this.jTextFieldPackageVersion.getText();\r
400 String arg2 = this.jTextFieldPackageGuid.getText();\r
401\r
402 String arg3 = this.jTextFieldFeatureFlag.getText();\r
403 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();\r
404 pdid = new PackageDependenciesIdentification(arg0, arg1, arg2, arg3, arg4);\r
405 return pdid;\r
406 }\r
407\r
ccb063b1 408 /*\r
409 * (non-Javadoc)\r
410 * \r
06a19cee 411 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)\r
ccb063b1 412 * \r
06a19cee 413 * Reflesh the frame when selected item changed\r
414 * \r
415 */\r
416 public void itemStateChanged(ItemEvent arg0) {\r
417 if (arg0.getSource() == this.jComboBoxPackageName && arg0.getStateChange() == ItemEvent.SELECTED) {\r
418 for (int index = 0; index < vPackage.size(); index++) {\r
419 if (this.jComboBoxPackageName.getSelectedItem().toString().equals(vPackage.get(index).getName())) {\r
420 this.jTextFieldPackageGuid.setText(vPackage.get(index).getGuid());\r
421 }\r
422 }\r
423 }\r
424 }\r
425\r
426 public PackageDependenciesIdentification getPdid() {\r
427 return pdid;\r
428 }\r
429\r
430 public void setPdid(PackageDependenciesIdentification pdid) {\r
431 this.pdid = pdid;\r
432 }\r
433\r
434}\r