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