]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/UpdatePCD.java
Fix the problem "update action multiple times fail".
[mirror_edk2.git] / Tools / Source / PackageEditor / src / org / tianocore / packaging / UpdatePCD.java
1 /** @file
2 Java class UpdatePCD is GUI for update PCD definitions 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 PCD definitions in spd file
37
38 @since PackageEditor 1.0
39 **/
40 public class UpdatePCD extends JFrame implements ActionListener {
41
42 private JPanel jContentPane = null;
43
44 private SpdFileContents sfc = null;
45
46 private JButton jButtonOk = null;
47
48 private JButton jButtonCancel = null;
49
50 private DefaultTableModel model = null;
51
52 private String[][] saa = null;
53
54 private JScrollPane jScrollPane = null;
55
56 private JTable jTable = null;
57
58 private JButton jButton = null;
59
60 /**
61 This is the default constructor
62 **/
63 public UpdatePCD(SpdFileContents sfc) {
64 super();
65 this.sfc = sfc;
66 initialize();
67
68 }
69
70 public void actionPerformed(ActionEvent arg0) {
71 if (arg0.getSource() == jButtonOk) {
72 this.save();
73 this.dispose();
74
75 }
76 if (arg0.getSource() == jButtonCancel) {
77 this.dispose();
78
79 }
80 if (arg0.getSource() == jButton) {
81 String[] o = { "FEATURE_FLAG", "", "", "UINT8", "0" };
82 model.addRow(o);
83 }
84
85 }
86
87 /**
88 This method initializes this
89
90 @return void
91 **/
92 private void initialize() {
93 this.setSize(916, 486);
94 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
95 this.setTitle("Update PCD Definitions");
96 this.setContentPane(getJContentPane());
97 this.centerWindow();
98 }
99 /**
100 Start the window at the center of screen
101
102 **/
103 protected void centerWindow(int intWidth, int intHeight) {
104 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
105 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
106 }
107
108 /**
109 Start the window at the center of screen
110
111 **/
112 protected void centerWindow() {
113 centerWindow(this.getSize().width, this.getSize().height);
114 }
115 /**
116 This method initializes jContentPane
117
118 @return javax.swing.JPanel
119 **/
120 private JPanel getJContentPane() {
121 if (jContentPane == null) {
122 jContentPane = new JPanel();
123 jContentPane.setLayout(null);
124 jContentPane.add(getJButtonOk(), null);
125 jContentPane.add(getJButtonCancel(), null);
126 jContentPane.add(getJScrollPane(), null);
127 jContentPane.add(getJButton(), null);
128 }
129 return jContentPane;
130 }
131
132 /**
133 Remove original Pcd definitions before saving updated ones
134 **/
135 protected void save() {
136 if (jTable.isEditing()) {
137 jTable.getCellEditor().stopCellEditing();
138 }
139 sfc.removeSpdPcdDefinition();
140 int rowCount = model.getRowCount();
141 int i = 0;
142 while (i < rowCount) {
143 String cName = null;
144 if (model.getValueAt(i, 1) != null) {
145 cName = model.getValueAt(i, 1).toString();
146 }
147 String token = null;
148 if (model.getValueAt(i, 2) != null) {
149 token = model.getValueAt(i, 2).toString();
150 }
151 String defaultVal = null;
152 if (model.getValueAt(i, 4) != null) {
153 defaultVal = model.getValueAt(i, 4).toString();
154 }
155 sfc.genSpdPcdDefinitions(model.getValueAt(i, 0).toString(), cName, token,
156 model.getValueAt(i, 3).toString(), null, null, null, null, null, null, defaultVal);
157 i++;
158 }
159 }
160
161 /**
162 This method initializes jButtonOk
163
164 @return javax.swing.JButton
165 **/
166 private JButton getJButtonOk() {
167 if (jButtonOk == null) {
168 jButtonOk = new JButton();
169 jButtonOk.setText("Ok");
170 jButtonOk.setSize(new java.awt.Dimension(84, 20));
171 jButtonOk.setLocation(new java.awt.Point(605, 404));
172 jButtonOk.addActionListener(this);
173 }
174 return jButtonOk;
175 }
176
177 /**
178 This method initializes jButtonCancel
179
180 @return javax.swing.JButton
181 **/
182 private JButton getJButtonCancel() {
183 if (jButtonCancel == null) {
184 jButtonCancel = new JButton();
185 jButtonCancel.setText("Cancel");
186 jButtonCancel.setSize(new java.awt.Dimension(82, 20));
187 jButtonCancel.setLocation(new java.awt.Point(712, 404));
188 jButtonCancel.addActionListener(this);
189 }
190 return jButtonCancel;
191 }
192
193 /**
194 This method initializes jScrollPane
195
196 @return javax.swing.JScrollPane
197 **/
198 private JScrollPane getJScrollPane() {
199 if (jScrollPane == null) {
200 jScrollPane = new JScrollPane();
201 jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
202 jScrollPane.setBounds(new java.awt.Rectangle(51, 62, 782, 304));
203 jScrollPane.setViewportView(getJTable2());
204 }
205 return jScrollPane;
206 }
207
208 /**
209 This method initializes jTable
210
211 @return javax.swing.JTable
212 **/
213 private JTable getJTable2() {
214 if (jTable == null) {
215 model = new DefaultTableModel();
216 jTable = new JTable(model);
217 jTable.setRowHeight(20);
218 model.addColumn("ItemType");
219 model.addColumn("C_Name");
220 model.addColumn("Token");
221 model.addColumn("DataType");
222 model.addColumn("DefaultValue");
223 //
224 // Using combobox to display ItemType in table
225 //
226 JComboBox jComboBoxItemType = new JComboBox();
227 jComboBoxItemType.addItem("FEATURE_FLAG");
228 jComboBoxItemType.addItem("FIXED_AT_BUILD");
229 jComboBoxItemType.addItem("PATCHABLE_IN_MODULE");
230 jComboBoxItemType.addItem("DYNAMIC");
231 jComboBoxItemType.addItem("DYNAMIC_EX");
232 TableColumn itemTypeColumn = jTable.getColumnModel().getColumn(0);
233 itemTypeColumn.setCellEditor(new DefaultCellEditor(jComboBoxItemType));
234 //
235 // Using combobox to display data type in table
236 //
237 JComboBox jComboBoxDataType = new JComboBox();
238 jComboBoxDataType.addItem("UINT8");
239 jComboBoxDataType.addItem("UINT16");
240 jComboBoxDataType.addItem("UINT32");
241 jComboBoxDataType.addItem("UINT64");
242 jComboBoxDataType.addItem("VOID*");
243 jComboBoxDataType.addItem("BOOLEAN");
244 TableColumn dataTypeColumn = jTable.getColumnModel().getColumn(3);
245 dataTypeColumn.setCellEditor(new DefaultCellEditor(jComboBoxDataType));
246
247 if (sfc.getSpdPcdDefinitionCount() == 0) {
248
249 return jTable;
250 }
251 saa = new String[sfc.getSpdPcdDefinitionCount()][5];
252 sfc.getSpdPcdDefinitions(saa);
253 int i = 0;
254 while (i < saa.length) {
255 model.addRow(saa[i]);
256 i++;
257 }
258
259 }
260 return jTable;
261 }
262
263 /**
264 This method initializes jButton
265
266 @return javax.swing.JButton
267 **/
268 private JButton getJButton() {
269 if (jButton == null) {
270 jButton = new JButton();
271 jButton.setBounds(new java.awt.Rectangle(499, 404, 77, 20));
272 jButton.setText("Insert");
273 jButton.addActionListener(this);
274 }
275 return jButton;
276 }
277 } // @jve:decl-index=0:visual-constraint="11,7"