]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/far/updateui/UpdateStepOne.java
1. Update release note to use jdk1.5.0_06 to take place of jdk1.5.0_04
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / far / updateui / UpdateStepOne.java
1 /** @file
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13
14 package org.tianocore.frameworkwizard.far.updateui;
15
16 import java.awt.Dimension;
17 import java.awt.Toolkit;
18 import java.awt.event.MouseEvent;
19 import java.awt.event.MouseListener;
20 import java.io.File;
21 import java.util.Vector;
22 import java.util.jar.JarFile;
23
24 import javax.swing.JFileChooser;
25 import javax.swing.JPanel;
26 import javax.swing.JTextArea;
27 import javax.swing.JButton;
28 import javax.swing.JLabel;
29 import javax.swing.JTextField;
30
31 import org.tianocore.frameworkwizard.common.DataType;
32 import org.tianocore.frameworkwizard.common.IFileFilter;
33 import org.tianocore.frameworkwizard.common.Log;
34 import org.tianocore.frameworkwizard.common.Tools;
35 import org.tianocore.frameworkwizard.common.ui.IDialog;
36 import org.tianocore.frameworkwizard.common.ui.IFrame;
37 import org.tianocore.frameworkwizard.far.Far;
38 import org.tianocore.frameworkwizard.far.FarIdentification;
39 import org.tianocore.frameworkwizard.workspace.Workspace;
40 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
41
42 import javax.swing.JScrollPane;
43 import javax.swing.JList;
44
45 public class UpdateStepOne extends IDialog implements MouseListener {
46
47 /**
48 *
49 */
50 private static final long serialVersionUID = 735554907464539931L;
51
52 private JPanel jContentPane = null;
53
54 private JTextArea jTextArea = null;
55
56 private JButton jButtonCancel = null;
57
58 private JButton jButtonNext = null;
59
60 private JLabel jLabel = null;
61
62 private JTextField jTextFieldFarFile = null;
63
64 private JButton jButtonBrowser = null;
65
66 private UpdateStepTwo stepTwo = null;
67
68 private Far far = null;
69
70 private Vector<FarIdentification> farVector = null;
71
72 private JLabel jLabel1 = null;
73
74 private JScrollPane jScrollPane = null;
75
76 private JList jListFarFromDb = null;
77
78 private File farFile = null;
79
80 public File getFarFile() {
81 return farFile;
82 }
83
84 /**
85 * This method initializes jTextArea
86 *
87 * @return javax.swing.JTextArea
88 */
89 private JTextArea getJTextArea() {
90 if (jTextArea == null) {
91 jTextArea = new JTextArea();
92 jTextArea.setBounds(new java.awt.Rectangle(30, 7, 642, 50));
93 jTextArea.setText("Step 1: Choose framework archive (FAR) file. \n");
94 jTextArea.setEditable(false);
95 }
96 return jTextArea;
97 }
98
99 /**
100 * This method initializes jButtonCancel
101 *
102 * @return javax.swing.JButton
103 */
104 private JButton getJButtonCancel() {
105 if (jButtonCancel == null) {
106 jButtonCancel = new JButton();
107 jButtonCancel.setBounds(new java.awt.Rectangle(570, 330, 90, 20));
108 jButtonCancel.setText("Cancel");
109 jButtonCancel.addMouseListener(this);
110 }
111 return jButtonCancel;
112 }
113
114 /**
115 * This method initializes jButtonNext
116 *
117 * @return javax.swing.JButton
118 */
119 private JButton getJButtonNext() {
120 if (jButtonNext == null) {
121 jButtonNext = new JButton();
122 jButtonNext.setBounds(new java.awt.Rectangle(470, 330, 90, 20));
123 jButtonNext.setText("Next");
124 jButtonNext.addMouseListener(this);
125 }
126 return jButtonNext;
127 }
128
129 /**
130 * This method initializes jTextField
131 *
132 * @return javax.swing.JTextField
133 */
134 private JTextField getJTextFieldFarFile() {
135 if (jTextFieldFarFile == null) {
136 jTextFieldFarFile = new JTextField();
137 jTextFieldFarFile.setBounds(new java.awt.Rectangle(130, 80, 436, 20));
138 }
139 return jTextFieldFarFile;
140 }
141
142 /**
143 * This method initializes jButton
144 *
145 * @return javax.swing.JButton
146 */
147 private JButton getJButtonBrowser() {
148 if (jButtonBrowser == null) {
149 jButtonBrowser = new JButton();
150 jButtonBrowser.setBounds(new java.awt.Rectangle(570, 80, 100, 20));
151 jButtonBrowser.setText("Browser...");
152 jButtonBrowser.addMouseListener(this);
153 }
154 return jButtonBrowser;
155 }
156
157 /**
158 * This method initializes jScrollPane
159 *
160 * @return javax.swing.JScrollPane
161 */
162 private JScrollPane getJScrollPane() {
163 if (jScrollPane == null) {
164 jScrollPane = new JScrollPane();
165 jScrollPane.setBounds(new java.awt.Rectangle(30, 135, 642, 160));
166 jScrollPane.setViewportView(getJListFarFromDb());
167 }
168 return jScrollPane;
169 }
170
171 /**
172 * This method initializes jListFarFromDb
173 *
174 * @return javax.swing.JList
175 */
176 private JList getJListFarFromDb() {
177 if (jListFarFromDb == null) {
178 jListFarFromDb = new JList();
179 WorkspaceTools wt = new WorkspaceTools();
180 farVector = wt.getAllFars();
181 jListFarFromDb.setListData(farVector);
182 jListFarFromDb.setSelectionMode(0);
183 }
184 return jListFarFromDb;
185 }
186
187 /**
188 * This is the default constructor
189 */
190 public UpdateStepOne(IFrame iFrame, boolean modal) {
191 super(iFrame, modal);
192 initialize();
193 }
194
195 /**
196 * This method initializes this
197 *
198 * @return void
199 */
200 private void initialize() {
201 this.setSize(700, 400);
202 this.setContentPane(getJContentPane());
203 this.setTitle("Update Framework Archive(FAR) - Step 1: Choose FAR File");
204 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
205 this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);
206 }
207
208 /**
209 * This method initializes jContentPane
210 *
211 * @return javax.swing.JPanel
212 */
213 private JPanel getJContentPane() {
214 if (jContentPane == null) {
215 jLabel1 = new JLabel();
216 jLabel1.setBounds(new java.awt.Rectangle(30, 110, 355, 18));
217 jLabel1.setText("Choose FAR from current framework database");
218 jLabel = new JLabel();
219 jLabel.setBounds(new java.awt.Rectangle(30, 80, 97, 20));
220 jLabel.setText("Choose FAR file: ");
221 jContentPane = new JPanel();
222 jContentPane.setLayout(null);
223 jContentPane.add(getJTextArea(), null);
224 jContentPane.add(getJButtonCancel(), null);
225 jContentPane.add(getJButtonNext(), null);
226 jContentPane.add(jLabel, null);
227 jContentPane.add(getJTextFieldFarFile(), null);
228 jContentPane.add(getJButtonBrowser(), null);
229 jContentPane.add(jLabel1, null);
230 jContentPane.add(getJScrollPane(), null);
231 }
232 return jContentPane;
233 }
234
235 public void mouseClicked(MouseEvent e) {
236 if (e.getSource() == jButtonCancel) {
237 this.setVisible(false);
238 } else if (e.getSource() == jButtonNext) {
239 //
240 // Judge if FAR file is existed
241 //
242 farFile = new File(jTextFieldFarFile.getText());
243 if (!farFile.exists() || !farFile.isFile()) {
244 Log.err("Please choose a FAR file already exists. ");
245 return;
246 }
247
248 //
249 // Judge FAR is valid
250 //
251 try {
252 JarFile file = new JarFile(farFile);
253 this.far = new Far(file);
254 } catch (Exception ex) {
255 Log.err(ex.getMessage());
256 }
257
258 //
259 // Add more logic process here
260 //
261 if (jListFarFromDb.getSelectedValue() == null) {
262 Log.err("Please choose a FAR from framework database. ");
263 return;
264 }
265
266 if (stepTwo == null) {
267 stepTwo = new UpdateStepTwo(this, true, this);
268 }
269 this.setVisible(false);
270 stepTwo.prepareTable();
271 stepTwo.setVisible(true);
272 } else if (e.getSource() == jButtonBrowser) {
273 JFileChooser fc = new JFileChooser();
274 fc.setAcceptAllFileFilterUsed(false);
275 fc.addChoosableFileFilter(new IFileFilter(DataType.FAR_SURFACE_AREA_EXT));
276 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
277
278 int result = fc.showSaveDialog(new JPanel());
279 if (result == JFileChooser.APPROVE_OPTION) {
280 this.jTextFieldFarFile.setText(Tools.addPathExt(fc.getSelectedFile().getPath(),
281 DataType.RETURN_TYPE_FAR_SURFACE_AREA));
282 }
283 }
284 }
285
286 public void mousePressed(MouseEvent e) {
287 // TODO Auto-generated method stub
288
289 }
290
291 public void mouseReleased(MouseEvent e) {
292 // TODO Auto-generated method stub
293
294 }
295
296 public void mouseEntered(MouseEvent e) {
297 // TODO Auto-generated method stub
298
299 }
300
301 public void mouseExited(MouseEvent e) {
302 // TODO Auto-generated method stub
303
304 }
305
306 public FarIdentification getSelecedDbFar() {
307 return (FarIdentification) jListFarFromDb.getSelectedValue();
308 }
309
310 public Far getFar() {
311 return far;
312 }
313 }