]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/packaging/ui/SpdLibClassDecls.java
Make opening dialogs re-gain focus when user switch back to main UI from other window...
[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.FontMetrics;
17 import java.awt.event.ActionEvent;
18 import java.awt.event.ComponentEvent;
19 import java.io.File;
20 import java.util.HashMap;
21 //import java.util.Iterator;
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.JTextArea;
32 import javax.swing.JComboBox;
33 import javax.swing.JLabel;
34 import javax.swing.JScrollPane;
35 import javax.swing.JButton;
36 import javax.swing.JFrame;
37 import javax.swing.ListSelectionModel;
38 import javax.swing.event.InternalFrameAdapter;
39 import javax.swing.event.InternalFrameEvent;
40 import javax.swing.event.ListSelectionEvent;
41 import javax.swing.event.ListSelectionListener;
42 import javax.swing.event.TableModelEvent;
43 import javax.swing.event.TableModelListener;
44 import javax.swing.table.DefaultTableModel;
45 import javax.swing.table.TableColumn;
46 import javax.swing.table.TableModel;
47 import org.tianocore.PackageSurfaceAreaDocument;
48 import org.tianocore.frameworkwizard.common.DataType;
49 import org.tianocore.frameworkwizard.common.DataValidation;
50 //import org.tianocore.frameworkwizard.common.GlobalData;
51 import org.tianocore.frameworkwizard.common.Tools;
52 import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageType;
53 import org.tianocore.frameworkwizard.common.ui.IInternalFrame;
54 import org.tianocore.frameworkwizard.common.ui.StarLabel;
55 import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;
56 import org.tianocore.frameworkwizard.platform.ui.ListEditor;
57 import org.tianocore.frameworkwizard.platform.ui.LongTextEditor;
58 //import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;
59 //import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
60
61
62 /**
63 GUI for create library definition elements of spd file.
64
65 @since PackageEditor 1.0
66 **/
67 public class SpdLibClassDecls extends IInternalFrame implements TableModelListener{
68 /**
69 *
70 */
71 private static final long serialVersionUID = 1L;
72
73 private JFrame topFrame;
74
75 private JTable jTable = null;
76
77 private DefaultTableModel model = null;
78
79 private JPanel jContentPane = null;
80
81 private JTextField jTextFieldAddClass = null;
82
83 private JComboBox jComboBoxSelect = null;
84
85 private JScrollPane jScrollPaneTable = null;
86
87 private JButton jButtonAdd = null;
88
89 private JButton jButtonRemove = null;
90
91 private JButton jButtonRemoveAll = null;
92
93 private JLabel jLabelHdr = null;
94
95 private JTextField jTextFieldHdr = null;
96
97 private JButton jButtonBrowse = null;
98
99 private StarLabel starLabel1 = null;
100
101 private StarLabel starLabel3 = null;
102
103 private SpdFileContents sfc = null;
104
105 private OpeningPackageType docConsole = null;
106
107 private JLabel jLabel1ClassName = null;
108
109 private JScrollPane topScrollPane = null; // @jve:decl-index=0:visual-constraint="10,53"
110
111 private int selectedRow = -1;
112
113 private StarLabel starLabel2 = null;
114
115 private JLabel jLabel2HelpText = null;
116
117 private JTextArea jTextAreaHelp = null;
118
119 private JScrollPane jHelpTextScrollPane = null;
120
121 private JLabel jLabel5SupArchList = null;
122
123 private JLabel jLabel6SupModList = null;
124
125 private JScrollPane jScrollPaneModules = null;
126
127 private JScrollPane jScrollPane1Arch = null;
128
129 private ICheckBoxList iCheckBoxListModules = null;
130
131 private ICheckBoxList iCheckBoxListArch = null;
132
133 private int cnClassName = 0;
134 private int cnHdrFile = 1;
135 private int cnHelpText = 2;
136 // private int cnRecInstName = 3;
137 // private int cnRecInstVer = 4;
138 private int cnSupArch = 5;
139 private int cnSupMod = 6;
140
141 private final int classNameMinWidth = 200;
142 private final int hdrFileMinWidth = 300;
143 private final int helpTextMinWidth = 300;
144 private final int supArchMinWidth = 200;
145 private final int supModMinWidth = 200;
146
147 private final int shortLabel = 90;
148 private final int longLabel = 220;
149 private final int labelCol = 12;
150 private final int shortValueCol = labelCol + shortLabel + 6;
151 private final int longValueCol = labelCol + longLabel + 6;
152 private final int longValueWidth = 347;
153 private final int shortWidth = 140;
154 private final int medWidth = 240;
155
156 private final int buttonWidth = 99;
157
158 private final int addButtonCol = shortValueCol + 10;
159 private final int removeButtonCol = addButtonCol + buttonWidth + 10;
160 private final int removeAllButtonCol = removeButtonCol + buttonWidth + 10;
161
162 private final int rowOne = 12;
163 private final int rowTwo = rowOne + 25;
164 private final int rowThree = rowTwo + 60 + 25;
165 private final int rowFour = rowThree + 25;
166 private final int rowFive = rowFour + 40 + 25;
167 private final int rowSix = rowFive + 40 + 25;
168 private final int rowSeven = rowSix;
169 private final int rowEight = rowSeven + 30;
170
171 HashMap<String, String> libNameGuidMap = new HashMap<String, String>();
172
173
174 /**
175 This method initializes this
176
177 **/
178 private void initialize() {
179
180 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
181
182 }
183
184 /**
185 This method initializes jTextFieldAddClass
186
187 @return javax.swing.JTextField
188 **/
189 private JTextField getJTextFieldAddClass() {
190 if (jTextFieldAddClass == null) {
191 jTextFieldAddClass = new JTextField();
192 jTextFieldAddClass.setBounds(new java.awt.Rectangle(shortValueCol,rowOne,longValueWidth,20));
193 jTextFieldAddClass.setPreferredSize(new java.awt.Dimension(longValueWidth,20));
194 jTextFieldAddClass.setEnabled(true);
195 }
196 return jTextFieldAddClass;
197 }
198
199 /**
200 This method initializes jComboBoxSelect
201
202 @return javax.swing.JComboBox
203 **/
204 private JComboBox getJComboBoxSelect() {
205 if (jComboBoxSelect == null) {
206 jComboBoxSelect = new JComboBox();
207 jComboBoxSelect.setBounds(new java.awt.Rectangle(220, 10, 260, 20));
208 jComboBoxSelect.setPreferredSize(new java.awt.Dimension(260,22));
209 jComboBoxSelect.setEnabled(true);
210 jComboBoxSelect.setVisible(false);
211 }
212 return jComboBoxSelect;
213 }
214
215 /**
216 This method initializes jScrollPaneTable
217
218 @return javax.swing.JScrollPane
219
220 Used for the Table of Library Classes that are provided by this package
221
222 **/
223 private JScrollPane getJScrollPaneTable() {
224 if (jScrollPaneTable == null) {
225 jScrollPaneTable = new JScrollPane();
226 jScrollPaneTable.setBounds(new java.awt.Rectangle(labelCol,rowEight,400,253));
227 jScrollPaneTable.setViewportView(getJTable());
228 }
229 return jScrollPaneTable;
230 }
231
232 /**
233 This method initializes jTable
234
235 @return javax.swing.JTable
236 **/
237 private JTable getJTable() {
238 if (jTable == null) {
239 model = new DefaultTableModel();
240 jTable = new JTable(model);
241 jTable.setRowHeight(20);
242 jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
243 jTable.setColumnSelectionAllowed(false);
244 model.addColumn("Class Name");
245 model.addColumn("Header");
246 model.addColumn("Help Text");
247 model.addColumn("Recommended Instance");
248 model.addColumn("Version");
249 model.addColumn("Supported Architectures");
250 model.addColumn("Supported Module Types");
251
252 jTable.getColumnModel().getColumn(cnHelpText).setCellEditor(new LongTextEditor(topFrame));
253
254 jTable.removeColumn(jTable.getColumnModel().getColumn(3));
255 jTable.removeColumn(jTable.getColumnModel().getColumn(3));
256
257 Vector<String> vArch = new Vector<String>();
258 vArch.add("IA32");
259 vArch.add("X64");
260 vArch.add("IPF");
261 vArch.add("EBC");
262 vArch.add("ARM");
263 vArch.add("PPC");
264 jTable.getColumnModel().getColumn(cnSupArch - 2).setCellEditor(new ListEditor(vArch, topFrame));
265
266 Vector<String> vModule = new Vector<String>();
267 vModule.add("BASE");
268 vModule.add("SEC");
269 vModule.add("PEI_CORE");
270 vModule.add("PEIM");
271 vModule.add("DXE_CORE");
272 vModule.add("DXE_DRIVER");
273 vModule.add("DXE_RUNTIME_DRIVER");
274 vModule.add("DXE_SAL_DRIVER");
275 vModule.add("DXE_SMM_DRIVER");
276 vModule.add("UEFI_DRIVER");
277 vModule.add("UEFI_APPLICATION");
278 vModule.add("USER_DEFINED");
279
280 jTable.getColumnModel().getColumn(cnSupMod - 2).setCellEditor(new ListEditor(vModule, topFrame));
281
282 TableColumn column = jTable.getColumnModel().getColumn(this.cnClassName);
283 column.setMinWidth(this.classNameMinWidth);
284 column = jTable.getColumnModel().getColumn(this.cnHdrFile);
285 column.setMinWidth(this.hdrFileMinWidth);
286 column = jTable.getColumnModel().getColumn(this.cnHelpText);
287 column.setMinWidth(this.helpTextMinWidth);
288 column = jTable.getColumnModel().getColumn(this.cnSupArch - 2);
289 column.setMinWidth(this.supArchMinWidth);
290 column = jTable.getColumnModel().getColumn(this.cnSupMod - 2);
291 column.setMinWidth(this.supModMinWidth);
292
293 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
294 jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
295 public void valueChanged(ListSelectionEvent e) {
296 if (e.getValueIsAdjusting()){
297 return;
298 }
299 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
300 if (lsm.isSelectionEmpty()) {
301 return;
302 }
303 else{
304 selectedRow = lsm.getMinSelectionIndex();
305 }
306 }
307 });
308
309 jTable.getModel().addTableModelListener(this);
310
311 }
312 return jTable;
313 }
314
315
316 public void tableChanged(TableModelEvent arg0) {
317 // TODO Auto-generated method stub
318 int row = arg0.getFirstRow();
319 int column = arg0.getColumn();
320 TableModel m = (TableModel)arg0.getSource();
321 if (arg0.getType() == TableModelEvent.UPDATE){
322
323 String lib = m.getValueAt(row, cnClassName) + "";
324 String hdr = m.getValueAt(row, cnHdrFile) + "";
325 String hlp = m.getValueAt(row, cnHelpText) + "";
326 String name = null;
327 // if (m.getValueAt(row, cnRecInstName) != null) {
328 // name = m.getValueAt(row, cnRecInstName).toString();
329 // }
330 // String ver = null;
331 // if (m.getValueAt(row, cnRecInstVer) != null){
332 // ver = m.getValueAt(row, cnRecInstVer).toString();
333 // }
334 String arch = null;
335 if (m.getValueAt(row, cnSupArch) != null) {
336 arch = m.getValueAt(row, cnSupArch).toString();
337 }
338 String module = null;
339 if (m.getValueAt(row, cnSupMod) != null) {
340 module = m.getValueAt(row, cnSupMod).toString();
341 }
342 String[] rowData = {lib, hdr, hlp, name};
343 if (!dataValidation(rowData)) {
344 return;
345 }
346
347 String guid = null;
348 // if (name != null && name.length() > 0) {
349 // getLibInstances(lib);
350 // guid = nameToGuid(name);
351 // if (guid == null){
352 // JOptionPane.showMessageDialog(frame, "Recommended Instance does not exist.");
353 // return;
354 // }
355 // }
356
357 String[] sa = new String[7];
358 sfc.getSpdLibClassDeclaration(sa, row);
359 Object cellData = m.getValueAt(row, column);
360 if (cellData == null) {
361 cellData = "";
362 }
363 // if (column == cnRecInstName) {
364 // if (guid == null) {
365 // if (sa[cnRecInstName] == null) {
366 // return;
367 // }
368 // }
369 // else {
370 // if (guid.equals(sa[cnRecInstName])) {
371 // return;
372 // }
373 // }
374 // }
375 if (cellData.equals(sa[column])) {
376 return;
377 }
378 if (cellData.toString().length() == 0 && sa[column] == null) {
379 return;
380 }
381 docConsole.setSaved(false);
382 sfc.updateSpdLibClass(row, lib, hdr, hlp, guid, null, arch, module);
383 }
384 }
385
386 /**
387 This method initializes jButtonAdd
388
389 @return javax.swing.JButton
390 **/
391 private JButton getJButtonAdd() {
392 if (jButtonAdd == null) {
393 jButtonAdd = new JButton();
394 jButtonAdd.setText("Add");
395 jButtonAdd.setSize(new java.awt.Dimension(buttonWidth,20));
396 jButtonAdd.setBounds(new java.awt.Rectangle(addButtonCol,rowSeven,buttonWidth,20));
397 jButtonAdd.addActionListener(this);
398 }
399 return jButtonAdd;
400 }
401
402 /**
403 This method initializes jButtonRemove
404
405 @return javax.swing.JButton
406 **/
407 private JButton getJButtonRemove() {
408 if (jButtonRemove == null) {
409 jButtonRemove = new JButton();
410 jButtonRemove.setText("Delete");
411 jButtonRemove.setSize(new java.awt.Dimension(buttonWidth,20));
412 jButtonRemove.setBounds(new java.awt.Rectangle(removeButtonCol,rowSeven,buttonWidth,20));
413 jButtonRemove.addActionListener(this);
414 }
415 return jButtonRemove;
416 }
417
418 /**
419 This method initializes jButtonRemoveAll
420
421 @return javax.swing.JButton
422 **/
423 private JButton getJButtonRemoveAll() {
424 if (jButtonRemoveAll == null) {
425 jButtonRemoveAll = new JButton();
426 jButtonRemoveAll.setText("Clear All");
427 jButtonRemoveAll.setLocation(removeAllButtonCol,rowSeven);
428 FontMetrics fm = jButtonRemoveAll.getFontMetrics(jButtonRemoveAll.getFont());
429 jButtonRemoveAll.setSize(fm.stringWidth(jButtonRemoveAll.getText()) + 50, 20);
430 jButtonRemoveAll.addActionListener(this);
431 }
432 return jButtonRemoveAll;
433 }
434
435 /**
436 This is the default constructor
437 **/
438 public SpdLibClassDecls(JFrame frame) {
439 super();
440 topFrame = frame;
441 initialize();
442 init();
443
444 }
445
446 public SpdLibClassDecls(PackageSurfaceAreaDocument.PackageSurfaceArea inPsa, JFrame frame){
447 this(frame);
448 sfc = new SpdFileContents(inPsa);
449 init(sfc);
450 }
451
452 public SpdLibClassDecls(OpeningPackageType opt, JFrame frame) {
453 this(opt.getXmlSpd(), frame);
454 docConsole = opt;
455 }
456 /**
457 This method initializes this
458
459 @return void
460 **/
461 private void init() {
462
463 this.setContentPane(getJContentPane());
464 this.setTitle("Library Class Declarations");
465 this.setBounds(new java.awt.Rectangle(0, 0, 500, 370));
466 this.setVisible(true);
467 this.addInternalFrameListener(new InternalFrameAdapter(){
468 public void internalFrameDeactivated(InternalFrameEvent e){
469 if (jTable.isEditing()) {
470 jTable.getCellEditor().stopCellEditing();
471 }
472 }
473 });
474 }
475
476 private void init(SpdFileContents sfc) {
477
478 if (sfc.getSpdPkgDefsRdOnly().equals("true")) {
479 JOptionPane.showMessageDialog(topFrame, "This is a read-only package. You will not be able to edit contents in table.");
480 }
481 initFrame();
482
483 if (sfc.getSpdLibClassDeclarationCount() == 0) {
484 return ;
485 }
486 //
487 // initialize table using SpdFileContents object
488 //
489 String[][] saa = new String[sfc.getSpdLibClassDeclarationCount()][7];
490 sfc.getSpdLibClassDeclarations(saa);
491 int i = 0;
492 while (i < saa.length) {
493 // if (saa[i][3] != null && saa[i][3].length() > 0) {
494 // getLibInstances(saa[i][0]);
495 // saa[i][3] = guidToName(saa[i][3]);
496 // }
497
498 model.addRow(saa[i]);
499 i++;
500 }
501
502 }
503
504 private void initFrame() {
505 boolean editable = true;
506 if (sfc.getSpdPkgDefsRdOnly().equals("true")) {
507 editable = false;
508 }
509
510 jButtonAdd.setEnabled(editable);
511 jButtonRemove.setEnabled(editable);
512 jButtonRemoveAll.setEnabled(editable);
513 jTable.setEnabled(editable);
514 }
515
516 private JScrollPane getJContentPane(){
517 if (topScrollPane == null){
518 topScrollPane = new JScrollPane();
519 topScrollPane.setViewportView(getJContentPane1());
520 }
521 return topScrollPane;
522 }
523 /**
524 This method initializes jContentPane
525
526 @return javax.swing.JPanel
527 **/
528 private JPanel getJContentPane1() {
529 if (jContentPane == null) {
530 // Library Class
531 starLabel1 = new StarLabel();
532 starLabel1.setLocation(new java.awt.Point(1,rowOne));
533 jLabel1ClassName = new JLabel();
534 jLabel1ClassName.setBounds(new java.awt.Rectangle(labelCol,rowOne,shortLabel,20));
535 jLabel1ClassName.setText("Library Class");
536
537 // Help Text
538 starLabel2 = new StarLabel();
539 starLabel2.setBounds(new java.awt.Rectangle(1,rowTwo,10,20));
540 jLabel2HelpText = new JLabel();
541 jLabel2HelpText.setBounds(new java.awt.Rectangle(labelCol,rowTwo,shortLabel,20));
542 jLabel2HelpText.setText("Help Text");
543
544 // Header File
545 starLabel3 = new StarLabel();
546 starLabel3.setLocation(new java.awt.Point(1,rowThree));
547 jLabelHdr = new JLabel();
548 jLabelHdr.setBounds(new java.awt.Rectangle(labelCol,rowThree,longLabel,20));
549 jLabelHdr.setText("Include Header for Specified Class");
550
551 jLabel6SupModList = new JLabel();
552 jLabel6SupModList.setBounds(new java.awt.Rectangle(labelCol,rowFive,longLabel,20));
553 jLabel6SupModList.setText("Supported Module Types");
554 jLabel6SupModList.setEnabled(true);
555
556 jLabel5SupArchList = new JLabel();
557 jLabel5SupArchList.setBounds(new java.awt.Rectangle(labelCol,rowFour,longLabel,20));
558 jLabel5SupArchList.setText("Supported Architectures");
559 jLabel5SupArchList.setEnabled(true);
560
561 jContentPane = new JPanel();
562 jContentPane.setPreferredSize(new Dimension(680, 600));
563 jContentPane.setLayout(null);
564 jContentPane.add(jLabelHdr, null);
565 jContentPane.add(starLabel1, null);
566 jContentPane.add(starLabel3, null);
567 jContentPane.add(getJTextFieldAddClass(), null);
568 jContentPane.add(getJComboBoxSelect(), null);
569 jContentPane.add(getJScrollPaneTable(), null);
570 jContentPane.add(getJButtonAdd(), null);
571 jContentPane.add(getJButtonRemove(), null);
572 jContentPane.add(getJButtonRemoveAll(), null);
573
574 jContentPane.add(getJTextFieldHdr(), null);
575 jContentPane.add(getJButtonBrowse(), null);
576 jContentPane.add(jLabel1ClassName, null);
577 jContentPane.add(starLabel2, null);
578 jContentPane.add(jLabel2HelpText, null);
579 jContentPane.add(getJHelpTextScrollPane(), null);
580
581 jContentPane.add(jLabel5SupArchList, null);
582 jContentPane.add(jLabel6SupModList, null);
583
584 jContentPane.add(getJScrollPaneModules(), null);
585 jContentPane.add(getJScrollPane1Arch(), null);
586
587 }
588
589 return jContentPane;
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] = jTextFieldAddClass.getText();
604 row[cnHdrFile] = jTextFieldHdr.getText().replace('\\', '/');
605 row[cnHelpText] = jTextAreaHelp.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], null, row[cnHdrFile], row[cnHelpText], row[cnSupArch], null, null, null, 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(this, "Library Class name entered does not match KeyWord datatype.");
667 return false;
668 }
669 if (!DataValidation.isPathAndFilename(row[cnHdrFile])) {
670 JOptionPane.showMessageDialog(this, "Include Header does not match the PathAndFilename datatype.");
671 return false;
672 }
673 if (row[cnHelpText].length() == 0) {
674 JOptionPane.showMessageDialog(this, "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.setPreferredSize(new java.awt.Dimension(shortWidth,20));
706 jTextFieldHdr.setLocation(new java.awt.Point(longValueCol,rowThree));
707 jTextFieldHdr.setSize(new java.awt.Dimension(shortWidth,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(longValueCol + shortWidth + 7,rowThree,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(topFrame);
742 if (retval == JFileChooser.APPROVE_OPTION) {
743
744 theFile = chooser.getSelectedFile();
745 String file = theFile.getPath();
746 if (!file.startsWith(dirPrefix)) {
747 JOptionPane.showMessageDialog(topFrame, "You can only select files in current package directory structure!");
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 Tools.resizeComponentWidth(this.jTextFieldAddClass, this.getWidth(), intPreferredWidth-28);
772 Tools.resizeComponentWidth(this.jHelpTextScrollPane, this.getWidth(), intPreferredWidth-28);
773 Tools.resizeComponentWidth(this.jScrollPaneTable, this.getWidth(), intPreferredWidth-10);
774 Tools.resizeComponentWidth(this.jTextFieldHdr, this.getWidth(), intPreferredWidth - 7);
775 Tools.relocateComponentX(this.jButtonBrowse, this.getWidth(), intPreferredWidth,
776 DataType.SPACE_TO_RIGHT_FOR_GENERATE_BUTTON);
777 }
778
779 /**
780 * This method initializes jHelpTextScrollPane
781 *
782 * @return javax.swing.JScrollPane jHelpTextScrollPane
783 */
784 private JScrollPane getJHelpTextScrollPane() {
785 if (jHelpTextScrollPane == null) {
786 jHelpTextScrollPane = new JScrollPane();
787 jHelpTextScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
788 jHelpTextScrollPane.setPreferredSize(new java.awt.Dimension(longValueWidth, 80));
789 jHelpTextScrollPane.setSize(new java.awt.Dimension(longValueWidth, 80));
790 jHelpTextScrollPane.setLocation(new java.awt.Point(shortValueCol,rowTwo));
791 jHelpTextScrollPane.setViewportView(getJTextAreaHelp());
792 }
793 return jHelpTextScrollPane;
794 }
795
796 /**
797 * This method initializes jTextAreaHelp
798 *
799 * @return javax.swing.JTextArea
800 */
801 private JTextArea getJTextAreaHelp() {
802 if (jTextAreaHelp == null) {
803 jTextAreaHelp = new JTextArea();
804 jTextAreaHelp.setLineWrap(true);
805 jTextAreaHelp.setWrapStyleWord(true);
806 }
807 return jTextAreaHelp;
808 }
809
810 private JScrollPane getJScrollPaneModules() {
811 if (jScrollPaneModules == null) {
812 jScrollPaneModules = new JScrollPane();
813 jScrollPaneModules.setBounds(new java.awt.Rectangle(longValueCol,rowFive,medWidth,60));
814 jScrollPaneModules.setPreferredSize(new java.awt.Dimension(medWidth, 60));
815 jScrollPaneModules.setViewportView(getICheckBoxListSupportedModules());
816 }
817 return jScrollPaneModules;
818 }
819
820 private ICheckBoxList getICheckBoxListSupportedModules() {
821 if (iCheckBoxListModules == null) {
822 iCheckBoxListModules = new ICheckBoxList();
823 iCheckBoxListModules.setBounds(new java.awt.Rectangle(longValueCol,rowFour,medWidth,60));
824 Vector<String> v = new Vector<String>();
825 v.add("BASE");
826 v.add("SEC");
827 v.add("PEI_CORE");
828 v.add("PEIM");
829 v.add("DXE_CORE");
830 v.add("DXE_DRIVER");
831 v.add("DXE_RUNTIME_DRIVER");
832 v.add("DXE_SAL_DRIVER");
833 v.add("DXE_SMM_DRIVER");
834 v.add("UEFI_DRIVER");
835 v.add("UEFI_APPLICATION");
836 v.add("USER_DEFINED");
837 iCheckBoxListModules.setAllItems(v);
838 }
839 return iCheckBoxListModules;
840 }
841
842 private String vectorToString(Vector<String> v) {
843 String s = " ";
844 for (int i = 0; i < v.size(); ++i) {
845 s += v.get(i);
846 s += " ";
847 }
848 return s.trim();
849 }
850
851 private JScrollPane getJScrollPane1Arch() {
852 if (jScrollPane1Arch == null) {
853 jScrollPane1Arch = new JScrollPane();
854 jScrollPane1Arch.setBounds(new java.awt.Rectangle(longValueCol,rowFour,medWidth,60));
855 jScrollPane1Arch.setPreferredSize(new java.awt.Dimension(medWidth, 60));
856 jScrollPane1Arch.setViewportView(getICheckBoxListArch());
857 }
858 return jScrollPane1Arch;
859 }
860 /**
861 * This method initializes iCheckBoxList
862 *
863 * @return org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList
864 */
865 private ICheckBoxList getICheckBoxListArch() {
866 if (iCheckBoxListArch == null) {
867 iCheckBoxListArch = new ICheckBoxList();
868 iCheckBoxListArch.setBounds(new java.awt.Rectangle(longValueCol,rowFour,medWidth,60));
869 Vector<String> v = new Vector<String>();
870 v.add("IA32");
871 v.add("X64");
872 v.add("IPF");
873 v.add("EBC");
874 v.add("ARM");
875 v.add("PPC");
876 iCheckBoxListArch.setAllItems(v);
877 }
878 return iCheckBoxListArch;
879 }
880
881 // private void getLibInstances(String libClass){
882 // libNameGuidMap.clear();
883 // try {
884 // Iterator ismi = GlobalData.vModuleList.iterator();
885 // while (ismi.hasNext()) {
886 // ModuleIdentification mi = (ModuleIdentification) ismi.next();
887 //
888 // Vector<String> classProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED", mi);
889 // for (int i = 0; i < classProduced.size(); ++i) {
890 // if (classProduced.get(i).equals(libClass)) {
891 // libNameGuidMap.put(mi.getName(), mi.getGuid());
892 // }
893 // }
894 // }
895 //
896 // }
897 // catch(Exception e){
898 // JOptionPane.showMessageDialog(frame, "Search Instances Failed.");
899 // }
900 //
901 // }
902
903 // private String nameToGuid(String name) {
904 // String s = null;
905 // if (!libNameGuidMap.containsKey(name)) {
906 // return s;
907 // }
908 //
909 // s = libNameGuidMap.get(name);
910 // return s;
911 // }
912
913 // private String guidToName(String guid){
914 // String s = "";
915 // if (!libNameGuidMap.containsValue(guid)) {
916 // return s;
917 // }
918 // Set<String> key = libNameGuidMap.keySet();
919 // Iterator<String> is = key.iterator();
920 // while(is.hasNext()) {
921 // s = is.next();
922 // if (libNameGuidMap.get(s).equals(guid)) {
923 // break;
924 // }
925 // }
926 // return s;
927 // }
928
929 }
930
931