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