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