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
.far
.FarStringDefinition
;
42 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
43 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
45 import javax
.swing
.JScrollPane
;
46 import javax
.swing
.JTable
;
47 import javax
.swing
.table
.DefaultTableModel
;
49 public class InstallStepOne
extends IDialog
implements MouseListener
{
54 private static final long serialVersionUID
= -8821906198791949544L;
56 private JPanel jContentPane
= null;
58 private JButton jButtonCancel
= null;
60 private JButton jButtonNext
= null;
62 private JTextArea jTextArea
= null;
64 private JLabel jLabel
= null;
66 private JTextField jTextFieldFarFile
= null;
68 private JButton jButtonBrowser
= null;
70 private InstallStepTwo stepTwo
= null;
74 private JLabel jLabelWarning
= null;
76 private JScrollPane jScrollPane
= null;
78 private JTable jTable
= null;
80 private PartialTableModel model
= null;
83 * This method initializes jButtonCancel
85 * @return javax.swing.JButton
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);
98 * This method initializes jButtonNext
100 * @return javax.swing.JButton
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);
113 * This method initializes jTextArea
115 * @return javax.swing.JTextArea
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);
128 * This method initializes jTextField
130 * @return javax.swing.JTextField
132 private JTextField
getJTextFieldFarFile() {
133 if (jTextFieldFarFile
== null) {
134 jTextFieldFarFile
= new JTextField();
135 jTextFieldFarFile
.setBounds(new java
.awt
.Rectangle(140, 80, 423, 20));
137 return jTextFieldFarFile
;
141 * This method initializes jButtonBrowser
143 * @return javax.swing.JButton
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);
152 return jButtonBrowser
;
156 * This method initializes jScrollPane
158 * @return javax.swing.JScrollPane
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());
166 jScrollPane
.setVisible(false);
171 * This method initializes jTable
173 * @return javax.swing.JTable
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");
186 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
188 jTable
.setVisible(false);
192 public void prepareTable(List
<PackageIdentification
> packageList
) {
193 model
.setRowCount(0);
195 // Change here to get packages and platforms from FAR
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();
209 * This is the default constructor
211 public InstallStepOne(IFrame iFrame
, boolean modal
) {
212 super(iFrame
, modal
);
217 * This method initializes this
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);
230 * This method initializes jContentPane
232 * @return javax.swing.JPanel
234 private JPanel
getJContentPane() {
235 if (jContentPane
== null) {
236 jLabelWarning
= new JLabel();
237 jLabelWarning
.setBounds(new java
.awt
.Rectangle(30, 125, 410, 20));
238 jLabelWarning
.setText("Can't install this FAR, lack following packages in current workspace");
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);
257 public void mouseClicked(MouseEvent e
) {
258 if (e
.getSource() == jButtonCancel
) {
259 this.setVisible(false);
260 } else if (e
.getSource() == jButtonNext
) {
262 // Add some logic process here
264 File farFile
= new File(jTextFieldFarFile
.getText());
265 if (!farFile
.exists() || !farFile
.isFile()) {
266 Log
.wrn("Install far", "Please choose a FAR file already exists. ");
275 jarFar
= new JarFile(farFile
);
276 far
= new Far(jarFar
);
279 // Far dependency check
281 List
<PackageIdentification
> pkgIdList
= DistributeRule
.installFarCheck(far
);
283 if (pkgIdList
.size() > 0) {
284 prepareTable(pkgIdList
);
285 jLabelWarning
.setVisible(true);
286 jTable
.setVisible(true);
287 jScrollPane
.setVisible(true);
291 } catch (Exception exp
) {
292 Log
.wrn("Install far" + exp
.getMessage());
293 Log
.err("Install far" + exp
.getMessage());
296 if (stepTwo
== null) {
297 stepTwo
= new InstallStepTwo(this, true, this);
299 this.setVisible(false);
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()));
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
));
324 public void mousePressed(MouseEvent e
) {
325 // TODO Auto-generated method stub
329 public void mouseReleased(MouseEvent e
) {
330 // TODO Auto-generated method stub
334 public void mouseEntered(MouseEvent e
) {
335 // TODO Auto-generated method stub
339 public void mouseExited(MouseEvent e
) {
340 // TODO Auto-generated method stub
344 public Far
getFar() {
350 class PartialTableModel
extends DefaultTableModel
{
354 private static final long serialVersionUID
= 1L;
356 public boolean isCellEditable(int row
, int col
) {