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