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