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