Adjusted locations and sizes of boxes for Windows, Linux and iMac GUI, no other funct...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / LibraryClassDefsDlg.java
CommitLineData
06a19cee 1/** @file\r
2 \r
3 The file is used to create, update Library Class Definition of MSA/MBD file\r
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.Dimension;\r
18import java.awt.event.ActionEvent;\r
19import java.util.Vector;\r
20\r
21import javax.swing.JButton;\r
22import javax.swing.JComboBox;\r
23import javax.swing.JLabel;\r
24import javax.swing.JPanel;\r
25import javax.swing.JScrollPane;\r
26import javax.swing.JTextField;\r
27\r
28import org.tianocore.frameworkwizard.common.DataType;\r
29import org.tianocore.frameworkwizard.common.DataValidation;\r
30import org.tianocore.frameworkwizard.common.EnumerationData;\r
31import org.tianocore.frameworkwizard.common.Log;\r
32import org.tianocore.frameworkwizard.common.Tools;\r
33import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;\r
34import org.tianocore.frameworkwizard.common.ui.IDialog;\r
35import org.tianocore.frameworkwizard.common.ui.IFrame;\r
36import org.tianocore.frameworkwizard.common.ui.StarLabel;\r
37import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;\r
38import org.tianocore.frameworkwizard.module.Identifications.LibraryClass.LibraryClassIdentification;\r
39import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r
40\r
41/**\r
42 The class is used to create, update Library Class Definition of MSA/MBD file\r
43 It extends IInternalFrame\r
44 \r
45 **/\r
46public class LibraryClassDefsDlg extends IDialog {\r
47\r
48 ///\r
49 /// Define class Serial Version UID\r
50 ///\r
51 private static final long serialVersionUID = -1743248695411382857L;\r
52\r
53 //\r
54 //Define class members\r
55 //\r
56 private JPanel jContentPane = null;\r
57\r
58 private JComboBox jComboBoxLibraryClassName = null;\r
59\r
60 private JLabel jLabelUsage = null;\r
61\r
62 private JComboBox jComboBoxUsage = null;\r
63\r
64 private JLabel jLabelLibraryClassName = null;\r
65\r
66 private JScrollPane jScrollPane = null;\r
67\r
68 private StarLabel jStarLabel1 = null;\r
69\r
70 private StarLabel jStarLabel2 = null;\r
71\r
72 private JLabel jLabelRecommendedInstanceVersion = null;\r
73\r
74 private JTextField jTextFieldRecommendedInstanceVersion = null;\r
75\r
76 private JLabel jLabelRecommendedInstanceGuid = null;\r
77\r
78 private JTextField jTextFieldRecommendedInstanceGuid = null;\r
79\r
80 private JButton jButtonGenerateGuid = null;\r
81\r
82 private JLabel jLabelFeatureFlag = null;\r
83\r
84 private JTextField jTextFieldFeatureFlag = null;\r
85\r
86 private JLabel jLabelArch = null;\r
87\r
88 private JLabel jLabelModuleList = null;\r
89\r
90 private JScrollPane jScrollPaneModuleList = null;\r
91\r
92 private ICheckBoxList iCheckBoxListModule = null;\r
93\r
94 private JLabel jLabelHelpText = null;\r
95\r
96 private JTextField jTextFieldHelpText = null;\r
97\r
98 private ArchCheckBox jArchCheckBox = null;\r
a929458e 99\r
06a19cee 100 private JButton jButtonOk = null;\r
101\r
102 private JButton jButtonCancel = null;\r
103\r
104 //\r
105 // Not for UI\r
106 //\r
107 private EnumerationData ed = new EnumerationData();\r
108\r
109 private WorkspaceTools wt = new WorkspaceTools();\r
110\r
111 private LibraryClassIdentification lcid = null;\r
112\r
113 /**\r
114 This method initializes jComboBoxSelect \r
115 \r
116 @return javax.swing.JComboBox jComboBoxSelect\r
117 \r
118 **/\r
119 private JComboBox getJComboBoxLibraryClassName() {\r
120 if (jComboBoxLibraryClassName == null) {\r
121 jComboBoxLibraryClassName = new JComboBox();\r
122 jComboBoxLibraryClassName.setBounds(new java.awt.Rectangle(160, 10, 320, 20));\r
123 jComboBoxLibraryClassName.setPreferredSize(new Dimension(320, 20));\r
124 jComboBoxLibraryClassName.setEnabled(true);\r
125 }\r
126 return jComboBoxLibraryClassName;\r
127 }\r
128\r
129 /**\r
130 This method initializes jComboBoxUsage \r
131 \r
132 @return javax.swing.JComboBox jComboBoxUsage\r
133 \r
134 **/\r
135 private JComboBox getJComboBoxUsage() {\r
136 if (jComboBoxUsage == null) {\r
137 jComboBoxUsage = new JComboBox();\r
138 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r
139 jComboBoxUsage.setPreferredSize(new Dimension(320, 20));\r
140 }\r
141 return jComboBoxUsage;\r
142 }\r
143\r
144 /**\r
145 This method initializes jScrollPane \r
146 \r
147 @return javax.swing.JScrollPane \r
148 */\r
149 private JScrollPane getJScrollPane() {\r
150 if (jScrollPane == null) {\r
151 jScrollPane = new JScrollPane();\r
152 jScrollPane.setViewportView(getJContentPane());\r
153 }\r
154 return jScrollPane;\r
155 }\r
156\r
157 /**\r
158 * This method initializes jTextFieldRecommendedInstanceVersion \r
159 * \r
160 * @return javax.swing.JTextField \r
161 */\r
162 private JTextField getJTextFieldRecommendedInstanceVersion() {\r
163 if (jTextFieldRecommendedInstanceVersion == null) {\r
164 jTextFieldRecommendedInstanceVersion = new JTextField();\r
165 jTextFieldRecommendedInstanceVersion.setPreferredSize(new java.awt.Dimension(260, 20));\r
166 jTextFieldRecommendedInstanceVersion.setSize(new java.awt.Dimension(260, 20));\r
167 jTextFieldRecommendedInstanceVersion.setLocation(new java.awt.Point(220, 85));\r
168 jTextFieldRecommendedInstanceVersion.setVisible(false);\r
169 }\r
170 return jTextFieldRecommendedInstanceVersion;\r
171 }\r
172\r
173 /**\r
174 * This method initializes jTextFieldRecommendedInstanceGuid \r
175 * \r
176 * @return javax.swing.JTextField \r
177 */\r
178 private JTextField getJTextFieldRecommendedInstanceGuid() {\r
179 if (jTextFieldRecommendedInstanceGuid == null) {\r
180 jTextFieldRecommendedInstanceGuid = new JTextField();\r
181 jTextFieldRecommendedInstanceGuid.setBounds(new java.awt.Rectangle(220, 110, 190, 20));\r
182 jTextFieldRecommendedInstanceGuid.setPreferredSize(new java.awt.Dimension(190, 20));\r
183 jTextFieldRecommendedInstanceGuid.setVisible(false);\r
184 }\r
185 return jTextFieldRecommendedInstanceGuid;\r
186 }\r
187\r
188 /**\r
189 * This method initializes jButtonGenerateGuid \r
190 * \r
191 * @return javax.swing.JButton \r
192 */\r
193 private JButton getJButtonGenerateGuid() {\r
194 if (jButtonGenerateGuid == null) {\r
195 jButtonGenerateGuid = new JButton();\r
196 jButtonGenerateGuid.setBounds(new java.awt.Rectangle(415, 110, 65, 20));\r
197 jButtonGenerateGuid.setPreferredSize(new java.awt.Dimension(65, 20));\r
198 jButtonGenerateGuid.setText("GEN");\r
199 jButtonGenerateGuid.setVisible(false);\r
200 jButtonGenerateGuid.addActionListener(this);\r
201 }\r
202 return jButtonGenerateGuid;\r
203 }\r
204\r
205 /**\r
206 * This method initializes jTextFieldFeatureFlag \r
207 * \r
208 * @return javax.swing.JTextField \r
209 */\r
210 private JTextField getJTextFieldFeatureFlag() {\r
211 if (jTextFieldFeatureFlag == null) {\r
212 jTextFieldFeatureFlag = new JTextField();\r
213 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 85, 320, 20));\r
214 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));\r
a929458e 215 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");\r
06a19cee 216 }\r
217 return jTextFieldFeatureFlag;\r
218 }\r
219\r
220 /**\r
221 This method initializes iCheckBoxListArch \r
222 \r
223 @return ICheckBoxList \r
224 **/\r
225 private ICheckBoxList getICheckBoxListSupModuleList() {\r
226 if (iCheckBoxListModule == null) {\r
227 iCheckBoxListModule = new ICheckBoxList();\r
228 }\r
229 return iCheckBoxListModule;\r
230 }\r
231\r
232 /**\r
233 This method initializes jScrollPaneModuleList \r
234 \r
235 @return javax.swing.JScrollPane \r
236 \r
237 **/\r
238 private JScrollPane getJScrollPaneModuleList() {\r
239 if (jScrollPaneModuleList == null) {\r
240 jScrollPaneModuleList = new JScrollPane();\r
241 jScrollPaneModuleList.setBounds(new java.awt.Rectangle(160, 135, 320, 80));\r
242 jScrollPaneModuleList.setPreferredSize(new java.awt.Dimension(320, 80));\r
243 jScrollPaneModuleList.setViewportView(getICheckBoxListSupModuleList());\r
244 }\r
245 return jScrollPaneModuleList;\r
246 }\r
247\r
248 /**\r
249 This method initializes jTextFieldHelpText \r
250 \r
251 @return javax.swing.JTextField \r
252 \r
253 **/\r
254 private JTextField getJTextFieldHelpText() {\r
255 if (jTextFieldHelpText == null) {\r
256 jTextFieldHelpText = new JTextField();\r
257 jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 60, 320, 20));\r
258 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));\r
259 }\r
260 return jTextFieldHelpText;\r
261 }\r
262\r
263 /**\r
264 This method initializes jButtonOk \r
265 \r
266 @return javax.swing.JButton \r
267 \r
268 **/\r
269 private JButton getJButtonOk() {\r
270 if (jButtonOk == null) {\r
271 jButtonOk = new JButton();\r
272 jButtonOk.setBounds(new java.awt.Rectangle(290, 225, 90, 20));\r
273 jButtonOk.setText("Ok");\r
274 jButtonOk.addActionListener(this);\r
275 }\r
276 return jButtonOk;\r
277 }\r
278\r
279 /**\r
280 This method initializes jButtonCancel \r
281 \r
282 @return javax.swing.JButton \r
283 \r
284 **/\r
285 private JButton getJButtonCancel() {\r
286 if (jButtonCancel == null) {\r
287 jButtonCancel = new JButton();\r
288 jButtonCancel.setBounds(new java.awt.Rectangle(390, 225, 90, 20));\r
289 jButtonCancel.setText("Cancel");\r
290 jButtonCancel.addActionListener(this);\r
291 }\r
292 return jButtonCancel;\r
293 }\r
294\r
295 public static void main(String[] args) {\r
296\r
297 }\r
298\r
299 /**\r
300 This is the default constructor\r
301 \r
302 **/\r
303 public LibraryClassDefsDlg(LibraryClassIdentification inLibraryClassIdentification, IFrame iFrame) {\r
304 super(iFrame, true);\r
305 init(inLibraryClassIdentification);\r
306 }\r
307\r
308 /**\r
309 This method initializes this\r
310 \r
311 **/\r
312 private void init() {\r
313 this.setContentPane(getJScrollPane());\r
314 this.setTitle("Library Class Definitions");\r
315 this.setBounds(new java.awt.Rectangle(0, 0, 500, 295));\r
316 initFrame();\r
317 this.setViewMode(false);\r
318 this.centerWindow();\r
319 }\r
320\r
321 /**\r
322 This method initializes this\r
323 \r
324 **/\r
325 private void init(LibraryClassIdentification inLibraryClassIdentification) {\r
326 init();\r
327 this.lcid = inLibraryClassIdentification;\r
328 if (lcid != null) {\r
329 this.jComboBoxLibraryClassName.setSelectedItem(lcid.getLibraryClassName());\r
330 this.jComboBoxUsage.setSelectedItem(lcid.getUsage());\r
331 this.jTextFieldRecommendedInstanceVersion.setText(lcid.getRecommendedInstanceVersion());\r
332 this.jTextFieldRecommendedInstanceGuid.setText(lcid.getRecommendedInstanceGuid());\r
333 this.jTextFieldFeatureFlag.setText(lcid.getFeatureFlag());\r
334 this.jArchCheckBox.setSelectedItems(lcid.getSupArchList());\r
335 this.iCheckBoxListModule.setAllItemsUnchecked();\r
336 this.iCheckBoxListModule.initCheckedItem(true, lcid.getSupModuleList());\r
337 this.jTextFieldHelpText.setText(lcid.getHelp());\r
338 }\r
339 }\r
340\r
341 /**\r
342 Disable all components when the mode is view\r
343 \r
344 @param isView true - The view mode; false - The non-view mode\r
345 \r
346 **/\r
347 public void setViewMode(boolean isView) {\r
348 if (isView) {\r
349 this.jComboBoxLibraryClassName.setEnabled(!isView);\r
350 this.jComboBoxUsage.setEnabled(!isView);\r
351 }\r
352 }\r
353\r
354 /**\r
355 This method initializes jContentPane\r
356 \r
357 @return javax.swing.JPanel jContentPane\r
358 \r
359 **/\r
360 private JPanel getJContentPane() {\r
361 if (jContentPane == null) {\r
362 jArchCheckBox = new ArchCheckBox();\r
363 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 110, 320, 20));\r
364 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));\r
365 jLabelHelpText = new JLabel();\r
ccb063b1 366 jLabelHelpText.setBounds(new java.awt.Rectangle(15, 60, 140, 20));\r
06a19cee 367 jLabelHelpText.setText("Help Text");\r
368 jLabelModuleList = new JLabel();\r
369 jLabelModuleList.setBounds(new java.awt.Rectangle(15, 135, 140, 20));\r
ccb063b1 370 jLabelModuleList.setText("Supported Module Types");\r
06a19cee 371 jLabelArch = new JLabel();\r
372 jLabelArch.setBounds(new java.awt.Rectangle(15, 110, 140, 20));\r
ccb063b1 373 jLabelArch.setText("Supported Architectures");\r
06a19cee 374 jLabelFeatureFlag = new JLabel();\r
375 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 85, 140, 20));\r
a929458e 376 jLabelFeatureFlag.setText("Feature Flag Expression");\r
06a19cee 377 jLabelRecommendedInstanceGuid = new JLabel();\r
378 jLabelRecommendedInstanceGuid.setBounds(new java.awt.Rectangle(15, 110, 200, 20));\r
379 jLabelRecommendedInstanceGuid.setText("Recommended Instance Guid");\r
380 jLabelRecommendedInstanceGuid.setVisible(false);\r
381 jLabelRecommendedInstanceVersion = new JLabel();\r
382 jLabelRecommendedInstanceVersion.setBounds(new java.awt.Rectangle(15, 85, 200, 20));\r
383 jLabelRecommendedInstanceVersion.setText("Recommended Instance Version");\r
384 jLabelRecommendedInstanceVersion.setVisible(false);\r
385 jLabelLibraryClassName = new JLabel();\r
386 jLabelLibraryClassName.setBounds(new java.awt.Rectangle(15, 10, 140, 20));\r
387 jLabelLibraryClassName.setText("Library Class Name");\r
388 jLabelUsage = new JLabel();\r
389 jLabelUsage.setBounds(new java.awt.Rectangle(15, 35, 140, 20));\r
390 jLabelUsage.setText("Usage");\r
391 jContentPane = new JPanel();\r
392 jContentPane.setLayout(null);\r
393 jContentPane.setPreferredSize(new java.awt.Dimension(490, 245));\r
394\r
395 jContentPane.add(getJComboBoxLibraryClassName(), null);\r
396 jContentPane.add(jLabelUsage, null);\r
397 jContentPane.add(getJComboBoxUsage(), null);\r
398 jContentPane.add(jLabelLibraryClassName, null);\r
399 jContentPane.add(jLabelRecommendedInstanceVersion, null);\r
400 jContentPane.add(getJTextFieldRecommendedInstanceVersion(), null);\r
401 jContentPane.add(jLabelRecommendedInstanceGuid, null);\r
402 jContentPane.add(getJTextFieldRecommendedInstanceGuid(), null);\r
403 jContentPane.add(getJButtonGenerateGuid(), null);\r
404 jContentPane.add(jLabelFeatureFlag, null);\r
405 jContentPane.add(getJTextFieldFeatureFlag(), null);\r
406 jContentPane.add(jLabelArch, null);\r
407 jStarLabel1 = new StarLabel();\r
ccb063b1 408 jStarLabel1.setLocation(new java.awt.Point(2, 10));\r
06a19cee 409 jStarLabel2 = new StarLabel();\r
ccb063b1 410 jStarLabel2.setLocation(new java.awt.Point(2, 35));\r
06a19cee 411\r
412 jContentPane.add(jStarLabel1, null);\r
413 jContentPane.add(jStarLabel2, null);\r
414 jContentPane.add(jLabelModuleList, null);\r
415 jContentPane.add(getJScrollPaneModuleList(), null);\r
416 jContentPane.add(jLabelHelpText, null);\r
417 jContentPane.add(getJTextFieldHelpText(), null);\r
418 jContentPane.add(jArchCheckBox, null);\r
419 jContentPane.add(getJButtonOk(), null);\r
420 jContentPane.add(getJButtonCancel(), null);\r
421 }\r
422 return jContentPane;\r
423 }\r
424\r
425 /**\r
426 This method initializes all existing libraries and usage types\r
427 \r
428 **/\r
429 private void initFrame() {\r
430 Tools.generateComboBoxByVector(jComboBoxLibraryClassName, wt.getAllLibraryClassDefinitionsFromWorkspace());\r
431 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVLibraryUsage());\r
432 this.iCheckBoxListModule.setAllItems(ed.getVFrameworkModuleTypes());\r
433 }\r
434\r
435 /* (non-Javadoc)\r
436 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
437 *\r
438 * Override actionPerformed to listen all actions\r
439 * \r
440 */\r
441 public void actionPerformed(ActionEvent arg0) {\r
442 if (arg0.getSource() == jButtonGenerateGuid) {\r
443 this.jTextFieldRecommendedInstanceGuid.setText(Tools.generateUuidString());\r
444 }\r
445\r
446 if (arg0.getSource() == jButtonOk) {\r
447 if (checkAdd()) {\r
448 getCurrentLibraryClass();\r
449 this.returnType = DataType.RETURN_TYPE_OK;\r
450 this.setVisible(false);\r
451 }\r
452 }\r
453\r
454 if (arg0.getSource() == jButtonCancel) {\r
455 this.returnType = DataType.RETURN_TYPE_CANCEL;\r
456 this.setVisible(false);\r
457 }\r
458 }\r
459\r
460 /**\r
461 Data validation for all fields\r
462 \r
463 @retval true - All datas are valid\r
464 @retval false - At least one data is invalid\r
465 \r
466 **/\r
467 public boolean checkAdd() {\r
468 //\r
469 // Check LibraryClass\r
470 //\r
471 if (this.jComboBoxLibraryClassName.getSelectedItem() == null) {\r
ed1665f2 472 Log.wrn("Update Library Class Definitions", "No Library Class can be added");\r
06a19cee 473 return false;\r
474 }\r
475 if (!DataValidation.isLibraryClass(this.jComboBoxLibraryClassName.getSelectedItem().toString())) {\r
ed1665f2 476 Log.wrn("Update Library Class Definitions", "Incorrect data type for Library Class");\r
06a19cee 477 return false;\r
478 }\r
479\r
480 //\r
481 // Check RecommendedInstanceVersion\r
482 //\r
483 // if (!isEmpty(this.jTextFieldRecommendedInstanceVersion.getText())) {\r
484 // if (!DataValidation.isRecommendedInstanceVersion(this.jTextFieldRecommendedInstanceVersion.getText())) {\r
485 // Log.err("Incorrect data type for Recommended Instance Version");\r
486 // return false;\r
487 // }\r
488 // }\r
489\r
490 //\r
491 // Check RecommendedInstanceGuid\r
492 //\r
493 // if (!isEmpty(this.jTextFieldRecommendedInstanceGuid.getText())) {\r
494 // if (!DataValidation.isGuid(this.jTextFieldRecommendedInstanceGuid.getText())) {\r
495 // Log.err("Incorrect data type for Recommended Instance Guid");\r
496 // return false;\r
497 // }\r
498 // }\r
499\r
500 //\r
501 // Check FeatureFlag\r
502 //\r
503 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r
504 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r
ed1665f2 505 Log.wrn("Update Library Class Definitions", "Incorrect data type for Feature Flag");\r
06a19cee 506 return false;\r
507 }\r
508 }\r
509\r
510 return true;\r
511 }\r
512\r
513 private LibraryClassIdentification getCurrentLibraryClass() {\r
514 String name = this.jComboBoxLibraryClassName.getSelectedItem().toString();\r
515 String usage = this.jComboBoxUsage.getSelectedItem().toString();\r
516 String version = this.jTextFieldRecommendedInstanceVersion.getText();\r
517 String guid = this.jTextFieldRecommendedInstanceGuid.getText();\r
518 String featureFlag = this.jTextFieldFeatureFlag.getText();\r
519 Vector<String> arch = this.jArchCheckBox.getSelectedItemsVector();\r
520 Vector<String> module = this.iCheckBoxListModule.getAllCheckedItemsString();\r
521 String help = this.jTextFieldHelpText.getText();\r
522 lcid = new LibraryClassIdentification(name, usage, version, guid, arch, featureFlag, module, help);\r
523 return lcid;\r
524 }\r
525\r
526 public LibraryClassIdentification getLcid() {\r
527 return lcid;\r
528 }\r
529\r
530 public void setLcid(LibraryClassIdentification lcid) {\r
531 this.lcid = lcid;\r
532 }\r
533}\r