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