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