]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/far/updateui/UpdateStepOne.java
Enhance Installation, removing and creating FAR functionality.
[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, 100, 400, 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(542, 100, 97, 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(130, 164, 500, 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 }
183 return jListFarFromDb;
184 }
185
186 /**
187 * This is the default constructor
188 */
189 public UpdateStepOne(IFrame iFrame, boolean modal) {
190 super(iFrame, modal);
191 initialize();
192 }
193
194 /**
195 * This method initializes this
196 *
197 * @return void
198 */
199 private void initialize() {
200 this.setSize(700, 400);
201 this.setContentPane(getJContentPane());
202 this.setTitle("Update Framework Archive(FAR) - Step 1: Choose FAR File");
203 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
204 this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);
205 }
206
207 /**
208 * This method initializes jContentPane
209 *
210 * @return javax.swing.JPanel
211 */
212 private JPanel getJContentPane() {
213 if (jContentPane == null) {
214 jLabel1 = new JLabel();
215 jLabel1.setBounds(new java.awt.Rectangle(30, 138, 355, 18));
216 jLabel1.setText("Choose FAR from current framework database");
217 jLabel = new JLabel();
218 jLabel.setBounds(new java.awt.Rectangle(30, 80, 220, 20));
219 jLabel.setText("Choose FAR file: ");
220 jContentPane = new JPanel();
221 jContentPane.setLayout(null);
222 jContentPane.add(getJTextArea(), null);
223 jContentPane.add(getJButtonCancel(), null);
224 jContentPane.add(getJButtonNext(), null);
225 jContentPane.add(jLabel, null);
226 jContentPane.add(getJTextFieldFarFile(), null);
227 jContentPane.add(getJButtonBrowser(), null);
228 jContentPane.add(jLabel1, null);
229 jContentPane.add(getJScrollPane(), null);
230 }
231 return jContentPane;
232 }
233
234 public void mouseClicked(MouseEvent e) {
235 if (e.getSource() == jButtonCancel) {
236 this.setVisible(false);
237 }
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 //
260 // Add more logic process here
261 //
262 if (jListFarFromDb.getSelectedValue() == null) {
263 Log.err("Please choose a FAR from framework database. ");
264 return ;
265 }
266
267 if (stepTwo == null) {
268 stepTwo = new UpdateStepTwo(this, true, this);
269 }
270 this.setVisible(false);
271 stepTwo.prepareTable();
272 stepTwo.setVisible(true);
273 }
274 else if (e.getSource() == jButtonBrowser) {
275 JFileChooser fc = new JFileChooser();
276 fc.setAcceptAllFileFilterUsed(false);
277 fc.addChoosableFileFilter(new IFileFilter(DataType.FAR_SURFACE_AREA_EXT));
278 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
279
280 int result = fc.showSaveDialog(new JPanel());
281 if (result == JFileChooser.APPROVE_OPTION) {
282 this.jTextFieldFarFile.setText(Tools.addPathExt(fc.getSelectedFile().getPath(),
283 DataType.RETURN_TYPE_FAR_SURFACE_AREA));
284 }
285 }
286 }
287
288 public void mousePressed(MouseEvent e) {
289 // TODO Auto-generated method stub
290
291 }
292
293 public void mouseReleased(MouseEvent e) {
294 // TODO Auto-generated method stub
295
296 }
297
298 public void mouseEntered(MouseEvent e) {
299 // TODO Auto-generated method stub
300
301 }
302
303 public void mouseExited(MouseEvent e) {
304 // TODO Auto-generated method stub
305
306 }
307
308 public FarIdentification getSelecedDbFar() {
309 return (FarIdentification) jListFarFromDb.getSelectedValue();
310 }
311
312 public Far getFar() {
313 return far;
314 }
315 }