]>
Commit | Line | Data |
---|---|---|
5a24e806 | 1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | **/\r | |
13 | \r | |
14 | package org.tianocore.frameworkwizard.far.updateui;\r | |
15 | \r | |
16 | import java.awt.Dimension;\r | |
17 | import java.awt.Toolkit;\r | |
18 | import java.awt.event.MouseEvent;\r | |
19 | import java.awt.event.MouseListener;\r | |
1898a0c3 | 20 | import java.io.File;\r |
21 | import java.util.ArrayList;\r | |
5a24e806 | 22 | import java.util.Iterator;\r |
1898a0c3 | 23 | import java.util.LinkedHashSet;\r |
5a24e806 | 24 | import java.util.List;\r |
1898a0c3 | 25 | import java.util.Set;\r |
26 | import java.util.Vector;\r | |
5a24e806 | 27 | \r |
28 | import javax.swing.JPanel;\r | |
29 | import javax.swing.JTextArea;\r | |
30 | import javax.swing.JButton;\r | |
31 | import javax.swing.JScrollPane;\r | |
32 | import javax.swing.JLabel;\r | |
33 | import javax.swing.JTable;\r | |
34 | import javax.swing.ListSelectionModel;\r | |
35 | import javax.swing.table.DefaultTableModel;\r | |
36 | \r | |
1898a0c3 | 37 | import org.tianocore.frameworkwizard.common.Log;\r |
5a24e806 | 38 | import org.tianocore.frameworkwizard.common.Tools;\r |
39 | import org.tianocore.frameworkwizard.common.ui.IDialog;\r | |
40 | import org.tianocore.frameworkwizard.far.AggregationOperation;\r | |
1898a0c3 | 41 | import org.tianocore.frameworkwizard.far.DistributeRule;\r |
5a24e806 | 42 | import org.tianocore.frameworkwizard.far.Far;\r |
43 | import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r | |
1898a0c3 | 44 | import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r |
5a24e806 | 45 | import org.tianocore.frameworkwizard.workspace.Workspace;\r |
46 | import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r | |
47 | \r | |
48 | public class UpdateStepTwo extends IDialog implements MouseListener {\r | |
49 | \r | |
50 | /**\r | |
51 | * \r | |
52 | */\r | |
53 | private static final long serialVersionUID = -4400145363721213110L;\r | |
54 | \r | |
55 | private JPanel jContentPane = null;\r | |
56 | \r | |
57 | private JTextArea jTextArea = null;\r | |
58 | \r | |
59 | private UpdateStepOne stepOne = null;\r | |
60 | \r | |
61 | private JButton jButtonCancel = null;\r | |
62 | \r | |
63 | private JButton jButtonFinish = null;\r | |
64 | \r | |
65 | private JButton jButtonPrevious = null;\r | |
66 | \r | |
67 | private JScrollPane jScrollPane = null;\r | |
68 | \r | |
69 | private JLabel jLabel = null;\r | |
70 | \r | |
71 | private JTable jTablePackage = null;\r | |
72 | \r | |
73 | private PartialTableModel model = null;\r | |
1898a0c3 | 74 | List<PackageIdentification> updatPkgList = new ArrayList<PackageIdentification>();\r |
5a24e806 | 75 | \r |
76 | public UpdateStepTwo(IDialog iDialog, boolean modal, UpdateStepOne stepOne) {\r | |
77 | this(iDialog, modal);\r | |
78 | this.stepOne = stepOne;\r | |
79 | }\r | |
80 | \r | |
81 | /**\r | |
82 | * This method initializes jTextArea \r | |
83 | * \r | |
84 | * @return javax.swing.JTextArea \r | |
85 | */\r | |
86 | private JTextArea getJTextArea() {\r | |
87 | if (jTextArea == null) {\r | |
88 | jTextArea = new JTextArea();\r | |
89 | jTextArea.setBounds(new java.awt.Rectangle(30, 7, 642, 50));\r | |
90 | jTextArea.setText("Step 2: Summary. \n");\r | |
91 | jTextArea.setEditable(false);\r | |
92 | }\r | |
93 | return jTextArea;\r | |
94 | }\r | |
95 | \r | |
96 | /**\r | |
97 | * This method initializes jButtonCancel \r | |
98 | * \r | |
99 | * @return javax.swing.JButton \r | |
100 | */\r | |
101 | private JButton getJButtonCancel() {\r | |
102 | if (jButtonCancel == null) {\r | |
103 | jButtonCancel = new JButton();\r | |
104 | jButtonCancel.setBounds(new java.awt.Rectangle(570, 330, 90, 20));\r | |
105 | jButtonCancel.setText("Cancel");\r | |
106 | jButtonCancel.addMouseListener(this);\r | |
107 | }\r | |
108 | return jButtonCancel;\r | |
109 | }\r | |
110 | \r | |
111 | /**\r | |
112 | * This method initializes jButtonFinish \r | |
113 | * \r | |
114 | * @return javax.swing.JButton \r | |
115 | */\r | |
116 | private JButton getJButtonFinish() {\r | |
117 | if (jButtonFinish == null) {\r | |
118 | jButtonFinish = new JButton();\r | |
119 | jButtonFinish.setBounds(new java.awt.Rectangle(470, 330, 90, 20));\r | |
120 | jButtonFinish.setText("Finish");\r | |
121 | jButtonFinish.addMouseListener(this);\r | |
122 | }\r | |
123 | return jButtonFinish;\r | |
124 | }\r | |
125 | \r | |
126 | /**\r | |
127 | * This method initializes jButtonPrevious \r | |
128 | * \r | |
129 | * @return javax.swing.JButton \r | |
130 | */\r | |
131 | private JButton getJButtonPrevious() {\r | |
132 | if (jButtonPrevious == null) {\r | |
133 | jButtonPrevious = new JButton();\r | |
134 | jButtonPrevious.setBounds(new java.awt.Rectangle(370, 330, 90, 20));\r | |
135 | jButtonPrevious.setText("Previous");\r | |
136 | jButtonPrevious.addMouseListener(this);\r | |
137 | }\r | |
138 | return jButtonPrevious;\r | |
139 | }\r | |
140 | \r | |
141 | /**\r | |
142 | * This method initializes jScrollPane \r | |
143 | * \r | |
144 | * @return javax.swing.JScrollPane \r | |
145 | */\r | |
146 | private JScrollPane getJScrollPane() {\r | |
147 | if (jScrollPane == null) {\r | |
148 | jScrollPane = new JScrollPane();\r | |
a45e9a40 | 149 | jScrollPane.setBounds(new java.awt.Rectangle(30, 100, 642, 170));\r |
5a24e806 | 150 | jScrollPane.setViewportView(getJTablePackage());\r |
151 | }\r | |
152 | return jScrollPane;\r | |
153 | }\r | |
154 | \r | |
155 | /**\r | |
156 | * This method initializes jTablePackage \r | |
157 | * \r | |
158 | * @return javax.swing.JTable \r | |
159 | */\r | |
160 | private JTable getJTablePackage() {\r | |
161 | if (jTablePackage == null) {\r | |
162 | jTablePackage = new JTable();\r | |
163 | model = new PartialTableModel();\r | |
164 | jTablePackage = new JTable(model);\r | |
165 | jTablePackage.setRowHeight(20);\r | |
166 | jTablePackage.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);\r | |
167 | model.addColumn("Name");\r | |
168 | model.addColumn("Version");\r | |
169 | model.addColumn("Guid");\r | |
170 | model.addColumn("Path");\r | |
171 | \r | |
172 | jTablePackage.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r | |
173 | }\r | |
174 | return jTablePackage;\r | |
175 | }\r | |
176 | \r | |
177 | public void prepareTable() {\r | |
178 | model.setRowCount(0);\r | |
179 | try {\r | |
180 | Far far = stepOne.getFar();\r | |
181 | List<PackageIdentification> packagesInFar = far.mainfest.getPackageList();\r | |
182 | \r | |
183 | WorkspaceTools wt = new WorkspaceTools();\r | |
184 | List<PackageIdentification> packagesInDb = wt.getAllPackages();\r | |
185 | \r | |
1898a0c3 | 186 | updatPkgList = AggregationOperation.intersection(packagesInDb, packagesInFar);\r |
5a24e806 | 187 | //\r |
188 | // Change here to get packages and platforms from FAR\r | |
189 | //\r | |
1898a0c3 | 190 | Iterator<PackageIdentification> iter = updatPkgList.iterator() ;//packageList.iterator();\r |
191 | while (iter.hasNext()) {\r | |
192 | String[] str = new String[4];\r | |
193 | PackageIdentification item = iter.next();\r | |
194 | str[0] = item.getName();\r | |
195 | str[1] = item.getVersion();\r | |
196 | str[2] = item.getGuid();\r | |
197 | str[3] = Tools.getFilePathOnly(Tools.getRelativePath(item.getPath(), Workspace.getCurrentWorkspace()));\r | |
198 | model.addRow(str);\r | |
199 | } \r | |
200 | }\r | |
201 | catch (Exception ex) {\r | |
202 | ex.printStackTrace();\r | |
5a24e806 | 203 | }\r |
1898a0c3 | 204 | }\r |
5a24e806 | 205 | \r |
206 | /**\r | |
207 | * This is the default constructor\r | |
208 | */\r | |
209 | public UpdateStepTwo(IDialog iDialog, boolean modal) {\r | |
210 | super(iDialog, modal);\r | |
211 | initialize();\r | |
212 | }\r | |
213 | \r | |
214 | /**\r | |
215 | * This method initializes this\r | |
216 | * \r | |
217 | * @return void\r | |
218 | */\r | |
219 | private void initialize() {\r | |
220 | this.setSize(700, 400);\r | |
221 | this.setContentPane(getJContentPane());\r | |
222 | this.setTitle("Update Framework Archive(FAR) - Step 2: Summary");\r | |
223 | Dimension d = Toolkit.getDefaultToolkit().getScreenSize();\r | |
224 | this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);\r | |
225 | }\r | |
226 | \r | |
1898a0c3 | 227 | /**\r |
228 | * This method initializes jContentPane\r | |
229 | * \r | |
230 | * @return javax.swing.JPanel\r | |
231 | */\r | |
232 | private JPanel getJContentPane() {\r | |
233 | if (jContentPane == null) {\r | |
234 | jLabel = new JLabel();\r | |
235 | jLabel.setBounds(new java.awt.Rectangle(30,70,281,20));\r | |
236 | jLabel.setText("Following packages will be updated: ");\r | |
237 | jContentPane = new JPanel();\r | |
238 | jContentPane.setLayout(null);\r | |
239 | jContentPane.add(getJTextArea(), null);\r | |
240 | jContentPane.add(getJButtonCancel(), null);\r | |
241 | jContentPane.add(getJButtonFinish(), null);\r | |
242 | jContentPane.add(getJButtonPrevious(), null);\r | |
243 | jContentPane.add(getJScrollPane(), null);\r | |
244 | jContentPane.add(jLabel, null);\r | |
5a24e806 | 245 | }\r |
1898a0c3 | 246 | return jContentPane;\r |
247 | }\r | |
248 | public void mouseClicked(MouseEvent e) {\r | |
249 | if (e.getSource() == jButtonCancel) {\r | |
250 | this.setVisible(false);\r | |
251 | }\r | |
252 | else if (e.getSource() == jButtonFinish) {\r | |
253 | //\r | |
254 | // Check depedency ?\r | |
255 | //\r | |
256 | WorkspaceTools wsTools = new WorkspaceTools();\r | |
257 | \r | |
258 | Iterator<PackageIdentification> iter = updatPkgList.iterator();\r | |
259 | List<PackageIdentification> depResultList = new ArrayList<PackageIdentification>();\r | |
260 | while (iter.hasNext()){\r | |
261 | List<PackageIdentification> depPkgList = stepOne.getFar().getPackageDependencies(iter.next());\r | |
262 | depResultList = AggregationOperation.union(depResultList, depPkgList);\r | |
263 | }\r | |
264 | \r | |
265 | List<PackageIdentification> dbPkgList = DistributeRule.vectorToList(wsTools.getAllPackages());\r | |
266 | List<PackageIdentification> resultList = AggregationOperation.minus(depResultList, AggregationOperation.union(\r | |
267 | this.updatPkgList, dbPkgList));\r | |
268 | Iterator resultIter = resultList.iterator();\r | |
269 | while (resultIter.hasNext()){\r | |
270 | Log.err("Missing dependency package " + ((PackageIdentification)resultIter.next()).toString() + "in workspace!");\r | |
271 | return;\r | |
272 | }\r | |
273 | \r | |
274 | //\r | |
275 | // Remove all update packages\r | |
276 | //\r | |
277 | //\r | |
278 | // For all packages, remove all files. \r | |
279 | // Exception FPD file still in DB\r | |
280 | //\r | |
281 | Vector<PlatformIdentification> allPlatforms = wsTools.getAllPlatforms();\r | |
282 | Set<File> allPlatformFiles = new LinkedHashSet<File>();\r | |
283 | \r | |
284 | Iterator<PlatformIdentification> allPlfIter = allPlatforms.iterator();\r | |
285 | while (iter.hasNext()) {\r | |
286 | allPlatformFiles.add(allPlfIter.next().getFpdFile());\r | |
287 | }\r | |
288 | \r | |
289 | Iterator<PackageIdentification> packageIter = this.updatPkgList.iterator();\r | |
290 | while (packageIter.hasNext()) {\r | |
291 | PackageIdentification item = packageIter.next();\r | |
292 | Set<File> deleteFiles = new LinkedHashSet<File>();\r | |
293 | recursiveDir(deleteFiles, item.getSpdFile().getParentFile(), allPlatformFiles);\r | |
294 | Iterator<File> iterDeleteFile = deleteFiles.iterator();\r | |
295 | while (iterDeleteFile.hasNext()){\r | |
296 | deleteFiles(iterDeleteFile.next());\r | |
297 | }\r | |
298 | //\r | |
299 | // Remove all empty parent dir\r | |
300 | //\r | |
301 | File parentDir = item.getSpdFile().getParentFile();\r | |
302 | while (parentDir.listFiles().length == 0) {\r | |
303 | File tempFile = parentDir;\r | |
304 | parentDir = parentDir.getParentFile();\r | |
305 | tempFile.delete();\r | |
5a24e806 | 306 | }\r |
1898a0c3 | 307 | }\r |
308 | \r | |
309 | //\r | |
310 | // Install all update packages\r | |
311 | //\r | |
312 | Iterator<PackageIdentification> updataIter = this.updatPkgList.iterator();\r | |
313 | while (updataIter.hasNext()){\r | |
314 | PackageIdentification pkgId = updataIter.next();\r | |
315 | try{\r | |
316 | stepOne.getFar().installPackage(pkgId, pkgId.getSpdFile());\r | |
317 | }catch (Exception ex){\r | |
318 | Log.err("Can install " + pkgId.toString() + " pakcage, please check it!");\r | |
319 | }\r | |
320 | \r | |
321 | }\r | |
322 | \r | |
323 | \r | |
324 | this.setVisible(false);\r | |
5a24e806 | 325 | }\r |
1898a0c3 | 326 | else if (e.getSource() == jButtonPrevious) {\r |
327 | this.setVisible(false);\r | |
328 | stepOne.setVisible(true);\r | |
5a24e806 | 329 | }\r |
1898a0c3 | 330 | }\r |
331 | public void mousePressed(MouseEvent e) {\r | |
332 | // TODO Auto-generated method stub\r | |
333 | \r | |
334 | }\r | |
335 | public void mouseReleased(MouseEvent e) {\r | |
336 | // TODO Auto-generated method stub\r | |
337 | \r | |
338 | }\r | |
339 | public void mouseEntered(MouseEvent e) {\r | |
340 | // TODO Auto-generated method stub\r | |
341 | \r | |
342 | }\r | |
343 | public void mouseExited(MouseEvent e) {\r | |
344 | // TODO Auto-generated method stub\r | |
345 | \r | |
346 | }\r | |
347 | \r | |
348 | private void recursiveDir(Set<File> files, File dir, Set<File> platformFiles) {\r | |
349 | File[] fileList = dir.listFiles();\r | |
350 | for (int i = 0; i < fileList.length; i ++) {\r | |
351 | if (fileList[i].isFile()) {\r | |
352 | if( ! platformFiles.contains(fileList[i])) {\r | |
353 | files.add(fileList[i]);\r | |
354 | }\r | |
355 | }\r | |
356 | else {\r | |
357 | if (isContain(fileList[i], platformFiles)) {\r | |
358 | recursiveDir(files, fileList[i], platformFiles);\r | |
359 | }\r | |
360 | else {\r | |
361 | files.add(fileList[i]);\r | |
362 | }\r | |
363 | }\r | |
364 | }\r | |
5a24e806 | 365 | }\r |
1898a0c3 | 366 | \r |
367 | private void deleteFiles(File file) {\r | |
368 | if (file.isDirectory()) {\r | |
369 | File[] files = file.listFiles();\r | |
370 | for (int i = 0; i < files.length; i ++) {\r | |
371 | deleteFiles(files[i]);\r | |
372 | }\r | |
373 | }\r | |
374 | file.delete();\r | |
5a24e806 | 375 | }\r |
1898a0c3 | 376 | \r |
377 | private boolean isContain(File dir, Set<File> platformFiles) {\r | |
378 | Iterator<File> iter = platformFiles.iterator();\r | |
379 | while (iter.hasNext()) {\r | |
380 | File file = iter.next();\r | |
381 | if (file.getPath().startsWith(dir.getPath())) {\r | |
382 | //\r | |
383 | // continue this FPD file\r | |
384 | //\r | |
385 | return true;\r | |
386 | }\r | |
387 | }\r | |
388 | return false;\r | |
5a24e806 | 389 | }\r |
1898a0c3 | 390 | }\r |
5a24e806 | 391 | \r |
5a24e806 | 392 | \r |
393 | class PartialTableModel extends DefaultTableModel {\r | |
1898a0c3 | 394 | /**\r |
395 | * \r | |
396 | */\r | |
397 | private static final long serialVersionUID = 1L;\r | |
398 | \r | |
399 | public boolean isCellEditable(int row, int col) {\r | |
400 | switch (col){\r | |
401 | case 3:\r | |
402 | return false;\r | |
403 | default:\r | |
404 | return false; \r | |
405 | }\r | |
406 | }\r | |
5a24e806 | 407 | }\r |