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