Fixed Enumeration ModuleType was suppose to be TOOL, not TOOLS.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / packaging / ui / SpdPackageHeaders.java
CommitLineData
a13899c5 1/** @file\r
2 Java class SpdPackageHeaders 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
a13899c5 16import java.awt.event.ActionEvent;\r
a13899c5 17import java.awt.event.ComponentEvent;\r
18import java.io.File;\r
a13899c5 19\r
20import javax.swing.DefaultCellEditor;\r
a13899c5 21import javax.swing.JFileChooser;\r
22import javax.swing.JOptionPane;\r
23import javax.swing.JPanel;\r
24import javax.swing.JRadioButton;\r
25import javax.swing.JTable;\r
26import javax.swing.JTextField;\r
27import javax.swing.JComboBox;\r
28import javax.swing.JLabel;\r
a13899c5 29import javax.swing.JScrollPane;\r
30import javax.swing.JButton;\r
31import javax.swing.JFrame;\r
32import javax.swing.ListSelectionModel;\r
33import javax.swing.event.InternalFrameAdapter;\r
34import javax.swing.event.InternalFrameEvent;\r
35import javax.swing.event.ListSelectionEvent;\r
36import javax.swing.event.ListSelectionListener;\r
37import javax.swing.event.TableModelEvent;\r
38import javax.swing.event.TableModelListener;\r
39import javax.swing.table.DefaultTableModel;\r
40import javax.swing.table.TableColumn;\r
41import javax.swing.table.TableModel;\r
42\r
43import org.tianocore.PackageSurfaceAreaDocument;\r
ce73a791 44import org.tianocore.frameworkwizard.common.DataValidation;\r
a13899c5 45import org.tianocore.frameworkwizard.common.Tools;\r
d6d24759 46import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageType;\r
a13899c5 47import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r
48import org.tianocore.frameworkwizard.common.ui.StarLabel;\r
49\r
50/**\r
51 GUI for create library definition elements of spd file.\r
52 \r
53 @since PackageEditor 1.0\r
54**/\r
55public class SpdPackageHeaders extends IInternalFrame implements TableModelListener{\r
ce73a791 56 /**\r
57 * \r
58 */\r
59 private static final long serialVersionUID = 1L;\r
60\r
a13899c5 61 static JFrame frame;\r
62 \r
63 private SpdFileContents sfc = null;\r
d6d24759 64 \r
65 private OpeningPackageType docConsole = null;\r
a13899c5 66\r
67 private DefaultTableModel model = null;\r
68\r
69 private JPanel jContentPane = null;\r
70\r
a13899c5 71 private JRadioButton jRadioButtonSelect = null;\r
72\r
a13899c5 73 private JComboBox jComboBoxSelect = null;\r
74\r
75 private JButton jButtonAdd = null;\r
76\r
77 private JButton jButtonRemove = null;\r
78\r
79 private JButton jButtonClearAll = null;\r
80\r
81 private JButton jButtonCancel = null;\r
82\r
83 private JButton jButtonOk = null;\r
84\r
85 private JLabel jLabel = null;\r
86\r
87 private JTextField jTextField = null;\r
88\r
89 private JButton jButtonBrowse = null;\r
90 \r
91 private StarLabel jStarLabel1 = null;\r
92 \r
93 private StarLabel jStarLabel2 = null;\r
94\r
95 private JScrollPane jScrollPane = null;\r
96\r
97 private JScrollPane jScrollPane1 = null;\r
98\r
99 private int selectedRow = -1;\r
100\r
101 private JTable jTable = null;\r
102\r
103\r
104\r
105 /**\r
106 This method initializes this\r
107 \r
108 **/\r
109 private void initialize() {\r
110 \r
111 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);\r
112\r
113 }\r
114\r
a13899c5 115 /**\r
116 This method initializes jRadioButtonSelect \r
117 \r
118 @return javax.swing.JRadioButton \r
119 **/\r
120 private JRadioButton getJRadioButtonSelect() {\r
121 if (jRadioButtonSelect == null) {\r
122 jRadioButtonSelect = new JRadioButton();\r
123 jRadioButtonSelect.setBounds(new java.awt.Rectangle(9,10,198,20));\r
124 jRadioButtonSelect.setText("Select Existing ModuleType");\r
125 jRadioButtonSelect.addActionListener(this);\r
126 jRadioButtonSelect.setSelected(true);\r
127 }\r
128 return jRadioButtonSelect;\r
129 }\r
130\r
a13899c5 131 /**\r
132 This method initializes jComboBoxSelect \r
133 \r
134 @return javax.swing.JComboBox \r
135 **/\r
136 private JComboBox getJComboBoxSelect() {\r
137 if (jComboBoxSelect == null) {\r
138 jComboBoxSelect = new JComboBox();\r
139 jComboBoxSelect.setBounds(new java.awt.Rectangle(220, 10, 260, 20));\r
140 jComboBoxSelect.setPreferredSize(new java.awt.Dimension(260,20));\r
141 \r
142 jComboBoxSelect.setEnabled(true);\r
143 }\r
144 return jComboBoxSelect;\r
145 }\r
146\r
147 /**\r
148 This method initializes jTable \r
149 \r
150 @return javax.swing.JTable \r
151 *\r
152 private JTable getJTable() {\r
153 if (jTable == null) {\r
154 model = new PackageHeaderTableModel();\r
155 model.addColumn("ModuleType");\r
156 model.addColumn("IncludeHeader");\r
157 \r
158\r
159 }\r
160 return jTable;\r
161 }*/\r
162 /**\r
163 This method initializes jButtonAdd \r
164 \r
165 @return javax.swing.JButton \r
166 **/\r
167 private JButton getJButtonAdd() {\r
168 if (jButtonAdd == null) {\r
169 jButtonAdd = new JButton();\r
170 jButtonAdd.setBounds(new java.awt.Rectangle(189,119,73,20));\r
171 jButtonAdd.setText("Add");\r
172 jButtonAdd.addActionListener(this);\r
173 }\r
174 return jButtonAdd;\r
175 }\r
176\r
177 /**\r
178 This method initializes jButtonRemove \r
179 \r
180 @return javax.swing.JButton \r
181 **/\r
182 private JButton getJButtonRemove() {\r
183 if (jButtonRemove == null) {\r
184 jButtonRemove = new JButton();\r
185 jButtonRemove.setBounds(new java.awt.Rectangle(271,119,87,20));\r
186 jButtonRemove.setText("Remove");\r
187 jButtonRemove.addActionListener(this);\r
188 }\r
189 return jButtonRemove;\r
190 }\r
191\r
192 /**\r
193 This method initializes jButtonRemoveAll \r
194 \r
195 @return javax.swing.JButton \r
196 **/\r
197 private JButton getJButtonClearAll() {\r
198 if (jButtonClearAll == null) {\r
199 jButtonClearAll = new JButton();\r
200 jButtonClearAll.setBounds(new java.awt.Rectangle(374,119,90,20));\r
201 jButtonClearAll.setText("Clear All");\r
202 jButtonClearAll.addActionListener(this);\r
203 }\r
204 return jButtonClearAll;\r
205 }\r
206\r
207 /**\r
208 This method initializes jButtonCancel \r
209 \r
210 @return javax.swing.JButton \r
211 **/\r
212 private JButton getJButtonCancel() {\r
213 if (jButtonCancel == null) {\r
214 jButtonCancel = new JButton();\r
215 jButtonCancel.setPreferredSize(new java.awt.Dimension(90, 20));\r
216 jButtonCancel.setLocation(new java.awt.Point(390, 305));\r
217 jButtonCancel.setText("Cancel");\r
218 jButtonCancel.setSize(new java.awt.Dimension(90, 20));\r
219 jButtonCancel.setVisible(false);\r
220 jButtonCancel.addActionListener(this);\r
221 }\r
222 return jButtonCancel;\r
223 }\r
224\r
225 /**\r
226 This method initializes jButton \r
227 \r
228 @return javax.swing.JButton \r
229 **/\r
230 private JButton getJButtonOk() {\r
231 if (jButtonOk == null) {\r
232 jButtonOk = new JButton();\r
233 jButtonOk.setSize(new java.awt.Dimension(90, 20));\r
234 jButtonOk.setText("OK");\r
235 jButtonOk.setLocation(new java.awt.Point(290, 305));\r
236 jButtonOk.setVisible(false);\r
237 jButtonOk.addActionListener(this);\r
238 }\r
239 return jButtonOk;\r
240 }\r
241\r
242 /**\r
243 This is the default constructor\r
244 **/\r
245 public SpdPackageHeaders() {\r
246 super();\r
247 initialize();\r
248 init();\r
249 \r
250 }\r
251\r
252 public SpdPackageHeaders(PackageSurfaceAreaDocument.PackageSurfaceArea inPsa){\r
253 this();\r
254 sfc = new SpdFileContents(inPsa);\r
255 init(sfc);\r
256 }\r
d6d24759 257 \r
258 public SpdPackageHeaders(OpeningPackageType opt) {\r
259 this(opt.getXmlSpd());\r
260 docConsole = opt;\r
261 }\r
a13899c5 262 /**\r
263 This method initializes this\r
264 \r
265 @return void\r
266 **/\r
267 private void init() {\r
268 \r
269 this.setContentPane(getJScrollPane());\r
270 this.setTitle("Library Class Declarations");\r
271 this.setBounds(new java.awt.Rectangle(0, 0, 500, 370));\r
272 this.setVisible(true);\r
273 this.addInternalFrameListener(new InternalFrameAdapter(){\r
274 public void internalFrameDeactivated(InternalFrameEvent e){\r
275 if (jTable.isEditing()) {\r
276 jTable.getCellEditor().stopCellEditing();\r
277 }\r
278 }\r
279 });\r
280 initFrame();\r
281 }\r
282\r
283 private void init(SpdFileContents sfc){\r
284 if (sfc.getSpdPackageHeaderCount() == 0) {\r
285 return ;\r
286 }\r
287 String[][] saa = new String[sfc.getSpdPackageHeaderCount()][2];\r
288 sfc.getSpdPackageHeaders(saa);\r
289 int i = 0;\r
290 while (i < saa.length) {\r
291 model.addRow(saa[i]);\r
292 i++;\r
293 }\r
294 }\r
295 \r
296 private JScrollPane getJScrollPane(){\r
297 if (jScrollPane == null){\r
298 jScrollPane = new JScrollPane();\r
299 jScrollPane.setViewportView(getJContentPane());\r
300 }\r
301 return jScrollPane;\r
302 }\r
303 /**\r
304 This method initializes jContentPane\r
305 \r
306 @return javax.swing.JPanel\r
307 **/\r
308 private JPanel getJContentPane() {\r
309 if (jContentPane == null) {\r
310 jStarLabel1 = new StarLabel();\r
311 jStarLabel1.setLocation(new java.awt.Point(0, 10));\r
312 jStarLabel2 = new StarLabel();\r
313 jStarLabel2.setLocation(new java.awt.Point(0,62));\r
314 jLabel = new JLabel();\r
315 jLabel.setBounds(new java.awt.Rectangle(14,62,199,22));\r
316 jLabel.setText("Include Header for Module Type");\r
317 \r
318 jContentPane = new JPanel();\r
319 jContentPane.setPreferredSize(new Dimension(480, 325));\r
320 jContentPane.setLayout(null);\r
321 jContentPane.add(jLabel, null);\r
322 jContentPane.add(jStarLabel1, null);\r
323 jContentPane.add(jStarLabel2, null);\r
a13899c5 324 jContentPane.add(getJRadioButtonSelect(), null);\r
a13899c5 325 jContentPane.add(getJComboBoxSelect(), null);\r
326 jContentPane.add(getJButtonAdd(), null);\r
327 jContentPane.add(getJButtonRemove(), null);\r
328 jContentPane.add(getJButtonClearAll(), null);\r
329 jContentPane.add(getJButtonCancel(), null);\r
330 jContentPane.add(getJButtonOk(), null);\r
331 \r
332 jContentPane.add(getJTextField(), null);\r
333 jContentPane.add(getJButtonBrowse(), null);\r
334 jContentPane.add(getJScrollPane1(), null);\r
335 }\r
336 return jContentPane;\r
337 }\r
338\r
339 /**\r
340 fill ComboBoxes with pre-defined contents\r
341 **/\r
342 private void initFrame() {\r
343 jComboBoxSelect.addItem("BASE");\r
344 jComboBoxSelect.addItem("SEC");\r
345 jComboBoxSelect.addItem("PEI_CORE");\r
346 jComboBoxSelect.addItem("PEIM");\r
347 jComboBoxSelect.addItem("DXE_CORE");\r
348 jComboBoxSelect.addItem("DXE_DRIVER");\r
349 jComboBoxSelect.addItem("DXE_RUNTIME_DRIVER");\r
350 jComboBoxSelect.addItem("DXE_SAL_DRIVER");\r
351 jComboBoxSelect.addItem("DXE_SMM_DRIVER");\r
d3792844 352 jComboBoxSelect.addItem("TOOL");\r
a13899c5 353 jComboBoxSelect.addItem("UEFI_DRIVER");\r
354 jComboBoxSelect.addItem("UEFI_APPLICATION");\r
355 jComboBoxSelect.addItem("USER_DEFINED");\r
356 jComboBoxSelect.setSelectedIndex(0);\r
357 }\r
358\r
359 /* (non-Javadoc)\r
360 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
361 */\r
362 public void actionPerformed(ActionEvent arg0) {\r
d6d24759 363 \r
364 docConsole.setSaved(false);\r
a13899c5 365 if (arg0.getSource() == jButtonOk) {\r
366 this.save();\r
367 this.dispose();\r
368\r
369 }\r
370 if (arg0.getSource() == jButtonCancel) {\r
371 this.dispose();\r
372 }\r
373\r
374 if (arg0.getSource() == jButtonAdd) {\r
375 String strLibClass = "";\r
ce73a791 376 \r
a13899c5 377 if (jRadioButtonSelect.isSelected()) {\r
378 strLibClass = jComboBoxSelect.getSelectedItem().toString();\r
379 }\r
380 //ToDo: check before add\r
381 String[] row = {"", ""};\r
382 row[0] = strLibClass;\r
383 row[1] = jTextField.getText().replace('\\', '/');\r
ce73a791 384 if (!dataValidation(row)) {\r
385 return;\r
386 }\r
a13899c5 387 model.addRow(row);\r
af25df16 388 jTable.changeSelection(model.getRowCount()-1, 0, false, false);\r
a13899c5 389 sfc.genSpdModuleHeaders(row[0], row[1], null, null, null, null, null, null);\r
390 }\r
391 //\r
392 // remove selected line\r
393 //\r
394 if (arg0.getSource() == jButtonRemove) {\r
395 if (jTable.isEditing()){\r
396 jTable.getCellEditor().stopCellEditing();\r
397 }\r
398 int rowSelected = selectedRow;\r
399 if (rowSelected >= 0) {\r
400 model.removeRow(rowSelected);\r
401 sfc.removeSpdPkgHeader(rowSelected);\r
402 }\r
403 }\r
404\r
405 if (arg0.getSource() == jButtonClearAll) {\r
406 if (model.getRowCount() == 0) {\r
407 return;\r
408 }\r
409 model.setRowCount(0);\r
410 sfc.removeSpdPkgHeader();\r
411 }\r
412\r
ce73a791 413 }\r
414 \r
415 private boolean dataValidation(String[] row) {\r
416 if (!DataValidation.isPathAndFilename(row[1])) {\r
417 JOptionPane.showMessageDialog(this, "Include header path is NOT PathAndFilename type.");\r
418 return false;\r
a13899c5 419 }\r
ce73a791 420 \r
421 return true;\r
a13899c5 422 }\r
423\r
424 /**\r
425 Add contents in list to sfc\r
426 **/\r
427 protected void save() {\r
428 \r
429 }\r
430\r
431 /**\r
432 This method initializes jTextField \r
433 \r
434 @return javax.swing.JTextField \r
435 **/\r
436 private JTextField getJTextField() {\r
437 if (jTextField == null) {\r
438 jTextField = new JTextField();\r
439 jTextField.setBounds(new java.awt.Rectangle(13,90,346,21));\r
440 jTextField.setPreferredSize(new java.awt.Dimension(345,20));\r
441 }\r
442 return jTextField;\r
443 }\r
444\r
445 /**\r
446 This method initializes jButtonBrowse \r
447 \r
448 @return javax.swing.JButton \r
449 **/\r
450 private JButton getJButtonBrowse() {\r
451 if (jButtonBrowse == null) {\r
452 jButtonBrowse = new JButton();\r
453 jButtonBrowse.setBounds(new java.awt.Rectangle(374,89,92,21));\r
454 jButtonBrowse.setText("Browse");\r
455 jButtonBrowse.setPreferredSize(new java.awt.Dimension(92,20));\r
456 jButtonBrowse.addActionListener(new javax.swing.AbstractAction() {\r
ce73a791 457 /**\r
458 * \r
459 */\r
460 private static final long serialVersionUID = 1L;\r
461\r
a13899c5 462 public void actionPerformed(ActionEvent e) {\r
463 //\r
464 // Select files from current workspace\r
465 //\r
466 String dirPrefix = Tools.dirForNewSpd.substring(0, Tools.dirForNewSpd.lastIndexOf(File.separator));\r
467 JFileChooser chooser = new JFileChooser(dirPrefix);\r
468 File theFile = null;\r
469 String headerDest = null;\r
470 \r
471 chooser.setMultiSelectionEnabled(false);\r
472 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);\r
473 int retval = chooser.showOpenDialog(frame);\r
474 if (retval == JFileChooser.APPROVE_OPTION) {\r
475\r
476 theFile = chooser.getSelectedFile();\r
477 String file = theFile.getPath();\r
478 if (!file.startsWith(dirPrefix)) {\r
479 JOptionPane.showMessageDialog(frame, "You can only select files in current package!");\r
480 return;\r
481 }\r
482 \r
483 \r
484 }\r
485 else {\r
486 return;\r
487 }\r
488 \r
489 headerDest = theFile.getPath();\r
490 int fileIndex = headerDest.indexOf(System.getProperty("file.separator"), dirPrefix.length());\r
491 \r
492 jTextField.setText(headerDest.substring(fileIndex + 1).replace('\\', '/'));\r
493 \r
494 }\r
495 });\r
496 }\r
497 return jButtonBrowse;\r
498 }\r
499 \r
500 /**\r
501 * This method initializes jScrollPane \r
502 * \r
503 * @return javax.swing.JScrollPane \r
504 */\r
505 private JScrollPane getJScrollPane1() {\r
506 if (jScrollPane1 == null) {\r
507 jScrollPane1 = new JScrollPane();\r
af25df16 508 jScrollPane1.setBounds(new java.awt.Rectangle(13,149,453,258));\r
a13899c5 509 jScrollPane1.setViewportView(getJTable());\r
510 }\r
511 return jScrollPane1;\r
512 }\r
513\r
514 /**\r
515 * This method initializes jTable \r
516 * \r
517 * @return javax.swing.JTable \r
518 */\r
519 private JTable getJTable() {\r
520 if (jTable == null) {\r
521 model = new DefaultTableModel();\r
522 jTable = new JTable(model);\r
ce73a791 523 jTable.setRowHeight(20);\r
a13899c5 524 model.addColumn("ModuleType");\r
525 model.addColumn("IncludeHeader");\r
526 TableColumn typeColumn = jTable.getColumnModel().getColumn(0);\r
527 JComboBox jComboBoxSelect = new JComboBox();\r
528 jComboBoxSelect.addItem("BASE");\r
529 jComboBoxSelect.addItem("SEC");\r
530 jComboBoxSelect.addItem("PEI_CORE");\r
531 jComboBoxSelect.addItem("PEIM");\r
532 jComboBoxSelect.addItem("DXE_CORE");\r
533 jComboBoxSelect.addItem("DXE_DRIVER");\r
534 jComboBoxSelect.addItem("DXE_RUNTIME_DRIVER");\r
535 jComboBoxSelect.addItem("DXE_SAL_DRIVER");\r
536 jComboBoxSelect.addItem("DXE_SMM_DRIVER");\r
d3792844 537 jComboBoxSelect.addItem("TOOL");\r
a13899c5 538 jComboBoxSelect.addItem("UEFI_DRIVER");\r
539 jComboBoxSelect.addItem("UEFI_APPLICATION");\r
540 jComboBoxSelect.addItem("USER_DEFINED");\r
541 typeColumn.setCellEditor(new DefaultCellEditor(jComboBoxSelect));\r
542 \r
543 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
544 jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){\r
545 public void valueChanged(ListSelectionEvent e) {\r
546 if (e.getValueIsAdjusting()){\r
547 return;\r
548 }\r
549 ListSelectionModel lsm = (ListSelectionModel)e.getSource();\r
550 if (lsm.isSelectionEmpty()) {\r
551 return;\r
552 }\r
553 else{\r
554 selectedRow = lsm.getMinSelectionIndex();\r
555 }\r
556 }\r
557 });\r
558 \r
559 jTable.getModel().addTableModelListener(this);\r
560 }\r
561 return jTable;\r
562 }\r
563 \r
564 public void tableChanged(TableModelEvent arg0) {\r
565 // TODO Auto-generated method stub\r
566 int row = arg0.getFirstRow();\r
567 TableModel m = (TableModel)arg0.getSource();\r
568 if (arg0.getType() == TableModelEvent.UPDATE){\r
569 String pkg = m.getValueAt(row, 0) + "";\r
570 String hdr = m.getValueAt(row, 1) + "";\r
ce73a791 571 String[] rowData = {pkg, hdr};\r
572 if (!dataValidation(rowData)) {\r
573 return;\r
574 }\r
d6d24759 575 docConsole.setSaved(false);\r
a13899c5 576 sfc.updateSpdPkgHdr(row, pkg, hdr);\r
577 }\r
578 }\r
579\r
580 public void componentResized(ComponentEvent arg0) {\r
581 int intPreferredWidth = 500;\r
582 \r
583 resizeComponentWidth(this.jComboBoxSelect, this.getWidth(), intPreferredWidth);\r
a13899c5 584 resizeComponentWidth(this.jTextField, this.getWidth(), intPreferredWidth);\r
585 resizeComponentWidth(this.jScrollPane, this.getWidth(), intPreferredWidth);\r
586 relocateComponentX(this.jButtonBrowse, this.getWidth(), this.getPreferredSize().width, 30);\r
587 }\r
588 \r
589 public static void main(String[] args){\r
590 new SpdPackageHeaders().setVisible(true);\r
591 }\r
592}\r
593\r
594\r