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
.updateui
;
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
.ArrayList
;
22 import java
.util
.Iterator
;
23 import java
.util
.LinkedHashSet
;
24 import java
.util
.List
;
26 import java
.util
.Vector
;
28 import javax
.swing
.JPanel
;
29 import javax
.swing
.JTextArea
;
30 import javax
.swing
.JButton
;
31 import javax
.swing
.JScrollPane
;
32 import javax
.swing
.JLabel
;
33 import javax
.swing
.JTable
;
34 import javax
.swing
.ListSelectionModel
;
35 import javax
.swing
.table
.DefaultTableModel
;
37 import org
.tianocore
.frameworkwizard
.common
.Log
;
38 import org
.tianocore
.frameworkwizard
.common
.Tools
;
39 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
40 import org
.tianocore
.frameworkwizard
.far
.AggregationOperation
;
41 import org
.tianocore
.frameworkwizard
.far
.DistributeRule
;
42 import org
.tianocore
.frameworkwizard
.far
.Far
;
43 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
44 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
45 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
46 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
48 public class UpdateStepTwo
extends IDialog
implements MouseListener
{
53 private static final long serialVersionUID
= -4400145363721213110L;
55 private JPanel jContentPane
= null;
57 private JTextArea jTextArea
= null;
59 private UpdateStepOne stepOne
= null;
61 private JButton jButtonCancel
= null;
63 private JButton jButtonFinish
= null;
65 private JButton jButtonPrevious
= null;
67 private JScrollPane jScrollPane
= null;
69 private JLabel jLabel
= null;
71 private JTable jTablePackage
= null;
73 private PartialTableModel model
= null;
74 List
<PackageIdentification
> updatPkgList
= new ArrayList
<PackageIdentification
>();
76 public UpdateStepTwo(IDialog iDialog
, boolean modal
, UpdateStepOne stepOne
) {
78 this.stepOne
= stepOne
;
82 * This method initializes jTextArea
84 * @return javax.swing.JTextArea
86 private JTextArea
getJTextArea() {
87 if (jTextArea
== null) {
88 jTextArea
= new JTextArea();
89 jTextArea
.setBounds(new java
.awt
.Rectangle(30, 7, 642, 50));
90 jTextArea
.setText("Step 2: Summary. \n");
91 jTextArea
.setEditable(false);
97 * This method initializes jButtonCancel
99 * @return javax.swing.JButton
101 private JButton
getJButtonCancel() {
102 if (jButtonCancel
== null) {
103 jButtonCancel
= new JButton();
104 jButtonCancel
.setBounds(new java
.awt
.Rectangle(570, 330, 90, 20));
105 jButtonCancel
.setText("Cancel");
106 jButtonCancel
.addMouseListener(this);
108 return jButtonCancel
;
112 * This method initializes jButtonFinish
114 * @return javax.swing.JButton
116 private JButton
getJButtonFinish() {
117 if (jButtonFinish
== null) {
118 jButtonFinish
= new JButton();
119 jButtonFinish
.setBounds(new java
.awt
.Rectangle(470, 330, 90, 20));
120 jButtonFinish
.setText("Finish");
121 jButtonFinish
.addMouseListener(this);
123 return jButtonFinish
;
127 * This method initializes jButtonPrevious
129 * @return javax.swing.JButton
131 private JButton
getJButtonPrevious() {
132 if (jButtonPrevious
== null) {
133 jButtonPrevious
= new JButton();
134 jButtonPrevious
.setBounds(new java
.awt
.Rectangle(370, 330, 90, 20));
135 jButtonPrevious
.setText("Previous");
136 jButtonPrevious
.addMouseListener(this);
138 return jButtonPrevious
;
142 * This method initializes jScrollPane
144 * @return javax.swing.JScrollPane
146 private JScrollPane
getJScrollPane() {
147 if (jScrollPane
== null) {
148 jScrollPane
= new JScrollPane();
149 jScrollPane
.setBounds(new java
.awt
.Rectangle(30, 98, 570, 170));
150 jScrollPane
.setViewportView(getJTablePackage());
156 * This method initializes jTablePackage
158 * @return javax.swing.JTable
160 private JTable
getJTablePackage() {
161 if (jTablePackage
== null) {
162 jTablePackage
= new JTable();
163 model
= new PartialTableModel();
164 jTablePackage
= new JTable(model
);
165 jTablePackage
.setRowHeight(20);
166 jTablePackage
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_SUBSEQUENT_COLUMNS
);
167 model
.addColumn("Name");
168 model
.addColumn("Version");
169 model
.addColumn("Guid");
170 model
.addColumn("Path");
172 jTablePackage
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
174 return jTablePackage
;
177 public void prepareTable() {
178 model
.setRowCount(0);
180 Far far
= stepOne
.getFar();
181 List
<PackageIdentification
> packagesInFar
= far
.mainfest
.getPackageList();
183 WorkspaceTools wt
= new WorkspaceTools();
184 List
<PackageIdentification
> packagesInDb
= wt
.getAllPackages();
186 updatPkgList
= AggregationOperation
.intersection(packagesInDb
, packagesInFar
);
188 // Change here to get packages and platforms from FAR
190 Iterator
<PackageIdentification
> iter
= updatPkgList
.iterator() ;//packageList.iterator();
191 while (iter
.hasNext()) {
192 String
[] str
= new String
[4];
193 PackageIdentification item
= iter
.next();
194 str
[0] = item
.getName();
195 str
[1] = item
.getVersion();
196 str
[2] = item
.getGuid();
197 str
[3] = Tools
.getFilePathOnly(Tools
.getRelativePath(item
.getPath(), Workspace
.getCurrentWorkspace()));
201 catch (Exception ex
) {
202 ex
.printStackTrace();
207 * This is the default constructor
209 public UpdateStepTwo(IDialog iDialog
, boolean modal
) {
210 super(iDialog
, modal
);
215 * This method initializes this
219 private void initialize() {
220 this.setSize(700, 400);
221 this.setContentPane(getJContentPane());
222 this.setTitle("Update Framework Archive(FAR) - Step 2: Summary");
223 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
224 this.setLocation((d
.width
- this.getSize().width
) / 2, (d
.height
- this.getSize().height
) / 2);
228 * This method initializes jContentPane
230 * @return javax.swing.JPanel
232 private JPanel
getJContentPane() {
233 if (jContentPane
== null) {
234 jLabel
= new JLabel();
235 jLabel
.setBounds(new java
.awt
.Rectangle(30,70,281,20));
236 jLabel
.setText("Following packages will be updated: ");
237 jContentPane
= new JPanel();
238 jContentPane
.setLayout(null);
239 jContentPane
.add(getJTextArea(), null);
240 jContentPane
.add(getJButtonCancel(), null);
241 jContentPane
.add(getJButtonFinish(), null);
242 jContentPane
.add(getJButtonPrevious(), null);
243 jContentPane
.add(getJScrollPane(), null);
244 jContentPane
.add(jLabel
, null);
248 public void mouseClicked(MouseEvent e
) {
249 if (e
.getSource() == jButtonCancel
) {
250 this.setVisible(false);
252 else if (e
.getSource() == jButtonFinish
) {
256 WorkspaceTools wsTools
= new WorkspaceTools();
258 Iterator
<PackageIdentification
> iter
= updatPkgList
.iterator();
259 List
<PackageIdentification
> depResultList
= new ArrayList
<PackageIdentification
>();
260 while (iter
.hasNext()){
261 List
<PackageIdentification
> depPkgList
= stepOne
.getFar().getPackageDependencies(iter
.next());
262 depResultList
= AggregationOperation
.union(depResultList
, depPkgList
);
265 List
<PackageIdentification
> dbPkgList
= DistributeRule
.vectorToList(wsTools
.getAllPackages());
266 List
<PackageIdentification
> resultList
= AggregationOperation
.minus(depResultList
, AggregationOperation
.union(
267 this.updatPkgList
, dbPkgList
));
268 Iterator resultIter
= resultList
.iterator();
269 while (resultIter
.hasNext()){
270 Log
.err("Missing dependency package " + ((PackageIdentification
)resultIter
.next()).toString() + "in workspace!");
275 // Remove all update packages
278 // For all packages, remove all files.
279 // Exception FPD file still in DB
281 Vector
<PlatformIdentification
> allPlatforms
= wsTools
.getAllPlatforms();
282 Set
<File
> allPlatformFiles
= new LinkedHashSet
<File
>();
284 Iterator
<PlatformIdentification
> allPlfIter
= allPlatforms
.iterator();
285 while (iter
.hasNext()) {
286 allPlatformFiles
.add(allPlfIter
.next().getFpdFile());
289 Iterator
<PackageIdentification
> packageIter
= this.updatPkgList
.iterator();
290 while (packageIter
.hasNext()) {
291 PackageIdentification item
= packageIter
.next();
292 Set
<File
> deleteFiles
= new LinkedHashSet
<File
>();
293 recursiveDir(deleteFiles
, item
.getSpdFile().getParentFile(), allPlatformFiles
);
294 Iterator
<File
> iterDeleteFile
= deleteFiles
.iterator();
295 while (iterDeleteFile
.hasNext()){
296 deleteFiles(iterDeleteFile
.next());
299 // Remove all empty parent dir
301 File parentDir
= item
.getSpdFile().getParentFile();
302 while (parentDir
.listFiles().length
== 0) {
303 File tempFile
= parentDir
;
304 parentDir
= parentDir
.getParentFile();
310 // Install all update packages
312 Iterator
<PackageIdentification
> updataIter
= this.updatPkgList
.iterator();
313 while (updataIter
.hasNext()){
314 PackageIdentification pkgId
= updataIter
.next();
316 stepOne
.getFar().installPackage(pkgId
, pkgId
.getSpdFile());
317 }catch (Exception ex
){
318 Log
.err("Can install " + pkgId
.toString() + " pakcage, please check it!");
324 this.setVisible(false);
326 else if (e
.getSource() == jButtonPrevious
) {
327 this.setVisible(false);
328 stepOne
.setVisible(true);
331 public void mousePressed(MouseEvent e
) {
332 // TODO Auto-generated method stub
335 public void mouseReleased(MouseEvent e
) {
336 // TODO Auto-generated method stub
339 public void mouseEntered(MouseEvent e
) {
340 // TODO Auto-generated method stub
343 public void mouseExited(MouseEvent e
) {
344 // TODO Auto-generated method stub
348 private void recursiveDir(Set
<File
> files
, File dir
, Set
<File
> platformFiles
) {
349 File
[] fileList
= dir
.listFiles();
350 for (int i
= 0; i
< fileList
.length
; i
++) {
351 if (fileList
[i
].isFile()) {
352 if( ! platformFiles
.contains(fileList
[i
])) {
353 files
.add(fileList
[i
]);
357 if (isContain(fileList
[i
], platformFiles
)) {
358 recursiveDir(files
, fileList
[i
], platformFiles
);
361 files
.add(fileList
[i
]);
367 private void deleteFiles(File file
) {
368 if (file
.isDirectory()) {
369 File
[] files
= file
.listFiles();
370 for (int i
= 0; i
< files
.length
; i
++) {
371 deleteFiles(files
[i
]);
377 private boolean isContain(File dir
, Set
<File
> platformFiles
) {
378 Iterator
<File
> iter
= platformFiles
.iterator();
379 while (iter
.hasNext()) {
380 File file
= iter
.next();
381 if (file
.getPath().startsWith(dir
.getPath())) {
383 // continue this FPD file
393 class PartialTableModel
extends DefaultTableModel
{
397 private static final long serialVersionUID
= 1L;
399 public boolean isCellEditable(int row
, int col
) {