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