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