]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/UpdatePkgHeader.java
Fix the problem "update action multiple times fail".
[mirror_edk2.git] / Tools / Source / PackageEditor / src / org / tianocore / packaging / UpdatePkgHeader.java
1 /** @file
2 Java class UpdatePkgHeader is GUI for update Package Header in 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.packaging;
14
15 import javax.swing.DefaultCellEditor;
16 import javax.swing.JComboBox;
17 import javax.swing.JPanel;
18 import javax.swing.JFrame;
19 import javax.swing.JLabel;
20 import javax.swing.JTextField;
21 import javax.swing.JButton;
22
23 import javax.swing.JScrollPane;
24 import javax.swing.JTable;
25 import javax.swing.table.*;
26
27 import org.tianocore.common.Tools;
28
29 import java.awt.Dimension;
30 import java.awt.Toolkit;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33 import java.io.*;
34
35 /**
36 GUI for update Package Header in spd file
37
38 @since PackageEditor 1.0
39 **/
40 public class UpdatePkgHeader extends JFrame implements ActionListener {
41
42 private JPanel jContentPane = null;
43
44 private JScrollPane jScrollPane = null;
45
46 private JTable jTable = null;
47
48 private SpdFileContents sfc = null;
49
50 private JButton jButtonOk = null;
51
52 private JButton jButtonCancel = null;
53
54 private DefaultTableModel model = null;
55
56 private JButton jButton = null;
57
58 /**
59 This is the default constructor
60 **/
61 public UpdatePkgHeader(SpdFileContents sfc) {
62 super();
63 this.sfc = sfc;
64 initialize();
65
66 }
67
68 public void actionPerformed(ActionEvent arg0) {
69 if (arg0.getSource() == jButtonOk) {
70 this.save();
71 this.dispose();
72
73 }
74 if (arg0.getSource() == jButtonCancel) {
75 this.dispose();
76
77 }
78
79 if (arg0.getSource() == jButton) {
80 String[] o = { "BASE", "" };
81 model.addRow(o);
82 }
83 }
84
85 /**
86 This method initializes this
87
88 @return void
89 **/
90 private void initialize() {
91 this.setSize(604, 553);
92 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
93 this.setTitle("Update Package Headers");
94 this.setContentPane(getJContentPane());
95 this.centerWindow();
96 }
97 /**
98 Start the window at the center of screen
99
100 **/
101 protected void centerWindow(int intWidth, int intHeight) {
102 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
103 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
104 }
105
106 /**
107 Start the window at the center of screen
108
109 **/
110 protected void centerWindow() {
111 centerWindow(this.getSize().width, this.getSize().height);
112 }
113 /**
114 This method initializes jContentPane
115
116 @return javax.swing.JPanel
117 **/
118 private JPanel getJContentPane() {
119 if (jContentPane == null) {
120 jContentPane = new JPanel();
121 jContentPane.setLayout(null);
122 jContentPane.add(getJScrollPane(), null);
123 jContentPane.add(getJButtonOk(), null);
124 jContentPane.add(getJButtonCancel(), null);
125 jContentPane.add(getJButton(), null);
126 }
127 return jContentPane;
128 }
129
130 /**
131 This method initializes jScrollPane
132
133 @return javax.swing.JScrollPane
134 **/
135 private JScrollPane getJScrollPane() {
136 if (jScrollPane == null) {
137 jScrollPane = new JScrollPane();
138 jScrollPane.setBounds(new java.awt.Rectangle(38, 45, 453, 419));
139 jScrollPane.setViewportView(getJTable());
140 }
141 return jScrollPane;
142 }
143
144 /**
145 This method initializes jTable
146
147 @return javax.swing.JTable
148 **/
149 private JTable getJTable() {
150 if (jTable == null) {
151 model = new DefaultTableModel();
152 jTable = new JTable(model);
153 jTable.setRowHeight(20);
154 model.addColumn("ModuleType");
155 model.addColumn("IncludeHeader");
156 //
157 // Using combobox to display ModuleType in table
158 //
159 TableColumn typeColumn = jTable.getColumnModel().getColumn(0);
160 JComboBox jComboBoxSelect = new JComboBox();
161 jComboBoxSelect.addItem("BASE");
162 jComboBoxSelect.addItem("SEC");
163 jComboBoxSelect.addItem("PEI_CORE");
164 jComboBoxSelect.addItem("PEIM");
165 jComboBoxSelect.addItem("DXE_CORE");
166 jComboBoxSelect.addItem("DXE_DRIVER");
167 jComboBoxSelect.addItem("DXE_RUNTIME_DRIVER");
168 jComboBoxSelect.addItem("DXE_SAL_DRIVER");
169 jComboBoxSelect.addItem("DXE_SMM_DRIVER");
170 jComboBoxSelect.addItem("TOOLS");
171 jComboBoxSelect.addItem("UEFI_DRIVER");
172 jComboBoxSelect.addItem("UEFI_APPLICATION");
173 jComboBoxSelect.addItem("USER_DEFINED");
174 typeColumn.setCellEditor(new DefaultCellEditor(jComboBoxSelect));
175
176 if (sfc.getSpdPackageHeaderCount() == 0) {
177 return jTable;
178 }
179 String[][] saa = new String[sfc.getSpdPackageHeaderCount()][2];
180 sfc.getSpdPackageHeaders(saa);
181 int i = 0;
182 while (i < saa.length) {
183 model.addRow(saa[i]);
184 i++;
185 }
186
187 }
188 return jTable;
189 }
190
191 /**
192 Remove original package headers before saving updated ones
193 **/
194 protected void save() {
195 if (jTable.isEditing()) {
196 jTable.getCellEditor().stopCellEditing();
197 }
198 sfc.removeSpdPkgHeader();
199 int rowCount = model.getRowCount();
200 int i = 0;
201 while (i < rowCount) {
202 String headFile = null;
203 if (model.getValueAt(i, 1) != null) {
204 headFile = model.getValueAt(i, 1).toString();
205 }
206 sfc.genSpdModuleHeaders(model.getValueAt(i, 0).toString(), headFile, null, null, null, null, null, null);
207 i++;
208 }
209 }
210
211 /**
212 This method initializes jButtonOk
213
214 @return javax.swing.JButton
215 **/
216 private JButton getJButtonOk() {
217 if (jButtonOk == null) {
218 jButtonOk = new JButton();
219 jButtonOk.setText("Ok");
220 jButtonOk.setSize(new java.awt.Dimension(84, 20));
221 jButtonOk.setLocation(new java.awt.Point(316, 486));
222 jButtonOk.addActionListener(this);
223 }
224 return jButtonOk;
225 }
226
227 /**
228 This method initializes jButtonCancel
229
230 @return javax.swing.JButton
231 **/
232 private JButton getJButtonCancel() {
233 if (jButtonCancel == null) {
234 jButtonCancel = new JButton();
235 jButtonCancel.setText("Cancel");
236 jButtonCancel.setSize(new java.awt.Dimension(82, 20));
237 jButtonCancel.setLocation(new java.awt.Point(411, 486));
238 jButtonCancel.addActionListener(this);
239 }
240 return jButtonCancel;
241 }
242
243 /**
244 This method initializes jButton
245
246 @return javax.swing.JButton
247 **/
248 private JButton getJButton() {
249 if (jButton == null) {
250 jButton = new JButton();
251 jButton.setBounds(new java.awt.Rectangle(220, 486, 85, 20));
252 jButton.setText("Insert");
253 jButton.addActionListener(this);
254 }
255 return jButton;
256 }
257 } // @jve:decl-index=0:visual-constraint="11,7"