]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/far/installui/InstallStepOne.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / far / installui / InstallStepOne.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.installui;
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.List;
22 import java.util.jar.JarFile;
23 import java.util.Iterator;
24
25 import javax.swing.JFileChooser;
26 import javax.swing.JPanel;
27 import javax.swing.JButton;
28 import javax.swing.JTextArea;
29 import javax.swing.JLabel;
30 import javax.swing.JTextField;
31 import javax.swing.ListSelectionModel;
32
33 import org.tianocore.frameworkwizard.common.DataType;
34 import org.tianocore.frameworkwizard.common.IFileFilter;
35 import org.tianocore.frameworkwizard.common.Log;
36 import org.tianocore.frameworkwizard.common.Tools;
37 import org.tianocore.frameworkwizard.common.ui.IDialog;
38 import org.tianocore.frameworkwizard.common.ui.IFrame;
39 import org.tianocore.frameworkwizard.far.DistributeRule;
40 import org.tianocore.frameworkwizard.far.Far;
41 import org.tianocore.frameworkwizard.far.FarStringDefinition;
42 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
43 import org.tianocore.frameworkwizard.workspace.Workspace;
44
45 import javax.swing.JScrollPane;
46 import javax.swing.JTable;
47 import javax.swing.table.DefaultTableModel;
48
49 public class InstallStepOne extends IDialog implements MouseListener {
50
51 /**
52 *
53 */
54 private static final long serialVersionUID = -8821906198791949544L;
55
56 private JPanel jContentPane = null;
57
58 private JButton jButtonCancel = null;
59
60 private JButton jButtonNext = null;
61
62 private JTextArea jTextArea = null;
63
64 private JLabel jLabel = null;
65
66 private JTextField jTextFieldFarFile = null;
67
68 private JButton jButtonBrowser = null;
69
70 private InstallStepTwo stepTwo = null;
71
72 Far far = null;
73
74 private JLabel jLabelWarning = null;
75
76 private JScrollPane jScrollPane = null;
77
78 private JTable jTable = null;
79
80 private PartialTableModel model = null;
81
82 /**
83 * This method initializes jButtonCancel
84 *
85 * @return javax.swing.JButton
86 */
87 private JButton getJButtonCancel() {
88 if (jButtonCancel == null) {
89 jButtonCancel = new JButton();
90 jButtonCancel.setBounds(new java.awt.Rectangle(570, 330, 90, 20));
91 jButtonCancel.setText("Cancel");
92 jButtonCancel.addMouseListener(this);
93 }
94 return jButtonCancel;
95 }
96
97 /**
98 * This method initializes jButtonNext
99 *
100 * @return javax.swing.JButton
101 */
102 private JButton getJButtonNext() {
103 if (jButtonNext == null) {
104 jButtonNext = new JButton();
105 jButtonNext.setBounds(new java.awt.Rectangle(470, 330, 90, 20));
106 jButtonNext.setText("Next");
107 jButtonNext.addMouseListener(this);
108 }
109 return jButtonNext;
110 }
111
112 /**
113 * This method initializes jTextArea
114 *
115 * @return javax.swing.JTextArea
116 */
117 private JTextArea getJTextArea() {
118 if (jTextArea == null) {
119 jTextArea = new JTextArea();
120 jTextArea.setBounds(new java.awt.Rectangle(30, 7, 642, 50));
121 jTextArea.setText("Step 1: Choose a framework archive(FAR) file. \n");
122 jTextArea.setEditable(false);
123 }
124 return jTextArea;
125 }
126
127 /**
128 * This method initializes jTextField
129 *
130 * @return javax.swing.JTextField
131 */
132 private JTextField getJTextFieldFarFile() {
133 if (jTextFieldFarFile == null) {
134 jTextFieldFarFile = new JTextField();
135 jTextFieldFarFile.setBounds(new java.awt.Rectangle(140, 80, 423, 20));
136 }
137 return jTextFieldFarFile;
138 }
139
140 /**
141 * This method initializes jButtonBrowser
142 *
143 * @return javax.swing.JButton
144 */
145 private JButton getJButtonBrowser() {
146 if (jButtonBrowser == null) {
147 jButtonBrowser = new JButton();
148 jButtonBrowser.setBounds(new java.awt.Rectangle(570, 80, 100, 20));
149 jButtonBrowser.setText("Browser...");
150 jButtonBrowser.addMouseListener(this);
151 }
152 return jButtonBrowser;
153 }
154
155 /**
156 * This method initializes jScrollPane
157 *
158 * @return javax.swing.JScrollPane
159 */
160 private JScrollPane getJScrollPane() {
161 if (jScrollPane == null) {
162 jScrollPane = new JScrollPane();
163 jScrollPane.setBounds(new java.awt.Rectangle(30, 165, 642, 140));
164 jScrollPane.setViewportView(getJTable());
165 }
166 jScrollPane.setVisible(false);
167 return jScrollPane;
168 }
169
170 /**
171 * This method initializes jTable
172 *
173 * @return javax.swing.JTable
174 */
175 private JTable getJTable() {
176 if (jTable == null) {
177 jTable = new JTable();
178 model = new PartialTableModel();
179 jTable = new JTable(model);
180 jTable.setRowHeight(20);
181 jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
182 model.addColumn("Name");
183 model.addColumn("Version");
184 model.addColumn("GUID");
185
186 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
187 }
188 jTable.setVisible(false);
189 return jTable;
190 }
191
192 public void prepareTable(List<PackageIdentification> packageList) {
193 model.setRowCount(0);
194 //
195 // Change here to get packages and platforms from FAR
196 //
197 Iterator<PackageIdentification> iter = packageList.iterator();
198 while (iter.hasNext()) {
199 String[] str = new String[3];
200 PackageIdentification item = iter.next();
201 str[0] = item.getName();
202 str[1] = item.getVersion();
203 str[2] = item.getGuid();
204 model.addRow(str);
205 }
206 }
207
208 /**
209 * This is the default constructor
210 */
211 public InstallStepOne(IFrame iFrame, boolean modal) {
212 super(iFrame, modal);
213 initialize();
214 }
215
216 /**
217 * This method initializes this
218 *
219 * @return void
220 */
221 private void initialize() {
222 this.setSize(700, 400);
223 this.setContentPane(getJContentPane());
224 this.setTitle(FarStringDefinition.INSTALL_STEP_ONE_TITLE);
225 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
226 this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);
227 }
228
229 /**
230 * This method initializes jContentPane
231 *
232 * @return javax.swing.JPanel
233 */
234 private JPanel getJContentPane() {
235 if (jContentPane == null) {
236 jLabelWarning = new JLabel();
237 jLabelWarning.setBounds(new java.awt.Rectangle(30, 125, 510, 20));
238 jLabelWarning.setText("Cannot install this FAR, the WORKSPACE is missing the following required packages.");
239 jLabelWarning.setVisible(false);
240 jLabel = new JLabel();
241 jLabel.setBounds(new java.awt.Rectangle(30, 80, 97, 20));
242 jLabel.setText("Choose FAR file: ");
243 jContentPane = new JPanel();
244 jContentPane.setLayout(null);
245 jContentPane.add(getJButtonCancel(), null);
246 jContentPane.add(getJButtonNext(), null);
247 jContentPane.add(getJTextArea(), null);
248 jContentPane.add(jLabel, null);
249 jContentPane.add(getJTextFieldFarFile(), null);
250 jContentPane.add(getJButtonBrowser(), null);
251 jContentPane.add(jLabelWarning, null);
252 jContentPane.add(getJScrollPane(), null);
253 }
254 return jContentPane;
255 }
256
257 public void mouseClicked(MouseEvent e) {
258 if (e.getSource() == jButtonCancel) {
259 this.setVisible(false);
260 } else if (e.getSource() == jButtonNext) {
261 //
262 // Add some logic process here
263 //
264 File farFile = new File(jTextFieldFarFile.getText());
265 if (!farFile.exists() || !farFile.isFile()) {
266 Log.wrn("Install far", "Please choose an existing FAR file.");
267 return;
268 }
269
270 //
271 // Verify Far
272 //
273 JarFile jarFar;
274 try {
275 jarFar = new JarFile(farFile);
276 far = new Far(jarFar);
277
278 //
279 // Far dependency check
280 //
281 List<PackageIdentification> pkgIdList = DistributeRule.installFarCheck(far);
282
283 if (pkgIdList.size() > 0) {
284 prepareTable(pkgIdList);
285 jLabelWarning.setVisible(true);
286 jTable.setVisible(true);
287 jScrollPane.setVisible(true);
288 return;
289 }
290
291 } catch (Exception exp) {
292 Log.wrn("Install far" + exp.getMessage());
293 Log.err("Install far" + exp.getMessage());
294 }
295
296 if (stepTwo == null) {
297 stepTwo = new InstallStepTwo(this, true, this);
298 }
299 this.setVisible(false);
300
301 //
302 // Refresh table
303 //
304 stepTwo.preparePackageTable();
305 stepTwo.preparePlatformTable();
306 stepTwo.setVisible(true);
307 } else if (e.getSource() == jButtonBrowser) {
308 JFileChooser fc = new JFileChooser();
309 fc.setAcceptAllFileFilterUsed(false);
310 fc.addChoosableFileFilter(new IFileFilter(DataType.FAR_SURFACE_AREA_EXT));
311 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
312
313 int result = fc.showOpenDialog(new JPanel());
314 if (result == JFileChooser.APPROVE_OPTION) {
315 jLabelWarning.setVisible(false);
316 jTable.setVisible(false);
317 jScrollPane.setVisible(false);
318 this.jTextFieldFarFile.setText(Tools.addPathExt(fc.getSelectedFile().getPath(),
319 DataType.RETURN_TYPE_FAR_SURFACE_AREA));
320 }
321 }
322 }
323
324 public void mousePressed(MouseEvent e) {
325 // TODO Auto-generated method stub
326
327 }
328
329 public void mouseReleased(MouseEvent e) {
330 // TODO Auto-generated method stub
331
332 }
333
334 public void mouseEntered(MouseEvent e) {
335 // TODO Auto-generated method stub
336
337 }
338
339 public void mouseExited(MouseEvent e) {
340 // TODO Auto-generated method stub
341
342 }
343
344 public Far getFar() {
345 return far;
346 }
347
348 }
349
350 class PartialTableModel extends DefaultTableModel {
351 /**
352 *
353 */
354 private static final long serialVersionUID = 1L;
355
356 public boolean isCellEditable(int row, int col) {
357 switch (col) {
358 default:
359 return false;
360 }
361 }
362 }