]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/packaging/ui/SpdLibClassDecls.java
Fix tracker "Package Library Class Recommended Instance should not default to null":
[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("Recommended Instance");
226 model.addColumn("Version");
227 model.addColumn("Sup. Arch");
228 model.addColumn("Mod. Types");
229
230 Vector<String> vArch = new Vector<String>();
231 vArch.add("IA32");
232 vArch.add("X64");
233 vArch.add("IPF");
234 vArch.add("EBC");
235 vArch.add("ARM");
236 vArch.add("PPC");
237 jTable.getColumnModel().getColumn(cnSupArch).setCellEditor(new ListEditor(vArch));
238
239 Vector<String> vModule = new Vector<String>();
240 vModule.add("BASE");
241 vModule.add("SEC");
242 vModule.add("PEI_CORE");
243 vModule.add("PEIM");
244 vModule.add("DXE_CORE");
245 vModule.add("DXE_DRIVER");
246 vModule.add("DXE_RUNTIME_DRIVER");
247 vModule.add("DXE_SAL_DRIVER");
248 vModule.add("DXE_SMM_DRIVER");
249 vModule.add("UEFI_DRIVER");
250 vModule.add("UEFI_APPLICATION");
251 vModule.add("USER_DEFINED");
252
253 jTable.getColumnModel().getColumn(cnSupMod).setCellEditor(new ListEditor(vModule));
254
255 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
256 jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
257 public void valueChanged(ListSelectionEvent e) {
258 if (e.getValueIsAdjusting()){
259 return;
260 }
261 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
262 if (lsm.isSelectionEmpty()) {
263 return;
264 }
265 else{
266 selectedRow = lsm.getMinSelectionIndex();
267 }
268 }
269 });
270
271 jTable.getModel().addTableModelListener(this);
272
273 }
274 return jTable;
275 }
276
277
278 public void tableChanged(TableModelEvent arg0) {
279 // TODO Auto-generated method stub
280 int row = arg0.getFirstRow();
281 TableModel m = (TableModel)arg0.getSource();
282 if (arg0.getType() == TableModelEvent.UPDATE){
283 String lib = m.getValueAt(row, cnClassName) + "";
284 String hdr = m.getValueAt(row, cnHdrFile) + "";
285 String hlp = m.getValueAt(row, cnHelpText) + "";
286 String name = m.getValueAt(row, cnRecInstName) + "";
287 String ver = m.getValueAt(row, cnRecInstVer) + "";
288 String arch = null;
289 if (m.getValueAt(row, cnSupArch) != null) {
290 arch = m.getValueAt(row, cnSupArch).toString();
291 }
292 String module = null;
293 if (m.getValueAt(row, cnSupMod) != null) {
294 module = m.getValueAt(row, cnSupMod).toString();
295 }
296 String[] rowData = {lib, hdr, hlp, name, ver};
297 if (!dataValidation(rowData)) {
298 return;
299 }
300 docConsole.setSaved(false);
301
302 getLibInstances(lib);
303 String guid = nameToGuid(name);
304
305 sfc.updateSpdLibClass(row, lib, hdr, hlp, guid, ver, arch, module);
306 }
307 }
308
309 /**
310 This method initializes jButtonAdd
311
312 @return javax.swing.JButton
313 **/
314 private JButton getJButtonAdd() {
315 if (jButtonAdd == null) {
316 jButtonAdd = new JButton();
317 jButtonAdd.setText("Add");
318 jButtonAdd.setSize(new java.awt.Dimension(99,20));
319 jButtonAdd.setLocation(new java.awt.Point(321,326));
320 jButtonAdd.addActionListener(this);
321 }
322 return jButtonAdd;
323 }
324
325 /**
326 This method initializes jButtonRemove
327
328 @return javax.swing.JButton
329 **/
330 private JButton getJButtonRemove() {
331 if (jButtonRemove == null) {
332 jButtonRemove = new JButton();
333 jButtonRemove.setText("Remove");
334 jButtonRemove.setSize(new java.awt.Dimension(99,20));
335 jButtonRemove.setLocation(new java.awt.Point(424,326));
336 jButtonRemove.addActionListener(this);
337 }
338 return jButtonRemove;
339 }
340
341 /**
342 This method initializes jButtonRemoveAll
343
344 @return javax.swing.JButton
345 **/
346 private JButton getJButtonRemoveAll() {
347 if (jButtonRemoveAll == null) {
348 jButtonRemoveAll = new JButton();
349 jButtonRemoveAll.setText("Remove All");
350 jButtonRemoveAll.setSize(new java.awt.Dimension(99,20));
351 jButtonRemoveAll.setLocation(new java.awt.Point(527,326));
352 jButtonRemoveAll.addActionListener(this);
353 }
354 return jButtonRemoveAll;
355 }
356
357 /**
358 This is the default constructor
359 **/
360 public SpdLibClassDecls() {
361 super();
362 initialize();
363 init();
364
365 }
366
367 public SpdLibClassDecls(PackageSurfaceAreaDocument.PackageSurfaceArea inPsa){
368 this();
369 sfc = new SpdFileContents(inPsa);
370 init(sfc);
371 }
372
373 public SpdLibClassDecls(OpeningPackageType opt) {
374 this(opt.getXmlSpd());
375 docConsole = opt;
376 }
377 /**
378 This method initializes this
379
380 @return void
381 **/
382 private void init() {
383
384 this.setContentPane(getJContentPane());
385 this.setTitle("Library Class Declarations");
386 this.setBounds(new java.awt.Rectangle(0, 0, 500, 370));
387 this.setVisible(true);
388 this.addInternalFrameListener(new InternalFrameAdapter(){
389 public void internalFrameDeactivated(InternalFrameEvent e){
390 if (jTable.isEditing()) {
391 jTable.getCellEditor().stopCellEditing();
392 }
393 }
394 });
395 initFrame();
396 }
397
398 private void init(SpdFileContents sfc) {
399 if (sfc.getSpdLibClassDeclarationCount() == 0) {
400 return ;
401 }
402 //
403 // initialize table using SpdFileContents object
404 //
405 String[][] saa = new String[sfc.getSpdLibClassDeclarationCount()][7];
406 sfc.getSpdLibClassDeclarations(saa);
407 int i = 0;
408 while (i < saa.length) {
409 if (saa[i][3] != null && saa[i][3].length() > 0) {
410 getLibInstances(saa[i][0]);
411 saa[i][3] = guidToName(saa[i][3]);
412 }
413
414 model.addRow(saa[i]);
415 i++;
416 }
417 }
418 private JScrollPane getJContentPane(){
419 if (topScrollPane == null){
420 topScrollPane = new JScrollPane();
421 topScrollPane.setSize(new java.awt.Dimension(634,590));
422 topScrollPane.setViewportView(getJContentPane1());
423 }
424 return topScrollPane;
425 }
426 /**
427 This method initializes jContentPane
428
429 @return javax.swing.JPanel
430 **/
431 private JPanel getJContentPane1() {
432 if (jContentPane == null) {
433 // Library Class
434 jStarLabel1 = new StarLabel();
435 jStarLabel1.setLocation(new java.awt.Point(1,7));
436 jLabel1ClassName = new JLabel();
437 jLabel1ClassName.setBounds(new java.awt.Rectangle(16,6,82,20));
438 jLabel1ClassName.setText("Library Class");
439
440 // Help Text
441 starLabel = new StarLabel();
442 starLabel.setBounds(new java.awt.Rectangle(1,33,10,20));
443 jLabel2HelpText = new JLabel();
444 jLabel2HelpText.setBounds(new java.awt.Rectangle(16,33,82,20));
445 jLabel2HelpText.setText("Help Text");
446
447 // Header File
448 jStarLabel2 = new StarLabel();
449 jStarLabel2.setLocation(new java.awt.Point(1,74));
450 jLabelHdr = new JLabel();
451 jLabelHdr.setBounds(new java.awt.Rectangle(14,74,199,22));
452 jLabelHdr.setText("Include Header for Specified Class");
453
454 jLabel6SupModList = new JLabel();
455 jLabel6SupModList.setBounds(new java.awt.Rectangle(16,252,108,16));
456 jLabel6SupModList.setText("Supported Module");
457 jLabel6SupModList.setEnabled(true);
458
459 jLabel5SupArchList = new JLabel();
460 jLabel5SupArchList.setBounds(new java.awt.Rectangle(15,169,93,16));
461 jLabel5SupArchList.setText("Supported Arch");
462 jLabel5SupArchList.setEnabled(true);
463 jLabel4RecInstVer = new JLabel();
464 jLabel4RecInstVer.setBounds(new java.awt.Rectangle(16,138,196,16));
465 jLabel4RecInstVer.setEnabled(true);
466 jLabel4RecInstVer.setText("Recommended Instance Version");
467 jLabel3RecInstName = new JLabel();
468 jLabel3RecInstName.setBounds(new java.awt.Rectangle(17,112,195,16));
469 jLabel3RecInstName.setEnabled(true);
470 jLabel3RecInstName.setText("Recommended Instance Name");
471
472 jContentPane = new JPanel();
473 jContentPane.setPreferredSize(new Dimension(480, 400));
474 jContentPane.setLayout(null);
475 jContentPane.add(jLabelHdr, null);
476 jContentPane.add(jStarLabel1, null);
477 jContentPane.add(jStarLabel2, null);
478 jContentPane.add(getJTextFieldAdd(), null);
479 jContentPane.add(getJComboBoxSelect(), null);
480 jContentPane.add(getJScrollPane(), null);
481 jContentPane.add(getJButtonAdd(), null);
482 jContentPane.add(getJButtonRemove(), null);
483 jContentPane.add(getJButtonRemoveAll(), null);
484
485 jContentPane.add(getJTextFieldHdr(), null);
486 jContentPane.add(getJButtonBrowse(), null);
487 jContentPane.add(jLabel1ClassName, null);
488 jContentPane.add(starLabel, null);
489 jContentPane.add(jLabel2HelpText, null);
490 jContentPane.add(getJTextFieldHelp(), null);
491
492 jContentPane.add(jLabel3RecInstName, null);
493 jContentPane.add(getJTextField1RecInstName(), null);
494 jContentPane.add(jLabel4RecInstVer, null);
495 jContentPane.add(getJTextField2RecInstVer(), null);
496 jContentPane.add(jLabel5SupArchList, null);
497 jContentPane.add(jLabel6SupModList, null);
498
499 jContentPane.add(getJScrollPaneModules(), null);
500 jContentPane.add(getJScrollPane1Arch(), null);
501 jContentPane.add(getJComboBox(), null);
502
503 }
504
505 return jContentPane;
506 }
507
508 /**
509 fill ComboBoxes with pre-defined contents
510 **/
511 private void initFrame() {
512 jComboBoxSelect.addItem("BaseCpuICacheFlush");
513 jComboBoxSelect.addItem("BaseDebugLibNull");
514 jComboBoxSelect.addItem("BaseDebugLibReportStatusCode");
515 jComboBoxSelect.addItem("BaseIoLibIntrinsic");
516 jComboBoxSelect.addItem("BaseLib");
517 jComboBoxSelect.addItem("BaseMemoryLib");
518 jComboBoxSelect.addItem("BaseMemoryLibMmx");
519 jComboBoxSelect.addItem("BaseMemoryLibSse2");
520 jComboBoxSelect.addItem("BasePeCoffGetEntryPointLib");
521 jComboBoxSelect.addItem("BasePeCoffLib");
522 jComboBoxSelect.addItem("BasePrintLib");
523 jComboBoxSelect.addItem("BaseReportStatusCodeLibNull");
524 jComboBoxSelect.addItem("CommonPciCf8Lib");
525 jComboBoxSelect.addItem("CommonPciExpressLib");
526 jComboBoxSelect.addItem("CommonPciLibCf8");
527 jComboBoxSelect.addItem("CommonPciLibPciExpress");
528 jComboBoxSelect.addItem("DxeCoreEntryPoint");
529 jComboBoxSelect.addItem("DxeHobLib");
530 jComboBoxSelect.addItem("DxeIoLibCpuIo");
531 jComboBoxSelect.addItem("DxeLib");
532 jComboBoxSelect.addItem("DxePcdLib");
533 jComboBoxSelect.addItem("DxeReportStatusCodeLib");
534 jComboBoxSelect.addItem("DxeServicesTableLib");
535 jComboBoxSelect.addItem("PeiCoreEntryPoint");
536 jComboBoxSelect.addItem("PeiMemoryLib");
537 jComboBoxSelect.addItem("PeimEntryPoint");
538 jComboBoxSelect.addItem("PeiReportStatusCodeLib");
539 jComboBoxSelect.addItem("PeiServicesTablePointerLib");
540 jComboBoxSelect.addItem("PeiServicesTablePointerLibMm7");
541 jComboBoxSelect.addItem("UefiDebugLibConOut");
542 jComboBoxSelect.addItem("UefiDebugLibStdErr");
543 jComboBoxSelect.addItem("UefiDriverEntryPointMultiple");
544 jComboBoxSelect.addItem("UefiDriverEntryPointSingle");
545 jComboBoxSelect.addItem("UefiDriverEntryPointSingleUnload");
546 jComboBoxSelect.addItem("UefiDriverModelLib");
547 jComboBoxSelect.addItem("UefiDriverModelLibNoConfigNoDiag");
548 jComboBoxSelect.addItem("UefiLib");
549 jComboBoxSelect.addItem("UefiMemoryLib");
550
551 }
552
553 /* (non-Javadoc)
554 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
555 */
556 public void actionPerformed(ActionEvent arg0) {
557
558 if (arg0.getSource() == jButtonAdd) {
559
560 //ToDo: check before add
561 // LAH WAS String[] row = {null, null, null, jComboBox.getSelectedItem()+"", jTextField2RecInstVer.getText(), null, null};
562 String[] row = {null, null, null, null, null, null, null};
563 row[cnClassName] = jTextFieldAdd.getText();
564 row[cnHdrFile] = jTextFieldHdr.getText().replace('\\', '/');
565 row[cnHelpText] = jTextFieldHelp.getText();
566 row[cnRecInstName] = jComboBox.getSelectedItem()+"";
567 row[cnRecInstVer] = jTextField2RecInstVer.getText();
568 row[cnSupArch] = vectorToString(iCheckBoxList.getAllCheckedItemsString());
569 if (row[cnSupArch].length() == 0) {
570 row[cnSupArch] = null;
571 }
572 row[cnSupMod] = vectorToString(iCheckBoxListModules.getAllCheckedItemsString());
573 if (row[cnSupMod].length() == 0){
574 row[cnSupMod] = null;
575 }
576 if (!dataValidation(row)) {
577 return;
578 }
579 model.addRow(row);
580 jTable.changeSelection(model.getRowCount()-1, 0, false, false);
581 docConsole.setSaved(false);
582 //
583 //convert to GUID before storing recommended lib instance.
584 //
585 getLibInstances(row[cnClassName]);
586 String recommendGuid = nameToGuid(row[cnRecInstName]);
587
588 sfc.genSpdLibClassDeclarations(row[cnClassName], recommendGuid, row[cnHdrFile], row[cnHelpText], row[cnSupArch], null, null, row[cnRecInstVer], null, row[cnSupMod]);
589
590 }
591 //
592 // remove selected line
593 //
594 if (arg0.getSource() == jButtonRemove) {
595 if (jTable.isEditing()){
596 jTable.getCellEditor().stopCellEditing();
597 }
598 int rowSelected = selectedRow;
599 if (rowSelected >= 0) {
600 model.removeRow(rowSelected);
601 docConsole.setSaved(false);
602 sfc.removeSpdLibClass(rowSelected);
603 }
604 }
605
606 if (arg0.getSource() == jButtonRemoveAll) {
607 if (model.getRowCount() == 0) {
608 return;
609 }
610 docConsole.setSaved(false);
611 model.setRowCount(0);
612 sfc.removeSpdLibClass();
613 }
614 }
615
616 private boolean dataValidation(String[] row) {
617 if (!DataValidation.isKeywordType(row[cnClassName])) {
618 JOptionPane.showMessageDialog(frame, "Library Class is NOT KeyWord Type.");
619 return false;
620 }
621 if (!DataValidation.isPathAndFilename(row[cnHdrFile])) {
622 JOptionPane.showMessageDialog(frame, "Include Header is NOT PathAndFilename Type.");
623 return false;
624 }
625 if (row[cnHelpText].length() == 0) {
626 JOptionPane.showMessageDialog(frame, "Help Text Must NOT be empty.");
627 return false;
628 }
629 if (row[cnRecInstVer].length() > 0) {
630 if (!DataValidation.isVersionDataType(row[cnRecInstVer])) {
631 JOptionPane.showMessageDialog(frame, "Recommended Instance Version is NOT VersionDataType.");
632 return false;
633 }
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 = null;
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