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