3 The file is used to create, update Library Class Definition of MSA/MBD file
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
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.
15 package org
.tianocore
.packaging
.module
.ui
;
17 import java
.awt
.event
.ActionEvent
;
19 import javax
.swing
.DefaultListModel
;
20 import javax
.swing
.JButton
;
21 import javax
.swing
.JComboBox
;
22 import javax
.swing
.JLabel
;
23 import javax
.swing
.JList
;
24 import javax
.swing
.JPanel
;
25 import javax
.swing
.JRadioButton
;
26 import javax
.swing
.JScrollPane
;
27 import javax
.swing
.JTextField
;
29 import org
.tianocore
.LibraryClassDefinitionsDocument
;
30 import org
.tianocore
.LibraryClassDocument
;
31 import org
.tianocore
.LibraryUsage
;
32 import org
.tianocore
.common
.DataValidation
;
33 import org
.tianocore
.common
.Log
;
34 import org
.tianocore
.packaging
.common
.ui
.IInternalFrame
;
37 The class is used to create, update Library Class Definition of MSA/MBD file
38 It extends IInternalFrame
40 @since ModuleEditor 1.0
43 public class ModuleLibraryClassDefinitions
extends IInternalFrame
{
46 /// Define class Serial Version UID
48 private static final long serialVersionUID
= -1743248695411382857L;
51 //Define class members
53 private static String Separator
= "::";
55 private DefaultListModel listItem
= new DefaultListModel();
57 private LibraryClassDefinitionsDocument
.LibraryClassDefinitions libraryClassDefinitions
= null;
59 private JPanel jContentPane
= null;
61 private JRadioButton jRadioButtonAdd
= null;
63 private JRadioButton jRadioButtonSelect
= null;
65 private JTextField jTextFieldAdd
= null;
67 private JComboBox jComboBoxSelect
= null;
69 private JLabel jLabelUsage
= null;
71 private JComboBox jComboBoxUsage
= null;
73 private JScrollPane jScrollPane
= null;
75 private JList jListLibraryClassDefinitions
= null;
77 private JButton jButtonAdd
= null;
79 private JButton jButtonRemove
= null;
81 private JButton jButtonClearAll
= null;
83 private JButton jButtonCancel
= null;
85 private JButton jButtonOk
= null;
88 This method initializes jRadioButtonAdd
90 @return javax.swing.JRadioButton jRadioButtonAdd
93 private JRadioButton
getJRadioButtonAdd() {
94 if (jRadioButtonAdd
== null) {
95 jRadioButtonAdd
= new JRadioButton();
96 jRadioButtonAdd
.setBounds(new java
.awt
.Rectangle(15, 35, 205, 20));
97 jRadioButtonAdd
.setText("Add a new Library Class");
98 jRadioButtonAdd
.addActionListener(this);
99 jRadioButtonAdd
.setSelected(false);
101 return jRadioButtonAdd
;
105 This method initializes jRadioButtonSelect
107 @return javax.swing.JRadioButton jRadioButtonSelect
110 private JRadioButton
getJRadioButtonSelect() {
111 if (jRadioButtonSelect
== null) {
112 jRadioButtonSelect
= new JRadioButton();
113 jRadioButtonSelect
.setBounds(new java
.awt
.Rectangle(15, 10, 205, 20));
114 jRadioButtonSelect
.setText("Select an existed Library Class");
115 jRadioButtonSelect
.addActionListener(this);
116 jRadioButtonSelect
.setSelected(true);
118 return jRadioButtonSelect
;
122 This method initializes jTextFieldAdd
124 @return javax.swing.JTextField jTextFieldAdd
127 private JTextField
getJTextFieldAdd() {
128 if (jTextFieldAdd
== null) {
129 jTextFieldAdd
= new JTextField();
130 jTextFieldAdd
.setBounds(new java
.awt
.Rectangle(220, 35, 260, 20));
131 jTextFieldAdd
.setEnabled(false);
133 return jTextFieldAdd
;
137 This method initializes jComboBoxSelect
139 @return javax.swing.JComboBox jComboBoxSelect
142 private JComboBox
getJComboBoxSelect() {
143 if (jComboBoxSelect
== null) {
144 jComboBoxSelect
= new JComboBox();
145 jComboBoxSelect
.setBounds(new java
.awt
.Rectangle(220, 10, 260, 20));
146 jComboBoxSelect
.setEnabled(true);
148 return jComboBoxSelect
;
152 This method initializes jComboBoxUsage
154 @return javax.swing.JComboBox jComboBoxUsage
157 private JComboBox
getJComboBoxUsage() {
158 if (jComboBoxUsage
== null) {
159 jComboBoxUsage
= new JComboBox();
160 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(220, 60, 260, 20));
162 return jComboBoxUsage
;
166 This method initializes jScrollPane
168 @return javax.swing.JScrollPane jScrollPane
171 private JScrollPane
getJScrollPane() {
172 if (jScrollPane
== null) {
173 jScrollPane
= new JScrollPane();
174 jScrollPane
.setBounds(new java
.awt
.Rectangle(15, 95, 350, 200));
175 jScrollPane
.setViewportView(getJListLibraryClassDefinitions());
181 This method initializes jListLibraryClassDefinitions
183 @return javax.swing.JList jListLibraryClassDefinitions
186 private JList
getJListLibraryClassDefinitions() {
187 if (jListLibraryClassDefinitions
== null) {
188 jListLibraryClassDefinitions
= new JList(listItem
);
190 return jListLibraryClassDefinitions
;
194 This method initializes jButtonAdd
196 @return javax.swing.JButton jButtonAdd
199 private JButton
getJButtonAdd() {
200 if (jButtonAdd
== null) {
201 jButtonAdd
= new JButton();
202 jButtonAdd
.setBounds(new java
.awt
.Rectangle(380, 115, 90, 20));
203 jButtonAdd
.setText("Add");
204 jButtonAdd
.addActionListener(this);
210 This method initializes jButtonRemove
212 @return javax.swing.JButton jButtonRemove
215 private JButton
getJButtonRemove() {
216 if (jButtonRemove
== null) {
217 jButtonRemove
= new JButton();
218 jButtonRemove
.setBounds(new java
.awt
.Rectangle(380, 230, 90, 20));
219 jButtonRemove
.setText("Remove");
220 jButtonRemove
.addActionListener(this);
222 return jButtonRemove
;
226 This method initializes jButtonRemoveAll
228 @return javax.swing.JButton jButtonClearAll
231 private JButton
getJButtonClearAll() {
232 if (jButtonClearAll
== null) {
233 jButtonClearAll
= new JButton();
234 jButtonClearAll
.setBounds(new java
.awt
.Rectangle(380, 260, 90, 20));
235 jButtonClearAll
.setText("Clear All");
236 jButtonClearAll
.addActionListener(this);
238 return jButtonClearAll
;
242 This method initializes jButtonCancel
244 @return javax.swing.JButton jButtonCancel
247 private JButton
getJButtonCancel() {
248 if (jButtonCancel
== null) {
249 jButtonCancel
= new JButton();
250 jButtonCancel
.setPreferredSize(new java
.awt
.Dimension(90, 20));
251 jButtonCancel
.setLocation(new java
.awt
.Point(390, 305));
252 jButtonCancel
.setText("Cancel");
253 jButtonCancel
.setSize(new java
.awt
.Dimension(90, 20));
254 jButtonCancel
.addActionListener(this);
256 return jButtonCancel
;
260 This method initializes jButtonOk
262 @return javax.swing.JButton jButtonOk
265 private JButton
getJButtonOk() {
266 if (jButtonOk
== null) {
267 jButtonOk
= new JButton();
268 jButtonOk
.setSize(new java
.awt
.Dimension(90, 20));
269 jButtonOk
.setText("OK");
270 jButtonOk
.setLocation(new java
.awt
.Point(290, 305));
271 jButtonOk
.addActionListener(this);
276 public static void main(String
[] args
) {
281 This is the default constructor
284 public ModuleLibraryClassDefinitions() {
287 this.setVisible(true);
291 This is the override edit constructor
293 @param inLibraryClassDefinitions The input data of LibraryClassDefinitionsDocument.LibraryClassDefinitions
296 public ModuleLibraryClassDefinitions(
297 LibraryClassDefinitionsDocument
.LibraryClassDefinitions inLibraryClassDefinitions
) {
299 init(inLibraryClassDefinitions
);
300 this.setVisible(true);
304 This method initializes this
305 Fill values to all fields if these values are not empty
307 @param inLibraryClassDefinitions The input data of LibraryClassDefinitionsDocument.LibraryClassDefinitions
310 private void init(LibraryClassDefinitionsDocument
.LibraryClassDefinitions inLibraryClassDefinitions
) {
312 this.setLibraryClassDefinitions(inLibraryClassDefinitions
);
313 if (this.libraryClassDefinitions
!= null) {
314 if (this.libraryClassDefinitions
.getLibraryClassList().size() > 0) {
315 for (int index
= 0; index
< this.libraryClassDefinitions
.getLibraryClassList().size(); index
++) {
316 listItem
.addElement(this.libraryClassDefinitions
.getLibraryClassArray(index
).getUsage().toString()
317 + ModuleLibraryClassDefinitions
.Separator
318 + this.libraryClassDefinitions
.getLibraryClassArray(index
).getStringValue());
319 this.libraryClassDefinitions
.getLibraryClassList();
326 This method initializes this
329 private void init() {
330 this.setContentPane(getJContentPane());
331 this.setTitle("Library Class Definitions");
332 this.setBounds(new java
.awt
.Rectangle(0, 0, 500, 515));
333 //this.centerWindow();
335 this.setViewMode(false);
339 Disable all components when the mode is view
341 @param isView true - The view mode; false - The non-view mode
344 public void setViewMode(boolean isView
) {
345 this.jButtonOk
.setVisible(false);
346 this.jButtonCancel
.setVisible(false);
348 this.jRadioButtonAdd
.setEnabled(!isView
);
349 this.jRadioButtonSelect
.setEnabled(!isView
);
350 this.jTextFieldAdd
.setEnabled(!isView
);
351 this.jComboBoxSelect
.setEnabled(!isView
);
352 this.jComboBoxUsage
.setEnabled(!isView
);
353 this.jButtonAdd
.setEnabled(!isView
);
354 this.jButtonRemove
.setEnabled(!isView
);
355 this.jButtonClearAll
.setEnabled(!isView
);
356 this.jButtonCancel
.setEnabled(!isView
);
357 this.jButtonOk
.setEnabled(!isView
);
362 This method initializes jContentPane
364 @return javax.swing.JPanel jContentPane
367 private JPanel
getJContentPane() {
368 if (jContentPane
== null) {
369 jLabelUsage
= new JLabel();
370 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 60, 205, 20));
371 jLabelUsage
.setText("Usage");
372 jContentPane
= new JPanel();
373 jContentPane
.setLayout(null);
374 jContentPane
.add(getJRadioButtonAdd(), null);
375 jContentPane
.add(getJRadioButtonSelect(), null);
376 jContentPane
.add(getJTextFieldAdd(), null);
377 jContentPane
.add(getJComboBoxSelect(), null);
378 jContentPane
.add(jLabelUsage
, null);
379 jContentPane
.add(getJComboBoxUsage(), null);
380 jContentPane
.add(getJScrollPane(), null);
381 jContentPane
.add(getJButtonAdd(), null);
382 jContentPane
.add(getJButtonRemove(), null);
383 jContentPane
.add(getJButtonClearAll(), null);
384 jContentPane
.add(getJButtonCancel(), null);
385 jContentPane
.add(getJButtonOk(), null);
391 This method initializes all existing libraries and usage types
394 private void initFrame() {
395 jComboBoxSelect
.addItem("BaseCpuICacheFlush");
396 jComboBoxSelect
.addItem("BaseDebugLibNull");
397 jComboBoxSelect
.addItem("BaseDebugLibReportStatusCode");
398 jComboBoxSelect
.addItem("BaseIoLibIntrinsic");
399 jComboBoxSelect
.addItem("BaseLib");
400 jComboBoxSelect
.addItem("BaseMemoryLib");
401 jComboBoxSelect
.addItem("BaseMemoryLibMmx");
402 jComboBoxSelect
.addItem("BaseMemoryLibSse2");
403 jComboBoxSelect
.addItem("BasePeCoffGetEntryPointLib");
404 jComboBoxSelect
.addItem("BasePeCoffLib");
405 jComboBoxSelect
.addItem("BasePrintLib");
406 jComboBoxSelect
.addItem("BaseReportStatusCodeLibNull");
407 jComboBoxSelect
.addItem("CommonPciCf8Lib");
408 jComboBoxSelect
.addItem("CommonPciExpressLib");
409 jComboBoxSelect
.addItem("CommonPciLibCf8");
410 jComboBoxSelect
.addItem("CommonPciLibPciExpress");
411 jComboBoxSelect
.addItem("DxeCoreEntryPoint");
412 jComboBoxSelect
.addItem("DxeHobLib");
413 jComboBoxSelect
.addItem("DxeIoLibCpuIo");
414 jComboBoxSelect
.addItem("DxeLib");
415 jComboBoxSelect
.addItem("DxePcdLib");
416 jComboBoxSelect
.addItem("DxeReportStatusCodeLib");
417 jComboBoxSelect
.addItem("DxeServicesTableLib");
418 jComboBoxSelect
.addItem("PeiCoreEntryPoint");
419 jComboBoxSelect
.addItem("PeiMemoryLib");
420 jComboBoxSelect
.addItem("PeimEntryPoint");
421 jComboBoxSelect
.addItem("PeiReportStatusCodeLib");
422 jComboBoxSelect
.addItem("PeiServicesTablePointerLib");
423 jComboBoxSelect
.addItem("PeiServicesTablePointerLibMm7");
424 jComboBoxSelect
.addItem("UefiDebugLibConOut");
425 jComboBoxSelect
.addItem("UefiDebugLibStdErr");
426 jComboBoxSelect
.addItem("UefiDriverEntryPointMultiple");
427 jComboBoxSelect
.addItem("UefiDriverEntryPointSingle");
428 jComboBoxSelect
.addItem("UefiDriverEntryPointSingleUnload");
429 jComboBoxSelect
.addItem("UefiDriverModelLib");
430 jComboBoxSelect
.addItem("UefiDriverModelLibNoConfigNoDiag");
431 jComboBoxSelect
.addItem("UefiLib");
432 jComboBoxSelect
.addItem("UefiMemoryLib");
434 jComboBoxUsage
.addItem("ALWAYS_CONSUMED");
435 jComboBoxUsage
.addItem("SOMETIMES_CONSUMED");
436 jComboBoxUsage
.addItem("ALWAYS_PRODUCED");
437 jComboBoxUsage
.addItem("SOMETIMES_PRODUCED");
438 jComboBoxUsage
.addItem("DEFAULT");
439 jComboBoxUsage
.addItem("PRIVATE");
443 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
445 * Override actionPerformed to listen all actions
448 public void actionPerformed(ActionEvent arg0
) {
449 if (arg0
.getSource() == jButtonOk
) {
451 this.setEdited(true);
454 if (arg0
.getSource() == jButtonCancel
) {
456 this.setEdited(false);
460 // Add current Library and its usage to the list
462 if (arg0
.getSource() == jButtonAdd
) {
466 String strLibClass
= "";
467 String strUsage
= "";
468 if (jRadioButtonAdd
.isSelected()) {
469 strLibClass
= jTextFieldAdd
.getText();
471 if (jRadioButtonSelect
.isSelected()) {
472 strLibClass
= jComboBoxSelect
.getSelectedItem().toString();
474 strUsage
= jComboBoxUsage
.getSelectedItem().toString();
475 listItem
.addElement(strUsage
+ ModuleLibraryClassDefinitions
.Separator
+ strLibClass
);
479 // Remove current Library and its usage of the list
481 if (arg0
.getSource() == jButtonRemove
) {
482 int intSelected
[] = jListLibraryClassDefinitions
.getSelectedIndices();
483 if (intSelected
.length
> 0) {
484 for (int index
= intSelected
.length
- 1; index
> -1; index
--) {
485 listItem
.removeElementAt(intSelected
[index
]);
488 jListLibraryClassDefinitions
.getSelectionModel().clearSelection();
491 if (arg0
.getSource() == jButtonClearAll
) {
492 listItem
.removeAllElements();
496 // Contorl the selected status when click RadionButton
497 // Do not use Radio Button Group
499 if (arg0
.getSource() == jRadioButtonAdd
) {
500 if (jRadioButtonAdd
.isSelected()) {
501 jRadioButtonSelect
.setSelected(false);
502 jTextFieldAdd
.setEnabled(true);
503 jComboBoxSelect
.setEnabled(false);
505 if (!jRadioButtonSelect
.isSelected() && !jRadioButtonAdd
.isSelected()) {
506 jRadioButtonAdd
.setSelected(true);
507 jTextFieldAdd
.setEnabled(true);
508 jComboBoxSelect
.setEnabled(false);
512 if (arg0
.getSource() == jRadioButtonSelect
) {
513 if (jRadioButtonSelect
.isSelected()) {
514 jRadioButtonAdd
.setSelected(false);
515 jTextFieldAdd
.setEnabled(false);
516 jComboBoxSelect
.setEnabled(true);
518 if (!jRadioButtonSelect
.isSelected() && !jRadioButtonAdd
.isSelected()) {
519 jRadioButtonSelect
.setSelected(true);
520 jTextFieldAdd
.setEnabled(false);
521 jComboBoxSelect
.setEnabled(true);
527 Data validation for all fields
529 @retval true - All datas are valid
530 @retval false - At least one data is invalid
533 public boolean check() {
534 if (listItem
.getSize() < 1) {
535 Log
.err("Must have one Library Class at least!");
542 Data validation for all fields
544 @retval true - All datas are valid
545 @retval false - At least one data is invalid
548 public boolean checkAdd() {
550 // Check if all required fields are not empty
552 if (this.jRadioButtonAdd
.isSelected() && isEmpty(this.jTextFieldAdd
.getText())) {
553 Log
.err("Library Class couldn't be empty");
558 // Check if all fields have correct data types
560 if (this.jRadioButtonAdd
.isSelected() && !DataValidation
.isLibraryClass(this.jTextFieldAdd
.getText())) {
561 Log
.err("Incorrect data type for Library Class");
568 Save all components of Mbd Header
569 if exists mbdHeader, set the value directly
570 if not exists mbdHeader, new an instance first
575 int intLibraryCount
= listItem
.getSize();
577 if (this.libraryClassDefinitions
== null) {
578 libraryClassDefinitions
= LibraryClassDefinitionsDocument
.LibraryClassDefinitions
.Factory
.newInstance();
581 if (intLibraryCount
> 0) {
582 LibraryClassDocument
.LibraryClass mLibraryClass
= LibraryClassDocument
.LibraryClass
.Factory
584 for (int index
= this.libraryClassDefinitions
.getLibraryClassList().size() - 1; index
> -1; index
--) {
585 this.libraryClassDefinitions
.removeLibraryClass(index
);
587 for (int index
= 0; index
< intLibraryCount
; index
++) {
588 String strAll
= listItem
.get(index
).toString();
589 String strUsage
= strAll
.substring(0, strAll
.indexOf(ModuleLibraryClassDefinitions
.Separator
));
590 String strLibraryClass
= strAll
.substring(strAll
.indexOf(ModuleLibraryClassDefinitions
.Separator
)
591 + ModuleLibraryClassDefinitions
.Separator
.length());
592 mLibraryClass
.setStringValue(strLibraryClass
);
593 mLibraryClass
.setUsage(LibraryUsage
.Enum
.forString(strUsage
));
594 this.libraryClassDefinitions
.addNewLibraryClass();
595 this.libraryClassDefinitions
.setLibraryClassArray(index
, mLibraryClass
);
598 this.libraryClassDefinitions
.setNil();
600 } catch (Exception e
) {
601 Log
.err("Update Library Class Definitions", e
.getMessage());
606 Get LibraryClassDefinitionsDocument.LibraryClassDefinitions
611 public LibraryClassDefinitionsDocument
.LibraryClassDefinitions
getLibraryClassDefinitions() {
612 return libraryClassDefinitions
;
616 Set LibraryClassDefinitionsDocument.LibraryClassDefinitions
618 @param libraryClassDefinitions The input data of LibraryClassDefinitionsDocument.LibraryClassDefinitions
621 public void setLibraryClassDefinitions(
622 LibraryClassDefinitionsDocument
.LibraryClassDefinitions libraryClassDefinitions
) {
623 this.libraryClassDefinitions
= libraryClassDefinitions
;