8b5dfd980b182daafa89af793fc37db120ecf119
[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 of MSA/MBD 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, 87, 320, 20));
215 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
216 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
217 }
218 return jTextFieldFeatureFlag;
219 }
220
221 /**
222 This method initializes iCheckBoxListArch
223
224 @return ICheckBoxList
225 **/
226 private ICheckBoxList getICheckBoxListSupModuleList() {
227 if (iCheckBoxListModule == null) {
228 iCheckBoxListModule = new ICheckBoxList();
229 }
230 return iCheckBoxListModule;
231 }
232
233 /**
234 This method initializes jScrollPaneModuleList
235
236 @return javax.swing.JScrollPane
237
238 **/
239 private JScrollPane getJScrollPaneModuleList() {
240 if (jScrollPaneModuleList == null) {
241 jScrollPaneModuleList = new JScrollPane();
242 jScrollPaneModuleList.setBounds(new java.awt.Rectangle(168, 137, 320, 80));
243 jScrollPaneModuleList.setPreferredSize(new java.awt.Dimension(320, 80));
244 jScrollPaneModuleList.setViewportView(getICheckBoxListSupModuleList());
245 }
246 return jScrollPaneModuleList;
247 }
248
249 /**
250 This method initializes jTextFieldHelpText
251
252 @return javax.swing.JTextField
253
254 **/
255 private JTextField getJTextFieldHelpText() {
256 if (jTextFieldHelpText == null) {
257 jTextFieldHelpText = new JTextField();
258 jTextFieldHelpText.setBounds(new java.awt.Rectangle(168, 62, 320, 20));
259 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));
260 }
261 return jTextFieldHelpText;
262 }
263
264 /**
265 This method initializes jButtonOk
266
267 @return javax.swing.JButton
268
269 **/
270 private JButton getJButtonOk() {
271 if (jButtonOk == null) {
272 jButtonOk = new JButton();
273 jButtonOk.setBounds(new java.awt.Rectangle(300, 232, 90, 20));
274 jButtonOk.setText("Ok");
275 jButtonOk.addActionListener(this);
276 }
277 return jButtonOk;
278 }
279
280 /**
281 This method initializes jButtonCancel
282
283 @return javax.swing.JButton
284
285 **/
286 private JButton getJButtonCancel() {
287 if (jButtonCancel == null) {
288 jButtonCancel = new JButton();
289 jButtonCancel.setBounds(new java.awt.Rectangle(400, 232, 90, 20));
290 jButtonCancel.setText("Cancel");
291 jButtonCancel.addActionListener(this);
292 }
293 return jButtonCancel;
294 }
295
296 public static void main(String[] args) {
297
298 }
299
300 /**
301 This is the default constructor
302
303 **/
304 public LibraryClassDefsDlg(LibraryClassIdentification inLibraryClassIdentification, IFrame iFrame) {
305 super(iFrame, true);
306 init(inLibraryClassIdentification);
307 }
308
309 /**
310 This method initializes this
311
312 **/
313 private void init() {
314 this.setContentPane(getJScrollPane());
315 this.setTitle("Library Class Definitions");
316 this.setBounds(new java.awt.Rectangle(0, 0, 505, 305));
317 initFrame();
318 this.setViewMode(false);
319 this.centerWindow();
320 }
321
322 /**
323 This method initializes this
324
325 **/
326 private void init(LibraryClassIdentification inLibraryClassIdentification) {
327 init();
328 this.lcid = inLibraryClassIdentification;
329 if (lcid != null) {
330 this.jComboBoxLibraryClassName.setSelectedItem(lcid.getLibraryClassName());
331 this.jComboBoxUsage.setSelectedItem(lcid.getUsage());
332 this.jTextFieldRecommendedInstanceVersion.setText(lcid.getRecommendedInstanceVersion());
333 this.jTextFieldRecommendedInstanceGuid.setText(lcid.getRecommendedInstanceGuid());
334 this.jTextFieldFeatureFlag.setText(lcid.getFeatureFlag());
335 this.jArchCheckBox.setSelectedItems(lcid.getSupArchList());
336 this.iCheckBoxListModule.setAllItemsUnchecked();
337 this.iCheckBoxListModule.initCheckedItem(true, lcid.getSupModuleList());
338 this.jTextFieldHelpText.setText(lcid.getHelp());
339 }
340 }
341
342 /**
343 Disable all components when the mode is view
344
345 @param isView true - The view mode; false - The non-view mode
346
347 **/
348 public void setViewMode(boolean isView) {
349 if (isView) {
350 this.jComboBoxLibraryClassName.setEnabled(!isView);
351 this.jComboBoxUsage.setEnabled(!isView);
352 }
353 }
354
355 /**
356 This method initializes jContentPane
357
358 @return javax.swing.JPanel jContentPane
359
360 **/
361 private JPanel getJContentPane() {
362 if (jContentPane == null) {
363 jArchCheckBox = new ArchCheckBox();
364 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 112, 320, 20));
365 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
366 jLabelHelpText = new JLabel();
367 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 62, 168, 20));
368 jLabelHelpText.setText("Help Text");
369 jLabelModuleList = new JLabel();
370 jLabelModuleList.setBounds(new java.awt.Rectangle(12, 137, 168, 20));
371 jLabelModuleList.setText("Supported Module Types");
372 jLabelArch = new JLabel();
373 jLabelArch.setBounds(new java.awt.Rectangle(12, 112, 168, 20));
374 jLabelArch.setText("Supported Architectures");
375 jLabelFeatureFlag = new JLabel();
376 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 87, 168, 20));
377 jLabelFeatureFlag.setText("Feature Flag Expression");
378 jLabelRecommendedInstanceGuid = new JLabel();
379 jLabelRecommendedInstanceGuid.setBounds(new java.awt.Rectangle(12, 112, 200, 20));
380 jLabelRecommendedInstanceGuid.setText("Recommended Instance Guid");
381 jLabelRecommendedInstanceGuid.setVisible(false);
382 jLabelRecommendedInstanceVersion = new JLabel();
383 jLabelRecommendedInstanceVersion.setBounds(new java.awt.Rectangle(12, 87, 200, 20));
384 jLabelRecommendedInstanceVersion.setText("Recommended Instance Version");
385 jLabelRecommendedInstanceVersion.setVisible(false);
386 jLabelLibraryClassName = new JLabel();
387 jLabelLibraryClassName.setBounds(new java.awt.Rectangle(12, 12, 168, 20));
388 jLabelLibraryClassName.setText("Library Class Name");
389 jLabelUsage = new JLabel();
390 jLabelUsage.setBounds(new java.awt.Rectangle(12, 37, 168, 20));
391 jLabelUsage.setText("Usage");
392 jContentPane = new JPanel();
393 jContentPane.setLayout(null);
394 jContentPane.setPreferredSize(new java.awt.Dimension(495, 255));
395
396 jContentPane.add(getJComboBoxLibraryClassName(), null);
397 jContentPane.add(jLabelUsage, null);
398 jContentPane.add(getJComboBoxUsage(), null);
399 jContentPane.add(jLabelLibraryClassName, null);
400 jContentPane.add(jLabelRecommendedInstanceVersion, null);
401 jContentPane.add(getJTextFieldRecommendedInstanceVersion(), null);
402 jContentPane.add(jLabelRecommendedInstanceGuid, null);
403 jContentPane.add(getJTextFieldRecommendedInstanceGuid(), null);
404 jContentPane.add(getJButtonGenerateGuid(), null);
405 jContentPane.add(jLabelFeatureFlag, null);
406 jContentPane.add(getJTextFieldFeatureFlag(), null);
407 jContentPane.add(jLabelArch, null);
408 jStarLabel1 = new StarLabel();
409 jStarLabel1.setLocation(new java.awt.Point(2, 10));
410 jStarLabel2 = new StarLabel();
411 jStarLabel2.setLocation(new java.awt.Point(2, 35));
412
413 jContentPane.add(jStarLabel1, null);
414 jContentPane.add(jStarLabel2, null);
415 jContentPane.add(jLabelModuleList, null);
416 jContentPane.add(getJScrollPaneModuleList(), null);
417 jContentPane.add(jLabelHelpText, null);
418 jContentPane.add(getJTextFieldHelpText(), null);
419 jContentPane.add(jArchCheckBox, null);
420 jContentPane.add(getJButtonOk(), null);
421 jContentPane.add(getJButtonCancel(), null);
422 }
423 return jContentPane;
424 }
425
426 /**
427 This method initializes all existing libraries and usage types
428
429 **/
430 private void initFrame() {
431 Tools.generateComboBoxByVector(jComboBoxLibraryClassName, wt.getAllLibraryClassDefinitionsFromWorkspace());
432 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVLibraryUsage());
433 this.iCheckBoxListModule.setAllItems(ed.getVFrameworkModuleTypes());
434 }
435
436 /* (non-Javadoc)
437 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
438 *
439 * Override actionPerformed to listen all actions
440 *
441 */
442 public void actionPerformed(ActionEvent arg0) {
443 if (arg0.getSource() == jButtonGenerateGuid) {
444 this.jTextFieldRecommendedInstanceGuid.setText(Tools.generateUuidString());
445 }
446
447 if (arg0.getSource() == jButtonOk) {
448 if (checkAdd()) {
449 getCurrentLibraryClass();
450 this.returnType = DataType.RETURN_TYPE_OK;
451 this.setVisible(false);
452 }
453 }
454
455 if (arg0.getSource() == jButtonCancel) {
456 this.returnType = DataType.RETURN_TYPE_CANCEL;
457 this.setVisible(false);
458 }
459 }
460
461 /**
462 Data validation for all fields
463
464 @retval true - All datas are valid
465 @retval false - At least one data is invalid
466
467 **/
468 public boolean checkAdd() {
469 //
470 // Check LibraryClass
471 //
472 if (this.jComboBoxLibraryClassName.getSelectedItem() == null) {
473 Log.wrn("Update Library Class Definitions", "No Library Class can be added");
474 return false;
475 }
476 if (!DataValidation.isLibraryClass(this.jComboBoxLibraryClassName.getSelectedItem().toString())) {
477 Log.wrn("Update Library Class Definitions", "Incorrect data type for Library Class");
478 return false;
479 }
480
481 //
482 // Check RecommendedInstanceVersion
483 //
484 // if (!isEmpty(this.jTextFieldRecommendedInstanceVersion.getText())) {
485 // if (!DataValidation.isRecommendedInstanceVersion(this.jTextFieldRecommendedInstanceVersion.getText())) {
486 // Log.err("Incorrect data type for Recommended Instance Version");
487 // return false;
488 // }
489 // }
490
491 //
492 // Check RecommendedInstanceGuid
493 //
494 // if (!isEmpty(this.jTextFieldRecommendedInstanceGuid.getText())) {
495 // if (!DataValidation.isGuid(this.jTextFieldRecommendedInstanceGuid.getText())) {
496 // Log.err("Incorrect data type for Recommended Instance Guid");
497 // return false;
498 // }
499 // }
500
501 //
502 // Check FeatureFlag
503 //
504 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
505 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
506 Log.wrn("Update Library Class Definitions", "Incorrect data type for Feature Flag");
507 return false;
508 }
509 }
510
511 return true;
512 }
513
514 private LibraryClassIdentification getCurrentLibraryClass() {
515 String name = this.jComboBoxLibraryClassName.getSelectedItem().toString();
516 String usage = this.jComboBoxUsage.getSelectedItem().toString();
517 String version = this.jTextFieldRecommendedInstanceVersion.getText();
518 String guid = this.jTextFieldRecommendedInstanceGuid.getText();
519 String featureFlag = this.jTextFieldFeatureFlag.getText();
520 Vector<String> arch = this.jArchCheckBox.getSelectedItemsVector();
521 Vector<String> module = this.iCheckBoxListModule.getAllCheckedItemsString();
522 String help = this.jTextFieldHelpText.getText();
523 lcid = new LibraryClassIdentification(name, usage, version, guid, arch, featureFlag, module, help);
524 return lcid;
525 }
526
527 public LibraryClassIdentification getLcid() {
528 return lcid;
529 }
530
531 public void setLcid(LibraryClassIdentification lcid) {
532 this.lcid = lcid;
533 }
534 }