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