2 Java class SpdPackageHeaders is GUI for create library definition elements of spd file.
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
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.
13 package org
.tianocore
.frameworkwizard
.packaging
.ui
;
15 import java
.awt
.Dimension
;
16 import java
.awt
.event
.ActionEvent
;
17 import java
.awt
.event
.ComponentEvent
;
20 import javax
.swing
.DefaultCellEditor
;
21 import javax
.swing
.JFileChooser
;
22 import javax
.swing
.JOptionPane
;
23 import javax
.swing
.JPanel
;
24 import javax
.swing
.JRadioButton
;
25 import javax
.swing
.JTable
;
26 import javax
.swing
.JTextField
;
27 import javax
.swing
.JComboBox
;
28 import javax
.swing
.JLabel
;
29 import javax
.swing
.JScrollPane
;
30 import javax
.swing
.JButton
;
31 import javax
.swing
.JFrame
;
32 import javax
.swing
.ListSelectionModel
;
33 import javax
.swing
.event
.InternalFrameAdapter
;
34 import javax
.swing
.event
.InternalFrameEvent
;
35 import javax
.swing
.event
.ListSelectionEvent
;
36 import javax
.swing
.event
.ListSelectionListener
;
37 import javax
.swing
.event
.TableModelEvent
;
38 import javax
.swing
.event
.TableModelListener
;
39 import javax
.swing
.table
.DefaultTableModel
;
40 import javax
.swing
.table
.TableColumn
;
41 import javax
.swing
.table
.TableModel
;
43 import org
.tianocore
.PackageSurfaceAreaDocument
;
44 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
45 import org
.tianocore
.frameworkwizard
.common
.Tools
;
46 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningPackageType
;
47 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
48 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
51 GUI for create library definition elements of spd file.
53 @since PackageEditor 1.0
55 public class SpdPackageHeaders
extends IInternalFrame
implements TableModelListener
{
59 private static final long serialVersionUID
= 1L;
63 private SpdFileContents sfc
= null;
65 private OpeningPackageType docConsole
= null;
67 private DefaultTableModel model
= null;
69 private JPanel jContentPane
= null;
71 private JRadioButton jRadioButtonSelect
= null;
73 private JComboBox jComboBoxSelect
= null;
75 private JButton jButtonAdd
= null;
77 private JButton jButtonRemove
= null;
79 private JButton jButtonClearAll
= null;
81 private JButton jButtonCancel
= null;
83 private JButton jButtonOk
= null;
85 private JLabel jLabel
= null;
87 private JTextField jTextField
= null;
89 private JButton jButtonBrowse
= null;
91 private StarLabel jStarLabel1
= null;
93 private StarLabel jStarLabel2
= null;
95 private JScrollPane jScrollPane
= null;
97 private JScrollPane jScrollPanePkgHdr
= null;
99 private int selectedRow
= -1;
101 private JTable jTable
= null;
106 This method initializes this
109 private void initialize() {
111 this.setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
116 This method initializes jRadioButtonSelect
118 @return javax.swing.JRadioButton
120 private JRadioButton
getJRadioButtonSelect() {
121 if (jRadioButtonSelect
== null) {
122 jRadioButtonSelect
= new JRadioButton();
123 jRadioButtonSelect
.setBounds(new java
.awt
.Rectangle(9,10,198,20));
124 jRadioButtonSelect
.setText("Select Existing ModuleType");
125 jRadioButtonSelect
.addActionListener(this);
126 jRadioButtonSelect
.setSelected(true);
128 return jRadioButtonSelect
;
132 This method initializes jComboBoxSelect
134 @return javax.swing.JComboBox
136 private JComboBox
getJComboBoxSelect() {
137 if (jComboBoxSelect
== null) {
138 jComboBoxSelect
= new JComboBox();
139 jComboBoxSelect
.setBounds(new java
.awt
.Rectangle(220, 10, 260, 20));
140 jComboBoxSelect
.setPreferredSize(new java
.awt
.Dimension(260,20));
142 jComboBoxSelect
.setEnabled(true);
144 return jComboBoxSelect
;
148 This method initializes jTable
150 @return javax.swing.JTable
152 private JTable getJTable() {
153 if (jTable == null) {
154 model = new PackageHeaderTableModel();
155 model.addColumn("ModuleType");
156 model.addColumn("IncludeHeader");
163 This method initializes jButtonAdd
165 @return javax.swing.JButton
167 private JButton
getJButtonAdd() {
168 if (jButtonAdd
== null) {
169 jButtonAdd
= new JButton();
170 jButtonAdd
.setBounds(new java
.awt
.Rectangle(189,119,73,20));
171 jButtonAdd
.setText("Add");
172 jButtonAdd
.addActionListener(this);
178 This method initializes jButtonRemove
180 @return javax.swing.JButton
182 private JButton
getJButtonRemove() {
183 if (jButtonRemove
== null) {
184 jButtonRemove
= new JButton();
185 jButtonRemove
.setBounds(new java
.awt
.Rectangle(271,119,87,20));
186 jButtonRemove
.setText("Remove");
187 jButtonRemove
.addActionListener(this);
189 return jButtonRemove
;
193 This method initializes jButtonRemoveAll
195 @return javax.swing.JButton
197 private JButton
getJButtonClearAll() {
198 if (jButtonClearAll
== null) {
199 jButtonClearAll
= new JButton();
200 jButtonClearAll
.setBounds(new java
.awt
.Rectangle(374,119,90,20));
201 jButtonClearAll
.setText("Clear All");
202 jButtonClearAll
.addActionListener(this);
204 return jButtonClearAll
;
208 This method initializes jButtonCancel
210 @return javax.swing.JButton
212 private JButton
getJButtonCancel() {
213 if (jButtonCancel
== null) {
214 jButtonCancel
= new JButton();
215 jButtonCancel
.setPreferredSize(new java
.awt
.Dimension(90, 20));
216 jButtonCancel
.setLocation(new java
.awt
.Point(390, 305));
217 jButtonCancel
.setText("Cancel");
218 jButtonCancel
.setSize(new java
.awt
.Dimension(90, 20));
219 jButtonCancel
.setVisible(false);
220 jButtonCancel
.addActionListener(this);
222 return jButtonCancel
;
226 This method initializes jButton
228 @return javax.swing.JButton
230 private JButton
getJButtonOk() {
231 if (jButtonOk
== null) {
232 jButtonOk
= new JButton();
233 jButtonOk
.setSize(new java
.awt
.Dimension(90, 20));
234 jButtonOk
.setText("OK");
235 jButtonOk
.setLocation(new java
.awt
.Point(290, 305));
236 jButtonOk
.setVisible(false);
237 jButtonOk
.addActionListener(this);
243 This is the default constructor
245 public SpdPackageHeaders() {
252 public SpdPackageHeaders(PackageSurfaceAreaDocument
.PackageSurfaceArea inPsa
){
254 sfc
= new SpdFileContents(inPsa
);
258 public SpdPackageHeaders(OpeningPackageType opt
) {
259 this(opt
.getXmlSpd());
263 This method initializes this
267 private void init() {
269 this.setContentPane(getJScrollPane());
270 this.setTitle("Package Headers");
271 this.setBounds(new java
.awt
.Rectangle(0, 0, 500, 370));
272 this.setVisible(true);
273 this.addInternalFrameListener(new InternalFrameAdapter(){
274 public void internalFrameDeactivated(InternalFrameEvent e
){
275 if (jTable
.isEditing()) {
276 jTable
.getCellEditor().stopCellEditing();
283 private void init(SpdFileContents sfc
){
284 if (sfc
.getSpdPackageHeaderCount() == 0) {
287 String
[][] saa
= new String
[sfc
.getSpdPackageHeaderCount()][2];
288 sfc
.getSpdPackageHeaders(saa
);
290 while (i
< saa
.length
) {
291 model
.addRow(saa
[i
]);
296 private JScrollPane
getJScrollPane(){
297 if (jScrollPane
== null){
298 jScrollPane
= new JScrollPane();
299 jScrollPane
.setViewportView(getJContentPane());
304 This method initializes jContentPane
306 @return javax.swing.JPanel
308 private JPanel
getJContentPane() {
309 if (jContentPane
== null) {
310 jStarLabel1
= new StarLabel();
311 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
312 jStarLabel2
= new StarLabel();
313 jStarLabel2
.setLocation(new java
.awt
.Point(0,62));
314 jLabel
= new JLabel();
315 jLabel
.setBounds(new java
.awt
.Rectangle(14,62,199,22));
316 jLabel
.setText("Include Header for Module Type");
318 jContentPane
= new JPanel();
319 jContentPane
.setPreferredSize(new Dimension(480, 325));
320 jContentPane
.setLayout(null);
321 jContentPane
.add(jLabel
, null);
322 jContentPane
.add(jStarLabel1
, null);
323 jContentPane
.add(jStarLabel2
, null);
324 jContentPane
.add(getJRadioButtonSelect(), null);
325 jContentPane
.add(getJComboBoxSelect(), null);
326 jContentPane
.add(getJButtonAdd(), null);
327 jContentPane
.add(getJButtonRemove(), null);
328 jContentPane
.add(getJButtonClearAll(), null);
329 jContentPane
.add(getJButtonCancel(), null);
330 jContentPane
.add(getJButtonOk(), null);
332 jContentPane
.add(getJTextField(), null);
333 jContentPane
.add(getJButtonBrowse(), null);
334 jContentPane
.add(getJScrollPanePkgHdr(), null);
340 fill ComboBoxes with pre-defined contents
342 private void initFrame() {
343 jComboBoxSelect
.addItem("BASE");
344 jComboBoxSelect
.addItem("SEC");
345 jComboBoxSelect
.addItem("PEI_CORE");
346 jComboBoxSelect
.addItem("PEIM");
347 jComboBoxSelect
.addItem("DXE_CORE");
348 jComboBoxSelect
.addItem("DXE_DRIVER");
349 jComboBoxSelect
.addItem("DXE_RUNTIME_DRIVER");
350 jComboBoxSelect
.addItem("DXE_SAL_DRIVER");
351 jComboBoxSelect
.addItem("DXE_SMM_DRIVER");
352 jComboBoxSelect
.addItem("TOOL");
353 jComboBoxSelect
.addItem("UEFI_DRIVER");
354 jComboBoxSelect
.addItem("UEFI_APPLICATION");
355 jComboBoxSelect
.addItem("USER_DEFINED");
356 jComboBoxSelect
.setSelectedIndex(0);
360 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
362 public void actionPerformed(ActionEvent arg0
) {
364 docConsole
.setSaved(false);
365 if (arg0
.getSource() == jButtonOk
) {
370 if (arg0
.getSource() == jButtonCancel
) {
374 if (arg0
.getSource() == jButtonAdd
) {
375 String strLibClass
= "";
377 if (jRadioButtonSelect
.isSelected()) {
378 strLibClass
= jComboBoxSelect
.getSelectedItem().toString();
380 //ToDo: check before add
381 String
[] row
= {"", ""};
382 row
[0] = strLibClass
;
383 row
[1] = jTextField
.getText().replace('\\', '/');
384 if (!dataValidation(row
)) {
388 jTable
.changeSelection(model
.getRowCount()-1, 0, false, false);
389 sfc
.genSpdModuleHeaders(row
[0], row
[1], null, null, null, null, null, null);
392 // remove selected line
394 if (arg0
.getSource() == jButtonRemove
) {
395 if (jTable
.isEditing()){
396 jTable
.getCellEditor().stopCellEditing();
398 int rowSelected
= selectedRow
;
399 if (rowSelected
>= 0) {
400 model
.removeRow(rowSelected
);
401 sfc
.removeSpdPkgHeader(rowSelected
);
405 if (arg0
.getSource() == jButtonClearAll
) {
406 if (model
.getRowCount() == 0) {
409 model
.setRowCount(0);
410 sfc
.removeSpdPkgHeader();
415 private boolean dataValidation(String
[] row
) {
416 if (!DataValidation
.isPathAndFilename(row
[1])) {
417 JOptionPane
.showMessageDialog(this, "Include header path is NOT PathAndFilename type.");
425 Add contents in list to sfc
427 protected void save() {
432 This method initializes jTextField
434 @return javax.swing.JTextField
436 private JTextField
getJTextField() {
437 if (jTextField
== null) {
438 jTextField
= new JTextField();
439 jTextField
.setBounds(new java
.awt
.Rectangle(13,90,346,21));
440 jTextField
.setPreferredSize(new java
.awt
.Dimension(345,20));
446 This method initializes jButtonBrowse
448 @return javax.swing.JButton
450 private JButton
getJButtonBrowse() {
451 if (jButtonBrowse
== null) {
452 jButtonBrowse
= new JButton();
453 jButtonBrowse
.setBounds(new java
.awt
.Rectangle(374,89,92,21));
454 jButtonBrowse
.setText("Browse");
455 jButtonBrowse
.setPreferredSize(new java
.awt
.Dimension(92,20));
456 jButtonBrowse
.addActionListener(new javax
.swing
.AbstractAction() {
460 private static final long serialVersionUID
= 1L;
462 public void actionPerformed(ActionEvent e
) {
464 // Select files from current workspace
466 String dirPrefix
= Tools
.dirForNewSpd
.substring(0, Tools
.dirForNewSpd
.lastIndexOf(File
.separator
));
467 JFileChooser chooser
= new JFileChooser(dirPrefix
);
469 String headerDest
= null;
471 chooser
.setMultiSelectionEnabled(false);
472 chooser
.setFileSelectionMode(JFileChooser
.FILES_AND_DIRECTORIES
);
473 int retval
= chooser
.showOpenDialog(frame
);
474 if (retval
== JFileChooser
.APPROVE_OPTION
) {
476 theFile
= chooser
.getSelectedFile();
477 String file
= theFile
.getPath();
478 if (!file
.startsWith(dirPrefix
)) {
479 JOptionPane
.showMessageDialog(frame
, "You can only select files in current package!");
489 headerDest
= theFile
.getPath();
490 int fileIndex
= headerDest
.indexOf(System
.getProperty("file.separator"), dirPrefix
.length());
492 jTextField
.setText(headerDest
.substring(fileIndex
+ 1).replace('\\', '/'));
497 return jButtonBrowse
;
501 * This method initializes jScrollPane
503 * @return javax.swing.JScrollPane
505 private JScrollPane
getJScrollPanePkgHdr() {
506 if (jScrollPanePkgHdr
== null) {
507 jScrollPanePkgHdr
= new JScrollPane();
508 jScrollPanePkgHdr
.setBounds(new java
.awt
.Rectangle(13,149,453,258));
509 jScrollPanePkgHdr
.setViewportView(getJTable());
511 return jScrollPanePkgHdr
;
515 * This method initializes jTable
517 * @return javax.swing.JTable
519 private JTable
getJTable() {
520 if (jTable
== null) {
521 model
= new DefaultTableModel();
522 jTable
= new JTable(model
);
523 jTable
.setRowHeight(20);
524 model
.addColumn("ModuleType");
525 model
.addColumn("IncludeHeader");
526 TableColumn typeColumn
= jTable
.getColumnModel().getColumn(0);
527 JComboBox jComboBoxSelect
= new JComboBox();
528 jComboBoxSelect
.addItem("BASE");
529 jComboBoxSelect
.addItem("SEC");
530 jComboBoxSelect
.addItem("PEI_CORE");
531 jComboBoxSelect
.addItem("PEIM");
532 jComboBoxSelect
.addItem("DXE_CORE");
533 jComboBoxSelect
.addItem("DXE_DRIVER");
534 jComboBoxSelect
.addItem("DXE_RUNTIME_DRIVER");
535 jComboBoxSelect
.addItem("DXE_SAL_DRIVER");
536 jComboBoxSelect
.addItem("DXE_SMM_DRIVER");
537 jComboBoxSelect
.addItem("TOOL");
538 jComboBoxSelect
.addItem("UEFI_DRIVER");
539 jComboBoxSelect
.addItem("UEFI_APPLICATION");
540 jComboBoxSelect
.addItem("USER_DEFINED");
541 typeColumn
.setCellEditor(new DefaultCellEditor(jComboBoxSelect
));
543 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
544 jTable
.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
545 public void valueChanged(ListSelectionEvent e
) {
546 if (e
.getValueIsAdjusting()){
549 ListSelectionModel lsm
= (ListSelectionModel
)e
.getSource();
550 if (lsm
.isSelectionEmpty()) {
554 selectedRow
= lsm
.getMinSelectionIndex();
559 jTable
.getModel().addTableModelListener(this);
564 public void tableChanged(TableModelEvent arg0
) {
565 // TODO Auto-generated method stub
566 int row
= arg0
.getFirstRow();
567 int column
= arg0
.getColumn();
568 TableModel m
= (TableModel
)arg0
.getSource();
569 if (arg0
.getType() == TableModelEvent
.UPDATE
){
570 String
[] sa
= new String
[2];
571 sfc
.getSpdModuleHeader(sa
, row
);
572 Object cellData
= m
.getValueAt(row
, column
);
573 if (cellData
== null) {
576 if (cellData
.equals(sa
[column
])) {
579 if (cellData
.toString().length() == 0 && sa
[column
] == null) {
582 String pkg
= m
.getValueAt(row
, 0) + "";
583 String hdr
= m
.getValueAt(row
, 1) + "";
584 String
[] rowData
= {pkg
, hdr
};
585 if (!dataValidation(rowData
)) {
588 docConsole
.setSaved(false);
589 sfc
.updateSpdPkgHdr(row
, pkg
, hdr
);
593 public void componentResized(ComponentEvent arg0
) {
594 int intPreferredWidth
= 500;
596 resizeComponentWidth(this.jComboBoxSelect
, this.getWidth(), intPreferredWidth
);
597 resizeComponentWidth(this.jTextField
, this.getWidth(), intPreferredWidth
);
598 resizeComponentWidth(this.jScrollPane
, this.getWidth(), intPreferredWidth
);
599 relocateComponentX(this.jButtonBrowse
, this.getWidth(), this.getPreferredSize().width
, 30);
602 public static void main(String
[] args
){
603 new SpdPackageHeaders().setVisible(true);