]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/packaging/module/ui/ModuleLibraryClassDefinitions.java
dfd6893f1849c8b51e2242854c69f6648dad91c3
[mirror_edk2.git] / Tools / Source / ModuleEditor / src / org / tianocore / packaging / module / ui / ModuleLibraryClassDefinitions.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.packaging.module.ui;
16
17 import java.awt.event.ActionEvent;
18
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;
28
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;
35
36 /**
37 The class is used to create, update Library Class Definition of MSA/MBD file
38 It extends IInternalFrame
39
40 @since ModuleEditor 1.0
41
42 **/
43 public class ModuleLibraryClassDefinitions extends IInternalFrame {
44
45 ///
46 /// Define class Serial Version UID
47 ///
48 private static final long serialVersionUID = -1743248695411382857L;
49
50 //
51 //Define class members
52 //
53 private static String Separator = "::";
54
55 private DefaultListModel listItem = new DefaultListModel();
56
57 private LibraryClassDefinitionsDocument.LibraryClassDefinitions libraryClassDefinitions = null;
58
59 private JPanel jContentPane = null;
60
61 private JRadioButton jRadioButtonAdd = null;
62
63 private JRadioButton jRadioButtonSelect = null;
64
65 private JTextField jTextFieldAdd = null;
66
67 private JComboBox jComboBoxSelect = null;
68
69 private JLabel jLabelUsage = null;
70
71 private JComboBox jComboBoxUsage = null;
72
73 private JScrollPane jScrollPane = null;
74
75 private JList jListLibraryClassDefinitions = null;
76
77 private JButton jButtonAdd = null;
78
79 private JButton jButtonRemove = null;
80
81 private JButton jButtonClearAll = null;
82
83 private JButton jButtonCancel = null;
84
85 private JButton jButtonOk = null;
86
87 /**
88 This method initializes jRadioButtonAdd
89
90 @return javax.swing.JRadioButton jRadioButtonAdd
91
92 **/
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);
100 }
101 return jRadioButtonAdd;
102 }
103
104 /**
105 This method initializes jRadioButtonSelect
106
107 @return javax.swing.JRadioButton jRadioButtonSelect
108
109 **/
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);
117 }
118 return jRadioButtonSelect;
119 }
120
121 /**
122 This method initializes jTextFieldAdd
123
124 @return javax.swing.JTextField jTextFieldAdd
125
126 **/
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);
132 }
133 return jTextFieldAdd;
134 }
135
136 /**
137 This method initializes jComboBoxSelect
138
139 @return javax.swing.JComboBox jComboBoxSelect
140
141 **/
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);
147 }
148 return jComboBoxSelect;
149 }
150
151 /**
152 This method initializes jComboBoxUsage
153
154 @return javax.swing.JComboBox jComboBoxUsage
155
156 **/
157 private JComboBox getJComboBoxUsage() {
158 if (jComboBoxUsage == null) {
159 jComboBoxUsage = new JComboBox();
160 jComboBoxUsage.setBounds(new java.awt.Rectangle(220, 60, 260, 20));
161 }
162 return jComboBoxUsage;
163 }
164
165 /**
166 This method initializes jScrollPane
167
168 @return javax.swing.JScrollPane jScrollPane
169
170 **/
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());
176 }
177 return jScrollPane;
178 }
179
180 /**
181 This method initializes jListLibraryClassDefinitions
182
183 @return javax.swing.JList jListLibraryClassDefinitions
184
185 **/
186 private JList getJListLibraryClassDefinitions() {
187 if (jListLibraryClassDefinitions == null) {
188 jListLibraryClassDefinitions = new JList(listItem);
189 }
190 return jListLibraryClassDefinitions;
191 }
192
193 /**
194 This method initializes jButtonAdd
195
196 @return javax.swing.JButton jButtonAdd
197
198 **/
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);
205 }
206 return jButtonAdd;
207 }
208
209 /**
210 This method initializes jButtonRemove
211
212 @return javax.swing.JButton jButtonRemove
213
214 **/
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);
221 }
222 return jButtonRemove;
223 }
224
225 /**
226 This method initializes jButtonRemoveAll
227
228 @return javax.swing.JButton jButtonClearAll
229
230 **/
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);
237 }
238 return jButtonClearAll;
239 }
240
241 /**
242 This method initializes jButtonCancel
243
244 @return javax.swing.JButton jButtonCancel
245
246 **/
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);
255 }
256 return jButtonCancel;
257 }
258
259 /**
260 This method initializes jButtonOk
261
262 @return javax.swing.JButton jButtonOk
263
264 **/
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);
272 }
273 return jButtonOk;
274 }
275
276 public static void main(String[] args) {
277
278 }
279
280 /**
281 This is the default constructor
282
283 **/
284 public ModuleLibraryClassDefinitions() {
285 super();
286 init();
287 this.setVisible(true);
288 }
289
290 /**
291 This is the override edit constructor
292
293 @param inLibraryClassDefinitions The input data of LibraryClassDefinitionsDocument.LibraryClassDefinitions
294
295 **/
296 public ModuleLibraryClassDefinitions(
297 LibraryClassDefinitionsDocument.LibraryClassDefinitions inLibraryClassDefinitions) {
298 super();
299 init(inLibraryClassDefinitions);
300 this.setVisible(true);
301 }
302
303 /**
304 This method initializes this
305 Fill values to all fields if these values are not empty
306
307 @param inLibraryClassDefinitions The input data of LibraryClassDefinitionsDocument.LibraryClassDefinitions
308
309 **/
310 private void init(LibraryClassDefinitionsDocument.LibraryClassDefinitions inLibraryClassDefinitions) {
311 init();
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();
320 }
321 }
322 }
323 }
324
325 /**
326 This method initializes this
327
328 **/
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();
334 initFrame();
335 this.setViewMode(false);
336 }
337
338 /**
339 Disable all components when the mode is view
340
341 @param isView true - The view mode; false - The non-view mode
342
343 **/
344 public void setViewMode(boolean isView) {
345 this.jButtonOk.setVisible(false);
346 this.jButtonCancel.setVisible(false);
347 if (isView) {
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);
358 }
359 }
360
361 /**
362 This method initializes jContentPane
363
364 @return javax.swing.JPanel jContentPane
365
366 **/
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);
386 }
387 return jContentPane;
388 }
389
390 /**
391 This method initializes all existing libraries and usage types
392
393 **/
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");
433
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");
440 }
441
442 /* (non-Javadoc)
443 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
444 *
445 * Override actionPerformed to listen all actions
446 *
447 */
448 public void actionPerformed(ActionEvent arg0) {
449 if (arg0.getSource() == jButtonOk) {
450 this.dispose();
451 this.setEdited(true);
452 this.save();
453 }
454 if (arg0.getSource() == jButtonCancel) {
455 this.dispose();
456 this.setEdited(false);
457 }
458
459 //
460 // Add current Library and its usage to the list
461 //
462 if (arg0.getSource() == jButtonAdd) {
463 if (!checkAdd()) {
464 return;
465 }
466 String strLibClass = "";
467 String strUsage = "";
468 if (jRadioButtonAdd.isSelected()) {
469 strLibClass = jTextFieldAdd.getText();
470 }
471 if (jRadioButtonSelect.isSelected()) {
472 strLibClass = jComboBoxSelect.getSelectedItem().toString();
473 }
474 strUsage = jComboBoxUsage.getSelectedItem().toString();
475 listItem.addElement(strUsage + ModuleLibraryClassDefinitions.Separator + strLibClass);
476 }
477
478 //
479 // Remove current Library and its usage of the list
480 //
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]);
486 }
487 }
488 jListLibraryClassDefinitions.getSelectionModel().clearSelection();
489 }
490
491 if (arg0.getSource() == jButtonClearAll) {
492 listItem.removeAllElements();
493 }
494
495 //
496 // Contorl the selected status when click RadionButton
497 // Do not use Radio Button Group
498 //
499 if (arg0.getSource() == jRadioButtonAdd) {
500 if (jRadioButtonAdd.isSelected()) {
501 jRadioButtonSelect.setSelected(false);
502 jTextFieldAdd.setEnabled(true);
503 jComboBoxSelect.setEnabled(false);
504 }
505 if (!jRadioButtonSelect.isSelected() && !jRadioButtonAdd.isSelected()) {
506 jRadioButtonAdd.setSelected(true);
507 jTextFieldAdd.setEnabled(true);
508 jComboBoxSelect.setEnabled(false);
509 }
510 }
511
512 if (arg0.getSource() == jRadioButtonSelect) {
513 if (jRadioButtonSelect.isSelected()) {
514 jRadioButtonAdd.setSelected(false);
515 jTextFieldAdd.setEnabled(false);
516 jComboBoxSelect.setEnabled(true);
517 }
518 if (!jRadioButtonSelect.isSelected() && !jRadioButtonAdd.isSelected()) {
519 jRadioButtonSelect.setSelected(true);
520 jTextFieldAdd.setEnabled(false);
521 jComboBoxSelect.setEnabled(true);
522 }
523 }
524 }
525
526 /**
527 Data validation for all fields
528
529 @retval true - All datas are valid
530 @retval false - At least one data is invalid
531
532 **/
533 public boolean check() {
534 if (listItem.getSize() < 1) {
535 Log.err("Must have one Library Class at least!");
536 return false;
537 }
538 return true;
539 }
540
541 /**
542 Data validation for all fields
543
544 @retval true - All datas are valid
545 @retval false - At least one data is invalid
546
547 **/
548 public boolean checkAdd() {
549 //
550 // Check if all required fields are not empty
551 //
552 if (this.jRadioButtonAdd.isSelected() && isEmpty(this.jTextFieldAdd.getText())) {
553 Log.err("Library Class couldn't be empty");
554 return false;
555 }
556
557 //
558 // Check if all fields have correct data types
559 //
560 if (this.jRadioButtonAdd.isSelected() && !DataValidation.isLibraryClass(this.jTextFieldAdd.getText())) {
561 Log.err("Incorrect data type for Library Class");
562 return false;
563 }
564 return true;
565 }
566
567 /**
568 Save all components of Mbd Header
569 if exists mbdHeader, set the value directly
570 if not exists mbdHeader, new an instance first
571
572 **/
573 public void save() {
574 try {
575 int intLibraryCount = listItem.getSize();
576
577 if (this.libraryClassDefinitions == null) {
578 libraryClassDefinitions = LibraryClassDefinitionsDocument.LibraryClassDefinitions.Factory.newInstance();
579 }
580
581 if (intLibraryCount > 0) {
582 LibraryClassDocument.LibraryClass mLibraryClass = LibraryClassDocument.LibraryClass.Factory
583 .newInstance();
584 for (int index = this.libraryClassDefinitions.getLibraryClassList().size() - 1; index > -1; index--) {
585 this.libraryClassDefinitions.removeLibraryClass(index);
586 }
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);
596 }
597 } else {
598 this.libraryClassDefinitions.setNil();
599 }
600 } catch (Exception e) {
601 Log.err("Update Library Class Definitions", e.getMessage());
602 }
603 }
604
605 /**
606 Get LibraryClassDefinitionsDocument.LibraryClassDefinitions
607
608 @return
609
610 **/
611 public LibraryClassDefinitionsDocument.LibraryClassDefinitions getLibraryClassDefinitions() {
612 return libraryClassDefinitions;
613 }
614
615 /**
616 Set LibraryClassDefinitionsDocument.LibraryClassDefinitions
617
618 @param libraryClassDefinitions The input data of LibraryClassDefinitionsDocument.LibraryClassDefinitions
619
620 **/
621 public void setLibraryClassDefinitions(
622 LibraryClassDefinitionsDocument.LibraryClassDefinitions libraryClassDefinitions) {
623 this.libraryClassDefinitions = libraryClassDefinitions;
624 }
625 }