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