Fixed grammar in text messages.
[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.far.FarStringDefinition;
40 import org.tianocore.frameworkwizard.workspace.Workspace;
41 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
42
43 import javax.swing.JScrollPane;
44 import javax.swing.JList;
45
46 public class UpdateStepOne extends IDialog implements MouseListener {
47
48 /**
49 *
50 */
51 private static final long serialVersionUID = 735554907464539931L;
52
53 private JPanel jContentPane = null;
54
55 private JTextArea jTextArea = null;
56
57 private JButton jButtonCancel = null;
58
59 private JButton jButtonNext = null;
60
61 private JLabel jLabel = null;
62
63 private JTextField jTextFieldFarFile = null;
64
65 private JButton jButtonBrowser = null;
66
67 private UpdateStepTwo stepTwo = null;
68
69 private Far far = null;
70
71 private Vector<FarIdentification> farVector = null;
72
73 private JLabel jLabel1 = null;
74
75 private JScrollPane jScrollPane = null;
76
77 private JList jListFarFromDb = null;
78
79 private File farFile = null;
80
81 public File getFarFile() {
82 return farFile;
83 }
84
85 /**
86 * This method initializes jTextArea
87 *
88 * @return javax.swing.JTextArea
89 */
90 private JTextArea getJTextArea() {
91 if (jTextArea == null) {
92 jTextArea = new JTextArea();
93 jTextArea.setBounds(new java.awt.Rectangle(30, 7, 642, 50));
94 jTextArea.setText("Step 1: Choose framework archive (FAR) file. \n");
95 jTextArea.setEditable(false);
96 }
97 return jTextArea;
98 }
99
100 /**
101 * This method initializes jButtonCancel
102 *
103 * @return javax.swing.JButton
104 */
105 private JButton getJButtonCancel() {
106 if (jButtonCancel == null) {
107 jButtonCancel = new JButton();
108 jButtonCancel.setBounds(new java.awt.Rectangle(570, 330, 90, 20));
109 jButtonCancel.setText("Cancel");
110 jButtonCancel.addMouseListener(this);
111 }
112 return jButtonCancel;
113 }
114
115 /**
116 * This method initializes jButtonNext
117 *
118 * @return javax.swing.JButton
119 */
120 private JButton getJButtonNext() {
121 if (jButtonNext == null) {
122 jButtonNext = new JButton();
123 jButtonNext.setBounds(new java.awt.Rectangle(470, 330, 90, 20));
124 jButtonNext.setText("Next");
125 jButtonNext.addMouseListener(this);
126 }
127 return jButtonNext;
128 }
129
130 /**
131 * This method initializes jTextField
132 *
133 * @return javax.swing.JTextField
134 */
135 private JTextField getJTextFieldFarFile() {
136 if (jTextFieldFarFile == null) {
137 jTextFieldFarFile = new JTextField();
138 jTextFieldFarFile.setBounds(new java.awt.Rectangle(130, 80, 436, 20));
139 }
140 return jTextFieldFarFile;
141 }
142
143 /**
144 * This method initializes jButton
145 *
146 * @return javax.swing.JButton
147 */
148 private JButton getJButtonBrowser() {
149 if (jButtonBrowser == null) {
150 jButtonBrowser = new JButton();
151 jButtonBrowser.setBounds(new java.awt.Rectangle(570, 80, 100, 20));
152 jButtonBrowser.setText("Browser...");
153 jButtonBrowser.addMouseListener(this);
154 }
155 return jButtonBrowser;
156 }
157
158 /**
159 * This method initializes jScrollPane
160 *
161 * @return javax.swing.JScrollPane
162 */
163 private JScrollPane getJScrollPane() {
164 if (jScrollPane == null) {
165 jScrollPane = new JScrollPane();
166 jScrollPane.setBounds(new java.awt.Rectangle(30, 135, 642, 160));
167 jScrollPane.setViewportView(getJListFarFromDb());
168 }
169 return jScrollPane;
170 }
171
172 /**
173 * This method initializes jListFarFromDb
174 *
175 * @return javax.swing.JList
176 */
177 private JList getJListFarFromDb() {
178 if (jListFarFromDb == null) {
179 jListFarFromDb = new JList();
180 WorkspaceTools wt = new WorkspaceTools();
181 farVector = wt.getAllFars();
182 jListFarFromDb.setListData(farVector);
183 jListFarFromDb.setSelectionMode(0);
184 }
185 return jListFarFromDb;
186 }
187
188 /**
189 * This is the default constructor
190 */
191 public UpdateStepOne(IFrame iFrame, boolean modal) {
192 super(iFrame, modal);
193 initialize();
194 }
195
196 /**
197 * This method initializes this
198 *
199 * @return void
200 */
201 private void initialize() {
202 this.setSize(700, 400);
203 this.setContentPane(getJContentPane());
204 this.setTitle(FarStringDefinition.UPDATE_STEP_ONE_TITLE);
205 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
206 this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);
207 }
208
209 /**
210 * This method initializes jContentPane
211 *
212 * @return javax.swing.JPanel
213 */
214 private JPanel getJContentPane() {
215 if (jContentPane == null) {
216 jLabel1 = new JLabel();
217 jLabel1.setBounds(new java.awt.Rectangle(30, 110, 355, 18));
218 jLabel1.setText("Choose FAR from current WORKSPACE.");
219 jLabel = new JLabel();
220 jLabel.setBounds(new java.awt.Rectangle(30, 80, 97, 20));
221 jLabel.setText("Choose FAR file: ");
222 jContentPane = new JPanel();
223 jContentPane.setLayout(null);
224 jContentPane.add(getJTextArea(), null);
225 jContentPane.add(getJButtonCancel(), null);
226 jContentPane.add(getJButtonNext(), null);
227 jContentPane.add(jLabel, null);
228 jContentPane.add(getJTextFieldFarFile(), null);
229 jContentPane.add(getJButtonBrowser(), null);
230 jContentPane.add(jLabel1, null);
231 jContentPane.add(getJScrollPane(), null);
232 }
233 return jContentPane;
234 }
235
236 public void mouseClicked(MouseEvent e) {
237 if (e.getSource() == jButtonCancel) {
238 this.setVisible(false);
239 } else if (e.getSource() == jButtonNext) {
240 //
241 // Judge if FAR file is existed
242 //
243 farFile = new File(jTextFieldFarFile.getText());
244 if (!farFile.exists() || !farFile.isFile()) {
245 Log.wrn("Update far", "Please choose a FAR file that already exists.");
246 return;
247 }
248
249 //
250 // Judge FAR is valid
251 //
252 try {
253 JarFile file = new JarFile(farFile);
254 this.far = new Far(file);
255 } catch (Exception ex) {
256 Log.wrn("Update far", ex.getMessage());
257 Log.err("Update far", ex.getMessage());
258 }
259
260 //
261 // Add more logic process here
262 //
263 if (jListFarFromDb.getSelectedValue() == null) {
264 Log.wrn("Update far", "Please choose a FAR from current WORKSPACE.");
265 return;
266 }
267
268 if (stepTwo == null) {
269 stepTwo = new UpdateStepTwo(this, true, this);
270 }
271 this.setVisible(false);
272 stepTwo.prepareTable();
273 stepTwo.setVisible(true);
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.showOpenDialog(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 }