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