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