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