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