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
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.
14 package org
.tianocore
.frameworkwizard
.far
.installui
;
16 import java
.awt
.Dimension
;
17 import java
.awt
.Toolkit
;
18 import java
.awt
.event
.MouseEvent
;
19 import java
.awt
.event
.MouseListener
;
21 import java
.util
.List
;
22 import java
.util
.jar
.JarFile
;
23 import java
.util
.Iterator
;
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
;
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
.packaging
.PackageIdentification
;
42 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
44 import javax
.swing
.JScrollPane
;
45 import javax
.swing
.JTable
;
46 import javax
.swing
.table
.DefaultTableModel
;
48 public class InstallStepOne
extends IDialog
implements MouseListener
{
53 private static final long serialVersionUID
= -8821906198791949544L;
55 private JPanel jContentPane
= null;
57 private JButton jButtonCancel
= null;
59 private JButton jButtonNext
= null;
61 private JTextArea jTextArea
= null;
63 private JLabel jLabel
= null;
65 private JTextField jTextFieldFarFile
= null;
67 private JButton jButtonBrowser
= null;
69 private InstallStepTwo stepTwo
= null;
73 private JLabel jLabelWarning
= null;
75 private JScrollPane jScrollPane
= null;
77 private JTable jTable
= null;
79 private PartialTableModel model
= null;
82 * This method initializes jButtonCancel
84 * @return javax.swing.JButton
86 private JButton
getJButtonCancel() {
87 if (jButtonCancel
== null) {
88 jButtonCancel
= new JButton();
89 jButtonCancel
.setBounds(new java
.awt
.Rectangle(570, 330, 90, 20));
90 jButtonCancel
.setText("Cancel");
91 jButtonCancel
.addMouseListener(this);
97 * This method initializes jButtonNext
99 * @return javax.swing.JButton
101 private JButton
getJButtonNext() {
102 if (jButtonNext
== null) {
103 jButtonNext
= new JButton();
104 jButtonNext
.setBounds(new java
.awt
.Rectangle(470, 330, 90, 20));
105 jButtonNext
.setText("Next");
106 jButtonNext
.addMouseListener(this);
112 * This method initializes jTextArea
114 * @return javax.swing.JTextArea
116 private JTextArea
getJTextArea() {
117 if (jTextArea
== null) {
118 jTextArea
= new JTextArea();
119 jTextArea
.setBounds(new java
.awt
.Rectangle(30, 7, 642, 50));
120 jTextArea
.setText("Step 1: Choose a framework archive(FAR) file. \n");
121 jTextArea
.setEditable(false);
127 * This method initializes jTextField
129 * @return javax.swing.JTextField
131 private JTextField
getJTextFieldFarFile() {
132 if (jTextFieldFarFile
== null) {
133 jTextFieldFarFile
= new JTextField();
134 jTextFieldFarFile
.setBounds(new java
.awt
.Rectangle(140, 80, 423, 20));
136 return jTextFieldFarFile
;
140 * This method initializes jButtonBrowser
142 * @return javax.swing.JButton
144 private JButton
getJButtonBrowser() {
145 if (jButtonBrowser
== null) {
146 jButtonBrowser
= new JButton();
147 jButtonBrowser
.setBounds(new java
.awt
.Rectangle(570, 80, 100, 20));
148 jButtonBrowser
.setText("Browser...");
149 jButtonBrowser
.addMouseListener(this);
151 return jButtonBrowser
;
155 * This method initializes jScrollPane
157 * @return javax.swing.JScrollPane
159 private JScrollPane
getJScrollPane() {
160 if (jScrollPane
== null) {
161 jScrollPane
= new JScrollPane();
162 jScrollPane
.setBounds(new java
.awt
.Rectangle(30, 165, 642, 140));
163 jScrollPane
.setViewportView(getJTable());
165 jScrollPane
.setVisible(false);
170 * This method initializes jTable
172 * @return javax.swing.JTable
174 private JTable
getJTable() {
175 if (jTable
== null) {
176 jTable
= new JTable();
177 model
= new PartialTableModel();
178 jTable
= new JTable(model
);
179 jTable
.setRowHeight(20);
180 jTable
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_SUBSEQUENT_COLUMNS
);
181 model
.addColumn("Name");
182 model
.addColumn("Version");
183 model
.addColumn("GUID");
185 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
187 jTable
.setVisible(false);
191 public void prepareTable(List
<PackageIdentification
> packageList
) {
192 model
.setRowCount(0);
194 // Change here to get packages and platforms from FAR
196 Iterator
<PackageIdentification
> iter
= packageList
.iterator();
197 while (iter
.hasNext()) {
198 String
[] str
= new String
[3];
199 PackageIdentification item
= iter
.next();
200 str
[0] = item
.getName();
201 str
[1] = item
.getVersion();
202 str
[2] = item
.getGuid();
208 * This is the default constructor
210 public InstallStepOne(IFrame iFrame
, boolean modal
) {
211 super(iFrame
, modal
);
216 * This method initializes this
220 private void initialize() {
221 this.setSize(700, 400);
222 this.setContentPane(getJContentPane());
223 this.setTitle("Install Framework Archive(FAR) - Step 1: Choose FAR file");
224 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
225 this.setLocation((d
.width
- this.getSize().width
) / 2, (d
.height
- this.getSize().height
) / 2);
229 * This method initializes jContentPane
231 * @return javax.swing.JPanel
233 private JPanel
getJContentPane() {
234 if (jContentPane
== null) {
235 jLabelWarning
= new JLabel();
236 jLabelWarning
.setBounds(new java
.awt
.Rectangle(30, 125, 410, 20));
237 jLabelWarning
.setText("Can't install this FAR, lack following packages in current workspace");
238 jLabelWarning
.setVisible(false);
239 jLabel
= new JLabel();
240 jLabel
.setBounds(new java
.awt
.Rectangle(30, 80, 97, 20));
241 jLabel
.setText("Choose FAR file: ");
242 jContentPane
= new JPanel();
243 jContentPane
.setLayout(null);
244 jContentPane
.add(getJButtonCancel(), null);
245 jContentPane
.add(getJButtonNext(), null);
246 jContentPane
.add(getJTextArea(), null);
247 jContentPane
.add(jLabel
, null);
248 jContentPane
.add(getJTextFieldFarFile(), null);
249 jContentPane
.add(getJButtonBrowser(), null);
250 jContentPane
.add(jLabelWarning
, null);
251 jContentPane
.add(getJScrollPane(), null);
256 public void mouseClicked(MouseEvent e
) {
257 if (e
.getSource() == jButtonCancel
) {
258 this.setVisible(false);
259 } else if (e
.getSource() == jButtonNext
) {
261 // Add some logic process here
263 File farFile
= new File(jTextFieldFarFile
.getText());
264 if (!farFile
.exists() || !farFile
.isFile()) {
265 Log
.err("Please choose a FAR file already exists. ");
274 jarFar
= new JarFile(farFile
);
275 far
= new Far(jarFar
);
278 // Far dependency check
280 List
<PackageIdentification
> pkgIdList
= DistributeRule
.installFarCheck(far
);
282 if (pkgIdList
.size() > 0) {
283 prepareTable(pkgIdList
);
284 jLabelWarning
.setVisible(true);
285 jTable
.setVisible(true);
286 jScrollPane
.setVisible(true);
290 } catch (Exception exp
) {
291 exp
.printStackTrace();
292 Log
.err("Far file invaild! The error message as follow:" + exp
.getMessage());
295 if (stepTwo
== null) {
296 stepTwo
= new InstallStepTwo(this, true, this);
298 this.setVisible(false);
303 stepTwo
.preparePackageTable();
304 stepTwo
.preparePlatformTable();
305 stepTwo
.setVisible(true);
306 } else if (e
.getSource() == jButtonBrowser
) {
307 JFileChooser fc
= new JFileChooser();
308 fc
.setAcceptAllFileFilterUsed(false);
309 fc
.addChoosableFileFilter(new IFileFilter(DataType
.FAR_SURFACE_AREA_EXT
));
310 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
312 int result
= fc
.showSaveDialog(new JPanel());
313 if (result
== JFileChooser
.APPROVE_OPTION
) {
314 jLabelWarning
.setVisible(false);
315 jTable
.setVisible(false);
316 jScrollPane
.setVisible(false);
317 this.jTextFieldFarFile
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(),
318 DataType
.RETURN_TYPE_FAR_SURFACE_AREA
));
323 public void mousePressed(MouseEvent e
) {
324 // TODO Auto-generated method stub
328 public void mouseReleased(MouseEvent e
) {
329 // TODO Auto-generated method stub
333 public void mouseEntered(MouseEvent e
) {
334 // TODO Auto-generated method stub
338 public void mouseExited(MouseEvent e
) {
339 // TODO Auto-generated method stub
343 public Far
getFar() {
349 class PartialTableModel
extends DefaultTableModel
{
353 private static final long serialVersionUID
= 1L;
355 public boolean isCellEditable(int row
, int col
) {