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