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