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