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