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
.createui
;
16 import java
.awt
.event
.MouseEvent
;
17 import java
.awt
.event
.MouseListener
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Iterator
;
21 import java
.util
.List
;
23 import javax
.swing
.JButton
;
24 import javax
.swing
.JFileChooser
;
25 import javax
.swing
.JLabel
;
26 import javax
.swing
.JPanel
;
27 import javax
.swing
.JTextArea
;
28 import javax
.swing
.JTextField
;
30 import org
.tianocore
.frameworkwizard
.common
.DataType
;
31 import org
.tianocore
.frameworkwizard
.common
.IDefaultTableModel
;
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
.far
.AggregationOperation
;
37 import org
.tianocore
.frameworkwizard
.far
.Far
;
38 import org
.tianocore
.frameworkwizard
.far
.PackageQuery
;
39 import org
.tianocore
.frameworkwizard
.far
.PackageQueryInterface
;
40 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
41 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
43 public class CreateStepFour
extends IDialog
implements MouseListener
{
48 private static final long serialVersionUID
= -7397213364965470902L;
50 private JPanel jContentPane
= null;
52 private JTextArea jTextAreaInstruction
= null;
54 private JLabel jLabel
= null;
56 private JLabel jLabel2
= null;
58 private JTextField jTextFieldSaveToFile
= null;
60 private JButton jButtonBrowser
= null;
62 // private JScrollPane jScrollPane = null;
63 private JButton jButtonCancel
= null;
65 private JButton jButtonFinish
= null;
67 private JButton jButtonPrevious
= null;
69 private IDefaultTableModel model
= null;
71 private CreateStepThree stepThree
= null;
73 // private JTable jTable = null;
74 public CreateStepFour(IDialog iDialog
, boolean modal
, CreateStepThree stepThree
) {
76 this.stepThree
= stepThree
;
80 * This method initializes jTextArea
82 * @return javax.swing.JTextArea
84 private JTextArea
getJTextArea() {
85 if (jTextAreaInstruction
== null) {
86 jTextAreaInstruction
= new JTextArea();
87 jTextAreaInstruction
.setBounds(new java
.awt
.Rectangle(30, 7, 642, 50));
88 jTextAreaInstruction
.setText("Step 4: Choose a file \n");
89 jTextAreaInstruction
.setEditable(false);
91 return jTextAreaInstruction
;
95 * This method initializes jTextField1
97 * @return javax.swing.JTextField
99 private JTextField
getJTextField1() {
100 if (jTextFieldSaveToFile
== null) {
101 jTextFieldSaveToFile
= new JTextField();
102 jTextFieldSaveToFile
.setBounds(new java
.awt
.Rectangle(147,70,412,20));
104 return jTextFieldSaveToFile
;
108 * This method initializes jButtonBrowser
110 * @return javax.swing.JButton
112 private JButton
getJButtonBrower() {
113 if (jButtonBrowser
== null) {
114 jButtonBrowser
= new JButton();
115 jButtonBrowser
.setBounds(new java
.awt
.Rectangle(570, 70, 100, 20));
116 jButtonBrowser
.setText("Browser...");
117 jButtonBrowser
.addMouseListener(this);
119 return jButtonBrowser
;
123 * This method initializes jScrollPane
125 * @return javax.swing.JScrollPane
127 // private JScrollPane getJScrollPane() {
128 // if (jScrollPane == null) {
129 // jScrollPane = new JScrollPane();
130 // jScrollPane.setBounds(new java.awt.Rectangle(139,85,500,100));
131 // jScrollPane.setViewportView(getJTable());
133 // return jScrollPane;
136 * This method initializes jButtonCancel
138 * @return javax.swing.JButton
140 private JButton
getJButtonCancel() {
141 if (jButtonCancel
== null) {
142 jButtonCancel
= new JButton();
143 jButtonCancel
.setBounds(new java
.awt
.Rectangle(570, 330, 90, 20));
144 jButtonCancel
.setText("Cancel");
145 jButtonCancel
.addMouseListener(this);
147 return jButtonCancel
;
151 * This method initializes jButtonFinish
153 * @return javax.swing.JButton
155 private JButton
getJButtonFinish() {
156 if (jButtonFinish
== null) {
157 jButtonFinish
= new JButton();
158 jButtonFinish
.setBounds(new java
.awt
.Rectangle(470, 330, 90, 20));
159 jButtonFinish
.setText("Finish");
160 jButtonFinish
.addMouseListener(this);
162 return jButtonFinish
;
166 * This method initializes jButtonPrevious
168 * @return javax.swing.JButton
170 private JButton
getJButtonPrevious() {
171 if (jButtonPrevious
== null) {
172 jButtonPrevious
= new JButton();
173 jButtonPrevious
.setBounds(new java
.awt
.Rectangle(370, 330, 90, 20));
174 jButtonPrevious
.setText("Previous");
175 jButtonPrevious
.addMouseListener(this);
176 jButtonPrevious
.setVisible(false);
178 return jButtonPrevious
;
182 * This is the default constructor
184 public CreateStepFour(IDialog iDialog
, boolean modal
) {
185 super(iDialog
, modal
);
190 * This method initializes this
194 private void initialize() {
195 this.setSize(700, 400);
196 this.setContentPane(getJContentPane());
197 this.setTitle("Create Framework Archive(FAR) - Step 4: Finish");
202 * This method initializes jContentPane
204 * @return javax.swing.JPanel
206 private JPanel
getJContentPane() {
207 if (jContentPane
== null) {
208 jLabel2
= new JLabel();
209 jLabel2
.setBounds(new java
.awt
.Rectangle(30,70,111,18));
210 jLabel2
.setText("Select File to Save: ");
211 jLabel
= new JLabel();
212 jLabel
.setBounds(new java
.awt
.Rectangle(29,108,320,20));
213 jLabel
.setText("This FAR will depend on following packages: ");
214 jLabel
.setVisible(false);
215 jContentPane
= new JPanel();
216 jContentPane
.setLayout(null);
217 jContentPane
.add(getJTextArea(), null);
218 jContentPane
.add(jLabel
, null);
219 // jContentPane.add(getJScrollPane(), null);
220 jContentPane
.add(getJButtonCancel(), null);
221 jContentPane
.add(getJButtonFinish(), null);
222 jContentPane
.add(getJButtonPrevious(), null);
223 jContentPane
.add(jLabel2
, null);
224 jContentPane
.add(getJTextField1(), null);
225 jContentPane
.add(getJButtonBrower(), null);
230 public void mouseClicked(MouseEvent e
) {
231 if (e
.getSource() == jButtonCancel
) {
232 this.setVisible(false);
233 } else if (e
.getSource() == jButtonFinish
) {
235 // Add some logic process here
236 // Guid Check, File Check etc.
238 if (this.jTextFieldSaveToFile
.getText() == null) {
239 Log
.err("Please input the Far name!");
243 // Create an output stream for JAR
246 Far far
= new Far(new File(this.jTextFieldSaveToFile
.getText()));
248 far
.creatFar(this.getPreviousStep().getPreviousStep().getSelectedPackages(),
249 this.getPreviousStep().getPreviousStep().getSelectedPlatforms(), this.getPreviousStep()
251 this.getPreviousStep().getPreviousStep().getPreviousStep().getFarHeader());
252 } catch (Exception exp
) {
253 Log
.err("Create error! ");
256 getPreviousStep().getPreviousStep().getPreviousStep().returnType
= DataType
.RETURN_TYPE_OK
;
257 getPreviousStep().getPreviousStep().dispose();
258 getPreviousStep().dispose();
259 this.setVisible(false);
261 } else if (e
.getSource() == jButtonPrevious
) {
262 stepThree
.setVisible(true);
263 this.setVisible(false);
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()));
270 int result
= fc
.showSaveDialog(new JPanel());
271 if (result
== JFileChooser
.APPROVE_OPTION
) {
272 this.jTextFieldSaveToFile
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(),
273 DataType
.RETURN_TYPE_FAR_SURFACE_AREA
));
278 public void mousePressed(MouseEvent e
) {
279 // TODO Auto-generated method stub
283 public void mouseReleased(MouseEvent e
) {
284 // TODO Auto-generated method stub
288 public void mouseEntered(MouseEvent e
) {
289 // TODO Auto-generated method stub
293 public void mouseExited(MouseEvent e
) {
294 // TODO Auto-generated method stub
298 public CreateStepThree
getPreviousStep() {
303 * This method initializes jTable
305 * @return javax.swing.JTable
307 // private JTable getJTable() {
308 // if (jTable == null) {
309 // jTable = new JTable();
310 // model = new PartialTableModel();
311 // jTable = new JTable(model);
312 // jTable.setRowHeight(20);
313 // jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
314 // model.addColumn("GUID");
315 // model.addColumn("Version");
316 // model.addColumn("Name");
318 // jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
320 // if (this.stepThree != null) {
325 public void prepareTable() {
326 model
.setRowCount(0);
328 List
<PackageIdentification
> packageList
= new ArrayList
<PackageIdentification
>();
330 // Change here to get packages and platforms from FAR
332 List
<PackageIdentification
> selectedPackages
= getPreviousStep().getPreviousStep().getSelectedPackages();
333 PackageQueryInterface pq
= new PackageQuery();
335 Iterator
<PackageIdentification
> iter
= selectedPackages
.iterator();
336 while (iter
.hasNext()) {
337 PackageIdentification item
= iter
.next();
338 List
<PackageIdentification
> list
= pq
.getPackageDependencies(item
.getSpdFile());
339 packageList
= AggregationOperation
.union(list
, packageList
);
342 packageList
= AggregationOperation
.minus(packageList
, selectedPackages
);
344 iter
= packageList
.iterator();
345 while (iter
.hasNext()) {
346 String
[] str
= new String
[3];
347 PackageIdentification item
= iter
.next();
348 str
[2] = item
.getName();
349 str
[1] = item
.getVersion();
350 str
[0] = item
.getGuid();