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