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