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