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