]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/packaging/ui/SpdLibClassDecls.java
4d35348dcf0e11da298c7687accf9a9b7238631f
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / packaging / ui / SpdLibClassDecls.java
1 /** @file
2 Java class SpdLibClassDecls is GUI for create library definition elements of spd file.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13 package org.tianocore.frameworkwizard.packaging.ui;
14
15 import java.awt.Dimension;
16 import java.awt.event.ActionEvent;
17 import java.awt.event.ComponentEvent;
18 import java.io.File;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.Map;
22 import java.util.Set;
23 import java.util.Vector;
24
25 import javax.swing.AbstractAction;
26 import javax.swing.JFileChooser;
27 import javax.swing.JOptionPane;
28 import javax.swing.JPanel;
29 import javax.swing.JTable;
30 import javax.swing.JTextField;
31 import javax.swing.JComboBox;
32 import javax.swing.JLabel;
33 import javax.swing.JScrollPane;
34 import javax.swing.JButton;
35 import javax.swing.JFrame;
36 import javax.swing.ListSelectionModel;
37 import javax.swing.event.InternalFrameAdapter;
38 import javax.swing.event.InternalFrameEvent;
39 import javax.swing.event.ListSelectionEvent;
40 import javax.swing.event.ListSelectionListener;
41 import javax.swing.event.TableModelEvent;
42 import javax.swing.event.TableModelListener;
43 import javax.swing.table.DefaultTableModel;
44 import javax.swing.table.TableModel;
45
46 import org.apache.xmlbeans.XmlObject;
47 import org.tianocore.PackageSurfaceAreaDocument;
48 import org.tianocore.frameworkwizard.common.DataValidation;
49 import org.tianocore.frameworkwizard.common.Tools;
50 import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageType;
51 import org.tianocore.frameworkwizard.common.ui.IInternalFrame;
52 import org.tianocore.frameworkwizard.common.ui.StarLabel;
53 import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;
54 import org.tianocore.frameworkwizard.platform.ui.ListEditor;
55 import org.tianocore.frameworkwizard.platform.ui.global.GlobalData;
56 import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;
57 import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;
58 import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;
59
60
61 /**
62 GUI for create library definition elements of spd file.
63
64 @since PackageEditor 1.0
65 **/
66 public class SpdLibClassDecls extends IInternalFrame implements TableModelListener{
67 /**
68 *
69 */
70 private static final long serialVersionUID = 1L;
71
72 static JFrame frame;
73
74 private JTable jTable = null;
75
76 private DefaultTableModel model = null;
77
78 private JPanel jContentPane = null;
79
80 private JTextField jTextFieldAdd = null;
81
82 private JComboBox jComboBoxSelect = null;
83
84 private JScrollPane jScrollPane = null;
85
86 private JButton jButtonAdd = null;
87
88 private JButton jButtonRemove = null;
89
90 private JButton jButtonRemoveAll = null;
91
92 private JLabel jLabelHdr = null;
93
94 private JTextField jTextFieldHdr = null;
95
96 private JButton jButtonBrowse = null;
97
98 private StarLabel jStarLabel1 = null;
99
100 private StarLabel jStarLabel2 = null;
101
102 private SpdFileContents sfc = null;
103
104 private OpeningPackageType docConsole = null;
105
106 private JLabel jLabel1ClassName = null;
107
108 private JScrollPane topScrollPane = null; // @jve:decl-index=0:visual-constraint="10,53"
109
110 private int selectedRow = -1;
111
112 private StarLabel starLabel = null;
113
114 private JLabel jLabel2HelpText = null;
115
116 private JTextField jTextFieldHelp = null;
117
118 private JLabel jLabel3RecInstName = null;
119
120 private JTextField jTextField1RecInstName = null;
121
122 private JLabel jLabel4RecInstVer = null;
123
124 private JTextField jTextField2RecInstVer = null;
125
126 private JLabel jLabel5SupArchList = null;
127
128 private JLabel jLabel6SupModList = null;
129
130 private JScrollPane jScrollPaneModules = null;
131
132 private JScrollPane jScrollPane1Arch = null;
133
134 private ICheckBoxList iCheckBoxListModules = null;
135
136 private ICheckBoxList iCheckBoxList = null;
137
138 private JComboBox jComboBox = null;
139
140 private int cnClassName = 0;
141 private int cnHdrFile = 1;
142 private int cnHelpText = 2;
143 private int cnRecInstName = 3;
144 private int cnRecInstVer = 4;
145 private int cnSupArch = 5;
146 private int cnSupMod = 6;
147
148 HashMap<String, String> libNameGuidMap = new HashMap<String, String>();
149
150
151 /**
152 This method initializes this
153
154 **/
155 private void initialize() {
156
157 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
158
159 }
160
161 /**
162 This method initializes jTextFieldAdd
163
164 @return javax.swing.JTextField
165 **/
166 private JTextField getJTextFieldAdd() {
167 if (jTextFieldAdd == null) {
168 jTextFieldAdd = new JTextField();
169 jTextFieldAdd.setBounds(new java.awt.Rectangle(122,6,390,20));
170 jTextFieldAdd.setPreferredSize(new java.awt.Dimension(260,20));
171 jTextFieldAdd.setEnabled(true);
172 }
173 return jTextFieldAdd;
174 }
175
176 /**
177 This method initializes jComboBoxSelect
178
179 @return javax.swing.JComboBox
180 **/
181 private JComboBox getJComboBoxSelect() {
182 if (jComboBoxSelect == null) {
183 jComboBoxSelect = new JComboBox();
184 jComboBoxSelect.setBounds(new java.awt.Rectangle(220, 10, 260, 20));
185 jComboBoxSelect.setPreferredSize(new java.awt.Dimension(260,22));
186 jComboBoxSelect.setEnabled(true);
187 jComboBoxSelect.setVisible(false);
188 }
189 return jComboBoxSelect;
190 }
191
192 /**
193 This method initializes jScrollPane
194
195 @return javax.swing.JScrollPane
196
197 Used for the Table of Library Classes that are provided by this package
198
199 **/
200 private JScrollPane getJScrollPane() {
201 if (jScrollPane == null) {
202 jScrollPane = new JScrollPane();
203 jScrollPane.setBounds(new java.awt.Rectangle(12,351,608,253));
204 jScrollPane.setPreferredSize(new java.awt.Dimension(390,150));
205 jScrollPane.setViewportView(getJTable());
206 }
207 return jScrollPane;
208 }
209
210 /**
211 This method initializes jTable
212
213 @return javax.swing.JTable
214 **/
215 private JTable getJTable() {
216 if (jTable == null) {
217 model = new DefaultTableModel();
218 jTable = new JTable(model);
219 jTable.setRowHeight(20);
220 // jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
221 jTable.setColumnSelectionAllowed(false);
222 model.addColumn("Class Name");
223 model.addColumn("Header");
224 model.addColumn("Help Text");
225 model.addColumn("Reserved");
226 model.addColumn("Reserved");
227 // model.addColumn("Recommended Instance");
228 // model.addColumn("Version");
229 model.addColumn("Sup. Arch");
230 model.addColumn("Mod. Types");
231
232 Vector<String> vArch = new Vector<String>();
233 vArch.add("IA32");
234 vArch.add("X64");
235 vArch.add("IPF");
236 vArch.add("EBC");
237 vArch.add("ARM");
238 vArch.add("PPC");
239 // jTable.getColumnModel().getColumn(cnSupArch).setCellEditor(new ListEditor(vArch));
240
241 Vector<String> vModule = new Vector<String>();
242 vModule.add("BASE");
243 vModule.add("SEC");
244 vModule.add("PEI_CORE");
245 vModule.add("PEIM");
246 vModule.add("DXE_CORE");
247 vModule.add("DXE_DRIVER");
248 vModule.add("DXE_RUNTIME_DRIVER");
249 vModule.add("DXE_SAL_DRIVER");
250 vModule.add("DXE_SMM_DRIVER");
251 vModule.add("UEFI_DRIVER");
252 vModule.add("UEFI_APPLICATION");
253 vModule.add("USER_DEFINED");
254 vModule.add("NONE");
255
256 jTable.getColumnModel().getColumn(cnSupMod).setCellEditor(new ListEditor(vModule));
257
258 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
259 jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
260 public void valueChanged(ListSelectionEvent e) {
261 if (e.getValueIsAdjusting()){
262 return;
263 }
264 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
265 if (lsm.isSelectionEmpty()) {
266 return;
267 }
268 else{
269 selectedRow = lsm.getMinSelectionIndex();
270 }
271 }
272 });
273
274 jTable.getModel().addTableModelListener(this);
275
276 }
277 return jTable;
278 }
279
280
281 public void tableChanged(TableModelEvent arg0) {
282 // TODO Auto-generated method stub
283 int row = arg0.getFirstRow();
284 TableModel m = (TableModel)arg0.getSource();
285 if (arg0.getType() == TableModelEvent.UPDATE){
286 String lib = m.getValueAt(row, cnClassName) + "";
287 String hdr = m.getValueAt(row, cnHdrFile) + "";
288 String hlp = m.getValueAt(row, cnHelpText) + "";
289 String name = m.getValueAt(row, cnRecInstName) + "";
290 String ver = m.getValueAt(row, cnRecInstVer) + "";
291 String arch = null;
292 if (m.getValueAt(row, cnSupArch) != null) {
293 arch = m.getValueAt(row, cnSupArch).toString();
294 }
295 String module = null;
296 // if (lsm.isSelectionEmpty()) {
297 if (m.getValueAt(row, cnSupMod) != null) {
298 module = m.getValueAt(row, cnSupMod).toString();
299 if (module == "NONE") {
300 module = null;
301 }
302 }
303 String[] rowData = {lib, hdr, hlp};
304 if (!dataValidation(rowData)) {
305 return;
306 }
307 docConsole.setSaved(false);
308
309 // LAH getLibInstances(lib);
310
311 // LAH String guid = nameToGuid(name);
312
313 // LAH WAS sfc.updateSpdLibClass(row, lib, hdr, hlp, guid, ver, arch, module);
314 sfc.updateSpdLibClass(row, lib, hdr, hlp, null, null, arch, module);
315 }
316 }
317
318 /**
319 This method initializes jButtonAdd
320
321 @return javax.swing.JButton
322 **/
323 private JButton getJButtonAdd() {
324 if (jButtonAdd == null) {
325 jButtonAdd = new JButton();
326 jButtonAdd.setText("Add");
327 jButtonAdd.setSize(new java.awt.Dimension(99,20));
328 jButtonAdd.setLocation(new java.awt.Point(321,326));
329 jButtonAdd.addActionListener(this);
330 }
331 return jButtonAdd;
332 }
333
334 /**
335 This method initializes jButtonRemove
336
337 @return javax.swing.JButton
338 **/
339 private JButton getJButtonRemove() {
340 if (jButtonRemove == null) {
341 jButtonRemove = new JButton();
342 jButtonRemove.setText("Remove");
343 jButtonRemove.setSize(new java.awt.Dimension(99,20));
344 jButtonRemove.setLocation(new java.awt.Point(424,326));
345 jButtonRemove.addActionListener(this);
346 }
347 return jButtonRemove;
348 }
349
350 /**
351 This method initializes jButtonRemoveAll
352
353 @return javax.swing.JButton
354 **/
355 private JButton getJButtonRemoveAll() {
356 if (jButtonRemoveAll == null) {
357 jButtonRemoveAll = new JButton();
358 jButtonRemoveAll.setText("Remove All");
359 jButtonRemoveAll.setSize(new java.awt.Dimension(99,20));
360 jButtonRemoveAll.setLocation(new java.awt.Point(527,326));
361 jButtonRemoveAll.addActionListener(this);
362 }
363 return jButtonRemoveAll;
364 }
365
366 /**
367 This is the default constructor
368 **/
369 public SpdLibClassDecls() {
370 super();
371 initialize();
372 init();
373
374 }
375
376 public SpdLibClassDecls(PackageSurfaceAreaDocument.PackageSurfaceArea inPsa){
377 this();
378 sfc = new SpdFileContents(inPsa);
379 init(sfc);
380 }
381
382 public SpdLibClassDecls(OpeningPackageType opt) {
383 this(opt.getXmlSpd());
384 docConsole = opt;
385 }
386 /**
387 This method initializes this
388
389 @return void
390 **/
391 private void init() {
392
393 this.setContentPane(getJContentPane());
394 this.setTitle("Library Class Declarations");
395 this.setBounds(new java.awt.Rectangle(0, 0, 500, 370));
396 this.setVisible(true);
397 this.addInternalFrameListener(new InternalFrameAdapter(){
398 public void internalFrameDeactivated(InternalFrameEvent e){
399 if (jTable.isEditing()) {
400 jTable.getCellEditor().stopCellEditing();
401 }
402 }
403 });
404 initFrame();
405 }
406
407 private void init(SpdFileContents sfc) {
408 if (sfc.getSpdLibClassDeclarationCount() == 0) {
409 return ;
410 }
411 //
412 // initialize table using SpdFileContents object
413 //
414 String[][] saa = new String[sfc.getSpdLibClassDeclarationCount()][7];
415 sfc.getSpdLibClassDeclarations(saa);
416 int i = 0;
417 while (i < saa.length) {
418 if (saa[i][3] != null && saa[i][3].length() > 0) {
419 getLibInstances(saa[i][0]);
420 saa[i][3] = guidToName(saa[i][3]);
421 }
422
423 model.addRow(saa[i]);
424 i++;
425 }
426 }
427 private JScrollPane getJContentPane(){
428 if (topScrollPane == null){
429 topScrollPane = new JScrollPane();
430 topScrollPane.setSize(new java.awt.Dimension(634,590));
431 topScrollPane.setViewportView(getJContentPane1());
432 }
433 return topScrollPane;
434 }
435 /**
436 This method initializes jContentPane
437
438 @return javax.swing.JPanel
439 **/
440 private JPanel getJContentPane1() {
441 if (jContentPane == null) {
442 // Library Class
443 jStarLabel1 = new StarLabel();
444 jStarLabel1.setLocation(new java.awt.Point(1,7));
445 jLabel1ClassName = new JLabel();
446 jLabel1ClassName.setBounds(new java.awt.Rectangle(16,6,82,20));
447 jLabel1ClassName.setText("Library Class");
448
449 // Help Text
450 starLabel = new StarLabel();
451 starLabel.setBounds(new java.awt.Rectangle(1,33,10,20));
452 jLabel2HelpText = new JLabel();
453 jLabel2HelpText.setBounds(new java.awt.Rectangle(16,33,82,20));
454 jLabel2HelpText.setText("Help Text");
455
456 // Header File
457 jStarLabel2 = new StarLabel();
458 jStarLabel2.setLocation(new java.awt.Point(1,74));
459 jLabelHdr = new JLabel();
460 jLabelHdr.setBounds(new java.awt.Rectangle(14,74,199,22));
461 jLabelHdr.setText("Include Header for Specified Class");
462
463 jLabel6SupModList = new JLabel();
464 jLabel6SupModList.setBounds(new java.awt.Rectangle(16,252,108,16));
465 jLabel6SupModList.setText("Supported Module");
466 jLabel6SupModList.setEnabled(true);
467
468 jLabel5SupArchList = new JLabel();
469 jLabel5SupArchList.setBounds(new java.awt.Rectangle(15,169,93,16));
470 jLabel5SupArchList.setText("Supported Arch");
471 jLabel5SupArchList.setEnabled(true);
472 jLabel4RecInstVer = new JLabel();
473 jLabel4RecInstVer.setBounds(new java.awt.Rectangle(16,138,196,16));
474 jLabel4RecInstVer.setEnabled(true);
475 jLabel4RecInstVer.setText("Recommended Instance Version");
476 jLabel3RecInstName = new JLabel();
477 jLabel3RecInstName.setBounds(new java.awt.Rectangle(17,112,195,16));
478 jLabel3RecInstName.setEnabled(true);
479 jLabel3RecInstName.setText("Recommended Instance Name");
480
481 jContentPane = new JPanel();
482 jContentPane.setPreferredSize(new Dimension(480, 400));
483 jContentPane.setLayout(null);
484 jContentPane.add(jLabelHdr, null);
485 jContentPane.add(jStarLabel1, null);
486 jContentPane.add(jStarLabel2, null);
487 jContentPane.add(getJTextFieldAdd(), null);
488 jContentPane.add(getJComboBoxSelect(), null);
489 jContentPane.add(getJScrollPane(), null);
490 jContentPane.add(getJButtonAdd(), null);
491 jContentPane.add(getJButtonRemove(), null);
492 jContentPane.add(getJButtonRemoveAll(), null);
493
494 jContentPane.add(getJTextFieldHdr(), null);
495 jContentPane.add(getJButtonBrowse(), null);
496 jContentPane.add(jLabel1ClassName, null);
497 jContentPane.add(starLabel, null);
498 jContentPane.add(jLabel2HelpText, null);
499 jContentPane.add(getJTextFieldHelp(), null);
500 // LAH Removed until we can fix permanently
501 // jContentPane.add(jLabel3RecInstName, null);
502 // jContentPane.add(getJTextField1RecInstName(), null);
503 // jContentPane.add(jLabel4RecInstVer, null);
504 // jContentPane.add(getJTextField2RecInstVer(), null);
505 jContentPane.add(jLabel5SupArchList, null);
506 jContentPane.add(jLabel6SupModList, null);
507
508 jContentPane.add(getJScrollPaneModules(), null);
509 jContentPane.add(getJScrollPane1Arch(), null);
510 // LAH jContentPane.add(getJComboBox(), null);
511
512 }
513
514 return jContentPane;
515 }
516
517 /**
518 fill ComboBoxes with pre-defined contents
519 **/
520 private void initFrame() {
521 jComboBoxSelect.addItem("BaseCpuICacheFlush");
522 jComboBoxSelect.addItem("BaseDebugLibNull");
523 jComboBoxSelect.addItem("BaseDebugLibReportStatusCode");
524 jComboBoxSelect.addItem("BaseIoLibIntrinsic");
525 jComboBoxSelect.addItem("BaseLib");
526 jComboBoxSelect.addItem("BaseMemoryLib");
527 jComboBoxSelect.addItem("BaseMemoryLibMmx");
528 jComboBoxSelect.addItem("BaseMemoryLibSse2");
529 jComboBoxSelect.addItem("BasePeCoffGetEntryPointLib");
530 jComboBoxSelect.addItem("BasePeCoffLib");
531 jComboBoxSelect.addItem("BasePrintLib");
532 jComboBoxSelect.addItem("BaseReportStatusCodeLibNull");
533 jComboBoxSelect.addItem("CommonPciCf8Lib");
534 jComboBoxSelect.addItem("CommonPciExpressLib");
535 jComboBoxSelect.addItem("CommonPciLibCf8");
536 jComboBoxSelect.addItem("CommonPciLibPciExpress");
537 jComboBoxSelect.addItem("DxeCoreEntryPoint");
538 jComboBoxSelect.addItem("DxeHobLib");
539 jComboBoxSelect.addItem("DxeIoLibCpuIo");
540 jComboBoxSelect.addItem("DxeLib");
541 jComboBoxSelect.addItem("DxePcdLib");
542 jComboBoxSelect.addItem("DxeReportStatusCodeLib");
543 jComboBoxSelect.addItem("DxeServicesTableLib");
544 jComboBoxSelect.addItem("PeiCoreEntryPoint");
545 jComboBoxSelect.addItem("PeiMemoryLib");
546 jComboBoxSelect.addItem("PeimEntryPoint");
547 jComboBoxSelect.addItem("PeiReportStatusCodeLib");
548 jComboBoxSelect.addItem("PeiServicesTablePointerLib");
549 jComboBoxSelect.addItem("PeiServicesTablePointerLibMm7");
550 jComboBoxSelect.addItem("UefiDebugLibConOut");
551 jComboBoxSelect.addItem("UefiDebugLibStdErr");
552 jComboBoxSelect.addItem("UefiDriverEntryPointMultiple");
553 jComboBoxSelect.addItem("UefiDriverEntryPointSingle");
554 jComboBoxSelect.addItem("UefiDriverEntryPointSingleUnload");
555 jComboBoxSelect.addItem("UefiDriverModelLib");
556 jComboBoxSelect.addItem("UefiDriverModelLibNoConfigNoDiag");
557 jComboBoxSelect.addItem("UefiLib");
558 jComboBoxSelect.addItem("UefiMemoryLib");
559
560 }
561
562 /* (non-Javadoc)
563 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
564 */
565 public void actionPerformed(ActionEvent arg0) {
566
567 if (arg0.getSource() == jButtonAdd) {
568
569 //ToDo: check before add
570 // LAH WAS String[] row = {null, null, null, jComboBox.getSelectedItem()+"", jTextField2RecInstVer.getText(), null, null};
571 String[] row = {null, null, null, null, null, null, null};
572 row[cnClassName] = jTextFieldAdd.getText();
573 row[cnHdrFile] = jTextFieldHdr.getText().replace('\\', '/');
574 row[cnHelpText] = jTextFieldHelp.getText();
575 row[cnSupArch] = vectorToString(iCheckBoxList.getAllCheckedItemsString());
576 if (row[cnSupArch].length() == 0) {
577 row[cnSupArch] = null;
578 }
579 row[cnSupMod] = vectorToString(iCheckBoxListModules.getAllCheckedItemsString());
580 if (row[cnSupMod].length() == 0){
581 row[cnSupMod] = null;
582 }
583 if (!dataValidation(row)) {
584 return;
585 }
586 model.addRow(row);
587 jTable.changeSelection(model.getRowCount()-1, 0, false, false);
588 docConsole.setSaved(false);
589 //
590 //convert to GUID before storing recommended lib instance.
591 //
592 getLibInstances(row[0]);
593
594 // LAH recommendGuid = nameToGuid(row[3]);
595
596 // LAH WAS sfc.genSpdLibClassDeclarations(row[0], recommendGuid, row[1], row[2], row[5], null, null, row[4], null, row[6]);
597 sfc.genSpdLibClassDeclarations(row[cnClassName], null, row[cnHdrFile], row[cnHelpText], row[cnSupArch], null, null, row[cnRecInstVer], null, row[cnSupMod]);
598
599 }
600 //
601 // remove selected line
602 //
603 if (arg0.getSource() == jButtonRemove) {
604 if (jTable.isEditing()){
605 jTable.getCellEditor().stopCellEditing();
606 }
607 int rowSelected = selectedRow;
608 if (rowSelected >= 0) {
609 model.removeRow(rowSelected);
610 sfc.removeSpdLibClass(rowSelected);
611 }
612 }
613
614 if (arg0.getSource() == jButtonRemoveAll) {
615 if (model.getRowCount() == 0) {
616 return;
617 }
618
619 model.setRowCount(0);
620 sfc.removeSpdLibClass();
621 }
622 }
623
624 private boolean dataValidation(String[] row) {
625 if (!DataValidation.isKeywordType(row[cnClassName])) {
626 JOptionPane.showMessageDialog(frame, "Library Class is NOT KeyWord Type.");
627 return false;
628 }
629 if (!DataValidation.isPathAndFilename(row[cnHdrFile])) {
630 JOptionPane.showMessageDialog(frame, "Include Header is NOT PathAndFilename Type.");
631 }
632 if (row[cnHelpText].length() == 0) {
633 JOptionPane.showMessageDialog(frame, "Help Text Must NOT be empty.");
634 }
635 return true;
636 }
637 /**
638 Add contents in list to sfc
639 **/
640 protected void save() {
641
642 }
643
644 /**
645 This method initializes jTextField
646
647 @return javax.swing.JTextField
648 **/
649 private JTextField getJTextFieldHdr() {
650 if (jTextFieldHdr == null) {
651 jTextFieldHdr = new JTextField();
652 jTextFieldHdr.setBounds(new java.awt.Rectangle(218,75,305,21));
653 jTextFieldHdr.setPreferredSize(new java.awt.Dimension(260,20));
654 }
655 return jTextFieldHdr;
656 }
657
658 /**
659 This method initializes jButtonBrowse
660
661 @return javax.swing.JButton
662 **/
663 private JButton getJButtonBrowse() {
664 if (jButtonBrowse == null) {
665 jButtonBrowse = new JButton();
666 jButtonBrowse.setBounds(new java.awt.Rectangle(527,75,90,20));
667 jButtonBrowse.setText("Browse");
668 jButtonBrowse.setPreferredSize(new java.awt.Dimension(99,20));
669 jButtonBrowse.addActionListener(new AbstractAction() {
670
671 /**
672 *
673 */
674 private static final long serialVersionUID = 1L;
675
676 public void actionPerformed(ActionEvent arg0) {
677 //
678 // Select files from current pkg
679 //
680 String dirPrefix = Tools.dirForNewSpd.substring(0, Tools.dirForNewSpd.lastIndexOf(File.separator));
681 JFileChooser chooser = new JFileChooser(dirPrefix);
682 File theFile = null;
683 String headerDest = null;
684
685 chooser.setMultiSelectionEnabled(false);
686 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
687 int retval = chooser.showOpenDialog(frame);
688 if (retval == JFileChooser.APPROVE_OPTION) {
689
690 theFile = chooser.getSelectedFile();
691 String file = theFile.getPath();
692 if (!file.startsWith(dirPrefix)) {
693 JOptionPane.showMessageDialog(frame, "You can only select files in current package!");
694 return;
695 }
696
697
698 }
699 else {
700 return;
701 }
702
703 headerDest = theFile.getPath();
704 int fileIndex = headerDest.indexOf(System.getProperty("file.separator"), dirPrefix.length());
705 jTextFieldHdr.setText(headerDest.substring(fileIndex + 1).replace('\\', '/'));
706
707 }
708
709 });
710 }
711 return jButtonBrowse;
712 }
713
714 public void componentResized(ComponentEvent arg0) {
715 int intPreferredWidth = 500;
716
717 resizeComponentWidth(this.jTextFieldAdd, this.getWidth(), intPreferredWidth);
718 resizeComponentWidth(this.jTextFieldHelp, this.getWidth(), intPreferredWidth);
719 resizeComponentWidth(this.jScrollPane, this.getWidth(), intPreferredWidth-10);
720
721 }
722 /**
723 * This method initializes jTextFieldHelp
724 *
725 * @return javax.swing.JTextField
726 */
727 private JTextField getJTextFieldHelp() {
728 if (jTextFieldHelp == null) {
729 jTextFieldHelp = new JTextField();
730 jTextFieldHelp.setBounds(new java.awt.Rectangle(122,33,390,20));
731 jTextFieldHelp.setPreferredSize(new java.awt.Dimension(260,20));
732 }
733 return jTextFieldHelp;
734 }
735
736 /**
737 * This method initializes jTextField1RecInstName
738 *
739 * @return javax.swing.JTextField
740 */
741 private JTextField getJTextField1RecInstName() {
742 if (jTextField1RecInstName == null) {
743 jTextField1RecInstName = new JTextField();
744 jTextField1RecInstName.setBounds(new java.awt.Rectangle(218,110,291,20));
745 jTextField1RecInstName.setEnabled(true);
746 jTextField1RecInstName.setVisible(false);
747 }
748 return jTextField1RecInstName;
749 }
750
751 /**
752 * This method initializes jTextField2RecInstVer
753 *
754 * @return javax.swing.JTextField
755 */
756 private JTextField getJTextField2RecInstVer() {
757 if (jTextField2RecInstVer == null) {
758 jTextField2RecInstVer = new JTextField();
759 jTextField2RecInstVer.setBounds(new java.awt.Rectangle(218,135,292,20));
760 jTextField2RecInstVer.setEnabled(true);
761 }
762 return jTextField2RecInstVer;
763 }
764
765 private JScrollPane getJScrollPaneModules() {
766 if (jScrollPaneModules == null) {
767 jScrollPaneModules = new JScrollPane();
768 jScrollPaneModules.setBounds(new java.awt.Rectangle(218,245,293,73));
769 jScrollPaneModules.setPreferredSize(new java.awt.Dimension(320, 80));
770 jScrollPaneModules.setViewportView(getICheckBoxListSupportedModules());
771 }
772 return jScrollPaneModules;
773 }
774
775 private ICheckBoxList getICheckBoxListSupportedModules() {
776 if (iCheckBoxListModules == null) {
777 iCheckBoxListModules = new ICheckBoxList();
778 iCheckBoxListModules.setBounds(new java.awt.Rectangle(218,246,292,73));
779 Vector<String> v = new Vector<String>();
780 v.add("BASE");
781 v.add("SEC");
782 v.add("PEI_CORE");
783 v.add("PEIM");
784 v.add("DXE_CORE");
785 v.add("DXE_DRIVER");
786 v.add("DXE_RUNTIME_DRIVER");
787 v.add("DXE_SAL_DRIVER");
788 v.add("DXE_SMM_DRIVER");
789 v.add("UEFI_DRIVER");
790 v.add("UEFI_APPLICATION");
791 v.add("USER_DEFINED");
792 iCheckBoxListModules.setAllItems(v);
793 }
794 return iCheckBoxListModules;
795 }
796
797 private String vectorToString(Vector<String> v) {
798 String s = " ";
799 for (int i = 0; i < v.size(); ++i) {
800 s += v.get(i);
801 s += " ";
802 }
803 return s.trim();
804 }
805
806 private JScrollPane getJScrollPane1Arch() {
807 if (jScrollPane1Arch == null) {
808 jScrollPane1Arch = new JScrollPane();
809 jScrollPane1Arch.setBounds(new java.awt.Rectangle(218,170,293,73));
810 jScrollPane1Arch.setPreferredSize(new java.awt.Dimension(320, 80));
811 jScrollPane1Arch.setViewportView(getICheckBoxList());
812 }
813 return jScrollPane1Arch;
814 }
815 /**
816 * This method initializes iCheckBoxList
817 *
818 * @return org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList
819 */
820 private ICheckBoxList getICheckBoxList() {
821 if (iCheckBoxList == null) {
822 iCheckBoxList = new ICheckBoxList();
823 iCheckBoxList.setBounds(new java.awt.Rectangle(218,171,292,66));
824 Vector<String> v = new Vector<String>();
825 v.add("IA32");
826 v.add("X64");
827 v.add("IPF");
828 v.add("EBC");
829 v.add("ARM");
830 v.add("PPC");
831 iCheckBoxList.setAllItems(v);
832 }
833 return iCheckBoxList;
834 }
835
836 /**
837 * This method initializes jComboBox
838 *
839 * @return javax.swing.JComboBox
840 */
841 private JComboBox getJComboBox() {
842 if (jComboBox == null) {
843 jComboBox = new JComboBox();
844 jComboBox.setPreferredSize(new java.awt.Dimension(31,20));
845 jComboBox.setSize(new java.awt.Dimension(290,20));
846 jComboBox.setLocation(new java.awt.Point(218,111));
847 jComboBox.addFocusListener(new java.awt.event.FocusAdapter() {
848 public void focusGained(java.awt.event.FocusEvent e) {
849 if (jTextFieldAdd.getText().length() == 0) {
850 return;
851 }
852 jComboBox.removeAllItems();
853 getLibInstances(jTextFieldAdd.getText());
854 Set<String> libNames = libNameGuidMap.keySet();
855 Iterator<String> si = libNames.iterator();
856 while(si.hasNext()) {
857 jComboBox.addItem(si.next());
858 }
859 }
860 });
861
862 }
863 return jComboBox;
864 }
865
866 private void getLibInstances(String libClass){
867 libNameGuidMap.clear();
868 try {
869 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db", System.getenv("WORKSPACE"));
870
871 Set<PackageIdentification> spi = GlobalData.getPackageList();
872 Iterator ispi = spi.iterator();
873
874 while (ispi.hasNext()) {
875 PackageIdentification pi = (PackageIdentification) ispi.next();
876
877 Set<ModuleIdentification> smi = GlobalData.getModules(pi);
878 Iterator ismi = smi.iterator();
879 while (ismi.hasNext()) {
880 ModuleIdentification mi = (ModuleIdentification) ismi.next();
881 Map<String, XmlObject> m = GlobalData.getNativeMsa(mi);
882 SurfaceAreaQuery.setDoc(m);
883 String[] classProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED");
884 for (int i = 0; i < classProduced.length; ++i) {
885 if (classProduced[i].equals(libClass)) {
886 libNameGuidMap.put(mi.getName(), mi.getGuid());
887 }
888 }
889 }
890 }
891 }
892 catch(Exception e){
893 JOptionPane.showMessageDialog(frame, "Search Instances Fail.");
894 }
895
896 }
897
898 private String nameToGuid(String name) {
899 String s = "";
900 if (!libNameGuidMap.containsKey(name)) {
901 return s;
902 }
903
904 s = libNameGuidMap.get(name);
905 return s;
906 }
907
908 private String guidToName(String guid){
909 String s = "";
910 if (!libNameGuidMap.containsValue(guid)) {
911 return s;
912 }
913 Set<String> key = libNameGuidMap.keySet();
914 Iterator<String> is = key.iterator();
915 while(is.hasNext()) {
916 s = is.next();
917 if (libNameGuidMap.get(s).equals(guid)) {
918 break;
919 }
920 }
921 return s;
922 }
923
924 }
925
926