]>
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.installui;\r | |
15 | \r | |
16 | import java.awt.Color;\r | |
17 | import java.awt.Dimension;\r | |
18 | import java.awt.Toolkit;\r | |
19 | import java.awt.event.MouseEvent;\r | |
20 | import java.awt.event.MouseListener;\r | |
21 | import java.io.File;\r | |
22 | import java.util.ArrayList;\r | |
23 | import java.util.Iterator;\r | |
24 | import java.util.LinkedHashMap;\r | |
25 | import java.util.LinkedHashSet;\r | |
26 | import java.util.List;\r | |
27 | import java.util.Map;\r | |
28 | import java.util.Set;\r | |
29 | \r | |
30 | import javax.swing.JPanel;\r | |
31 | import javax.swing.JTextArea;\r | |
32 | import javax.swing.JButton;\r | |
33 | import javax.swing.JLabel;\r | |
34 | import javax.swing.JScrollPane;\r | |
35 | import javax.swing.ListSelectionModel;\r | |
36 | import javax.swing.table.DefaultTableModel;\r | |
37 | import javax.swing.JTable;\r | |
38 | \r | |
39 | import org.tianocore.frameworkwizard.common.DataType;\r | |
40 | import org.tianocore.frameworkwizard.common.Log;\r | |
41 | import org.tianocore.frameworkwizard.common.Tools;\r | |
42 | import org.tianocore.frameworkwizard.common.ui.IDialog;\r | |
43 | import org.tianocore.frameworkwizard.far.Far;\r | |
44 | import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r | |
45 | import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r | |
46 | import org.tianocore.frameworkwizard.workspace.Workspace;\r | |
47 | import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r | |
48 | \r | |
49 | public class InstallStepTwo extends IDialog implements MouseListener {\r | |
50 | \r | |
51 | /**\r | |
52 | * \r | |
53 | */\r | |
54 | private static final long serialVersionUID = 4583090421587036969L;\r | |
55 | \r | |
56 | private JPanel jContentPane = null;\r | |
57 | \r | |
58 | private JTextArea jTextArea = null;\r | |
59 | \r | |
60 | private PartialEditableTableModel packageModel = null;\r | |
61 | \r | |
62 | private PartialEditableTableModel platformModel = null;\r | |
63 | \r | |
64 | private InstallStepOne stepOne = null;\r | |
65 | \r | |
66 | private JButton jButtonCancel = null;\r | |
67 | \r | |
68 | private JButton jButtonFinish = null;\r | |
69 | \r | |
70 | private JButton jButtonPrevious = null;\r | |
71 | \r | |
72 | private JLabel jLabel = null;\r | |
73 | \r | |
74 | private JScrollPane jScrollPane = null;\r | |
75 | \r | |
76 | private JTable jTablePackage = null;\r | |
77 | \r | |
78 | private JLabel jLabel1 = null;\r | |
79 | \r | |
80 | private JScrollPane jScrollPane1 = null;\r | |
81 | \r | |
82 | private JTable jTablePlatform = null;\r | |
83 | \r | |
84 | List<PlatformIdentification> platformVector = null;\r | |
85 | \r | |
86 | List<PackageIdentification> packageVector = null;\r | |
87 | \r | |
88 | public InstallStepTwo(IDialog iDialog, boolean modal, InstallStepOne stepOne) {\r | |
89 | this(iDialog, modal);\r | |
90 | this.stepOne = stepOne;\r | |
91 | }\r | |
92 | \r | |
93 | /**\r | |
94 | * This method initializes jTextArea \r | |
95 | * \r | |
96 | * @return javax.swing.JTextArea \r | |
97 | */\r | |
98 | private JTextArea getJTextArea() {\r | |
99 | if (jTextArea == null) {\r | |
100 | jTextArea = new JTextArea();\r | |
101 | jTextArea.setBounds(new java.awt.Rectangle(30, 7, 642, 50));\r | |
102 | jTextArea.setText("Step 2: Set Path for Packages and Platforms. \n");\r | |
103 | jTextArea.setCaretColor(Color.RED);\r | |
104 | jTextArea.append("Note that path is relative to WORKSPACE. ");\r | |
105 | jTextArea.setEditable(false);\r | |
106 | }\r | |
107 | return jTextArea;\r | |
108 | }\r | |
109 | \r | |
110 | /**\r | |
111 | * This method initializes jButtonCancel \r | |
112 | * \r | |
113 | * @return javax.swing.JButton \r | |
114 | */\r | |
115 | private JButton getJButtonCancel() {\r | |
116 | if (jButtonCancel == null) {\r | |
117 | jButtonCancel = new JButton();\r | |
118 | jButtonCancel.setBounds(new java.awt.Rectangle(570, 330, 90, 20));\r | |
119 | jButtonCancel.setText("Cancel");\r | |
120 | jButtonCancel.addMouseListener(this);\r | |
121 | }\r | |
122 | return jButtonCancel;\r | |
123 | }\r | |
124 | \r | |
125 | /**\r | |
126 | * This method initializes jButtonFinish \r | |
127 | * \r | |
128 | * @return javax.swing.JButton \r | |
129 | */\r | |
130 | private JButton getJButtonFinish() {\r | |
131 | if (jButtonFinish == null) {\r | |
132 | jButtonFinish = new JButton();\r | |
133 | jButtonFinish.setBounds(new java.awt.Rectangle(470, 330, 90, 20));\r | |
134 | jButtonFinish.setText("Finish");\r | |
135 | jButtonFinish.addMouseListener(this);\r | |
136 | }\r | |
137 | return jButtonFinish;\r | |
138 | }\r | |
139 | \r | |
140 | /**\r | |
141 | * This method initializes jButtonPrevious \r | |
142 | * \r | |
143 | * @return javax.swing.JButton \r | |
144 | */\r | |
145 | private JButton getJButtonPrevious() {\r | |
146 | if (jButtonPrevious == null) {\r | |
147 | jButtonPrevious = new JButton();\r | |
148 | jButtonPrevious.setBounds(new java.awt.Rectangle(370, 330, 90, 20));\r | |
149 | jButtonPrevious.setText("Previous");\r | |
150 | jButtonPrevious.addMouseListener(this);\r | |
151 | }\r | |
152 | return jButtonPrevious;\r | |
153 | }\r | |
154 | \r | |
155 | /**\r | |
156 | * This method initializes jScrollPane \r | |
157 | * \r | |
158 | * @return javax.swing.JScrollPane \r | |
159 | */\r | |
160 | private JScrollPane getJScrollPane() {\r | |
161 | if (jScrollPane == null) {\r | |
162 | jScrollPane = new JScrollPane();\r | |
a45e9a40 | 163 | jScrollPane.setBounds(new java.awt.Rectangle(30, 80, 642, 110));\r |
5a24e806 | 164 | jScrollPane.setViewportView(getJTablePackage());\r |
165 | }\r | |
166 | return jScrollPane;\r | |
167 | }\r | |
168 | \r | |
169 | /**\r | |
170 | * This method initializes jTable \r | |
171 | * \r | |
172 | * @return javax.swing.JTable \r | |
173 | */\r | |
174 | private JTable getJTablePackage() {\r | |
175 | if (jTablePackage == null) {\r | |
176 | jTablePackage = new JTable();\r | |
177 | packageModel = new PartialEditableTableModel();\r | |
178 | jTablePackage = new JTable(packageModel);\r | |
179 | jTablePackage.setRowHeight(20);\r | |
180 | jTablePackage.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);\r | |
181 | packageModel.addColumn("Name");\r | |
182 | packageModel.addColumn("Version");\r | |
183 | packageModel.addColumn("Default Path");\r | |
184 | packageModel.addColumn("Install To");\r | |
185 | \r | |
186 | jTablePackage.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r | |
187 | }\r | |
188 | return jTablePackage;\r | |
189 | }\r | |
190 | \r | |
191 | public void preparePackageTable() {\r | |
192 | packageModel.setRowCount(0);\r | |
193 | //\r | |
194 | // Change here to get packages and platforms from FAR\r | |
195 | //\r | |
196 | try {\r | |
197 | Far far = stepOne.getFar();\r | |
198 | \r | |
199 | packageVector = far.mainfest.getPackageList();\r | |
200 | Iterator<PackageIdentification> iter = packageVector.iterator();\r | |
201 | while (iter.hasNext()) {\r | |
202 | String[] str = new String[4];\r | |
203 | PackageIdentification item = iter.next();\r | |
204 | str[0] = item.getName();\r | |
205 | str[1] = item.getVersion();\r | |
206 | str[2] = Tools.getFilePathOnly(Tools.getRelativePath(item.getPath(), Workspace.getCurrentWorkspace()));\r | |
207 | str[3] = Tools.getFilePathOnly(Tools.getRelativePath(item.getPath(), Workspace.getCurrentWorkspace()));\r | |
208 | packageModel.addRow(str);\r | |
209 | }\r | |
210 | } catch (Exception e) {\r | |
211 | }\r | |
212 | }\r | |
213 | \r | |
214 | /**\r | |
215 | * This method initializes jScrollPane1 \r | |
216 | * \r | |
217 | * @return javax.swing.JScrollPane \r | |
218 | */\r | |
219 | private JScrollPane getJScrollPane1() {\r | |
220 | if (jScrollPane1 == null) {\r | |
221 | jScrollPane1 = new JScrollPane();\r | |
a45e9a40 | 222 | jScrollPane1.setBounds(new java.awt.Rectangle(30, 215, 642, 110));\r |
5a24e806 | 223 | jScrollPane1.setViewportView(getJTablePlatform());\r |
224 | }\r | |
225 | return jScrollPane1;\r | |
226 | }\r | |
227 | \r | |
228 | /**\r | |
229 | * This method initializes jTablePlatform \r | |
230 | * \r | |
231 | * @return javax.swing.JTable \r | |
232 | */\r | |
233 | private JTable getJTablePlatform() {\r | |
234 | if (jTablePlatform == null) {\r | |
235 | jTablePlatform = new JTable();\r | |
236 | platformModel = new PartialEditableTableModel();\r | |
237 | jTablePlatform = new JTable(platformModel);\r | |
238 | jTablePlatform.setRowHeight(20);\r | |
239 | jTablePlatform.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);\r | |
240 | platformModel.addColumn("Name");\r | |
241 | platformModel.addColumn("Version");\r | |
242 | platformModel.addColumn("Default Path");\r | |
243 | platformModel.addColumn("Install To");\r | |
244 | \r | |
245 | jTablePlatform.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r | |
246 | preparePlatformTable();\r | |
247 | }\r | |
248 | return jTablePlatform;\r | |
249 | }\r | |
250 | \r | |
251 | public void preparePlatformTable() {\r | |
252 | platformModel.setRowCount(0);\r | |
253 | //\r | |
254 | // Change here to get packages and platforms from FAR\r | |
255 | //\r | |
256 | try {\r | |
257 | Far far = stepOne.getFar();\r | |
258 | \r | |
259 | platformVector = far.mainfest.getPlatformList();\r | |
260 | Iterator<PlatformIdentification> iter = platformVector.iterator();\r | |
261 | while (iter.hasNext()) {\r | |
262 | String[] str = new String[4];\r | |
263 | PlatformIdentification item = iter.next();\r | |
264 | str[0] = item.getName();\r | |
265 | str[1] = item.getVersion();\r | |
266 | str[2] = Tools.getFilePathOnly(Tools.getRelativePath(item.getPath(), Workspace.getCurrentWorkspace()));\r | |
267 | str[3] = Tools.getFilePathOnly(Tools.getRelativePath(item.getPath(), Workspace.getCurrentWorkspace()));\r | |
268 | platformModel.addRow(str);\r | |
269 | }\r | |
270 | } catch (Exception e) {\r | |
271 | }\r | |
272 | }\r | |
273 | \r | |
274 | /**\r | |
275 | * This is the default constructor\r | |
276 | */\r | |
277 | public InstallStepTwo(IDialog iDialog, boolean modal) {\r | |
278 | super(iDialog, modal);\r | |
279 | initialize();\r | |
280 | }\r | |
281 | \r | |
282 | /**\r | |
283 | * This method initializes this\r | |
284 | * \r | |
285 | * @return void\r | |
286 | */\r | |
287 | private void initialize() {\r | |
288 | this.setSize(700, 400);\r | |
289 | this.setContentPane(getJContentPane());\r | |
290 | this.setTitle("Install Framework Archive(FAR) - Step 2: Set Path for Packages and Platforms");\r | |
291 | Dimension d = Toolkit.getDefaultToolkit().getScreenSize();\r | |
292 | this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);\r | |
293 | }\r | |
294 | \r | |
295 | /**\r | |
296 | * This method initializes jContentPane\r | |
297 | * \r | |
298 | * @return javax.swing.JPanel\r | |
299 | */\r | |
300 | private JPanel getJContentPane() {\r | |
301 | if (jContentPane == null) {\r | |
302 | jLabel1 = new JLabel();\r | |
303 | jLabel1.setBounds(new java.awt.Rectangle(30, 195, 348, 18));\r | |
304 | jLabel1.setText("Edit pathes for platforms: ");\r | |
305 | jLabel = new JLabel();\r | |
306 | jLabel.setBounds(new java.awt.Rectangle(29, 60, 366, 20));\r | |
307 | jLabel.setText("Edit pathes for packages");\r | |
308 | jContentPane = new JPanel();\r | |
309 | jContentPane.setLayout(null);\r | |
310 | jContentPane.add(getJTextArea(), null);\r | |
311 | jContentPane.add(getJButtonCancel(), null);\r | |
312 | jContentPane.add(getJButtonFinish(), null);\r | |
313 | jContentPane.add(getJButtonPrevious(), null);\r | |
314 | jContentPane.add(jLabel, null);\r | |
315 | jContentPane.add(getJScrollPane(), null);\r | |
316 | jContentPane.add(jLabel1, null);\r | |
317 | jContentPane.add(getJScrollPane1(), null);\r | |
318 | }\r | |
319 | return jContentPane;\r | |
320 | }\r | |
321 | \r | |
322 | public void mouseClicked(MouseEvent e) {\r | |
323 | if (e.getSource() == jButtonCancel) {\r | |
324 | this.setVisible(false);\r | |
325 | this.dispose();\r | |
326 | } else if (e.getSource() == jButtonFinish) {\r | |
ef6e2efe | 327 | \r |
328 | if (jTablePackage.isEditing()) {\r | |
329 | jTablePackage.getCellEditor().stopCellEditing();\r | |
330 | }\r | |
331 | \r | |
332 | if (jTablePlatform.isEditing()) {\r | |
333 | jTablePlatform.getCellEditor().stopCellEditing();\r | |
334 | }\r | |
335 | \r | |
5a24e806 | 336 | List<String> packageList = new ArrayList<String>();\r |
337 | List<String> platformList = new ArrayList<String>();\r | |
338 | //\r | |
339 | // Add some logic process here\r | |
340 | // Guid Check, File Check etc.\r | |
341 | //\r | |
342 | Set<File> allNewPath = new LinkedHashSet<File>();\r | |
343 | Map<PackageIdentification, File> packageMap = new LinkedHashMap<PackageIdentification, File>();\r | |
344 | for (int i = 0; i < packageModel.getRowCount(); i++) {\r | |
345 | File toFile = new File(Workspace.getCurrentWorkspace() + File.separatorChar\r | |
346 | + packageModel.getValueAt(i, 3));\r | |
347 | if (!isPackagePathValid(toFile)) {\r | |
ed1665f2 | 348 | Log.wrn("Install far", packageVector.get(i) + " path already has package now. ");\r |
5a24e806 | 349 | return;\r |
350 | }\r | |
351 | if (allNewPath.contains(toFile)) {\r | |
ed1665f2 | 352 | Log.wrn("Install far", "Path " + packageModel.getValueAt(i, 3) + " is specified by twice. ");\r |
5a24e806 | 353 | return;\r |
354 | }\r | |
355 | allNewPath.add(toFile);\r | |
356 | File spdFile = new File((String) packageModel.getValueAt(i, 3) + File.separatorChar\r | |
357 | + packageVector.get(i).getSpdFile().getName());\r | |
358 | packageList.add(spdFile.getPath());\r | |
359 | packageMap.put(packageVector.get(i), toFile);\r | |
360 | }\r | |
361 | \r | |
362 | Map<PlatformIdentification, File> platformMap = new LinkedHashMap<PlatformIdentification, File>();\r | |
363 | for (int i = 0; i < platformModel.getRowCount(); i++) {\r | |
364 | File toFile = new File(Workspace.getCurrentWorkspace() + File.separatorChar\r | |
365 | + platformModel.getValueAt(i, 3));\r | |
366 | if (!isPlatformPathValid(toFile)) {\r | |
ed1665f2 | 367 | Log.wrn("Install far", platformVector.get(i) + " path already has platform now. ");\r |
5a24e806 | 368 | return;\r |
369 | }\r | |
370 | File fpdFile = new File((String) platformModel.getValueAt(i, 3) + File.separatorChar\r | |
371 | + platformVector.get(i).getFpdFile().getName());\r | |
372 | platformList.add(fpdFile.getPath());\r | |
373 | platformMap.put(platformVector.get(i), toFile);\r | |
374 | }\r | |
375 | \r | |
376 | //\r | |
377 | //\r | |
378 | //\r | |
379 | Far far = stepOne.getFar();\r | |
380 | try {\r | |
381 | far.InstallFar(platformMap, packageMap);\r | |
382 | //\r | |
383 | // Add to database\r | |
384 | //\r | |
385 | WorkspaceTools wt = new WorkspaceTools();\r | |
386 | wt.addFarToDb(packageList, platformList, far.mainfest.getHeader());\r | |
387 | } catch (Exception ex) {\r | |
ed1665f2 | 388 | Log.wrn("Install far", ex.getMessage());\r |
389 | Log.err("Install far", ex.getMessage());\r | |
5a24e806 | 390 | return;\r |
391 | }\r | |
392 | \r | |
393 | this.setVisible(false);\r | |
394 | this.stepOne.returnType = DataType.RETURN_TYPE_OK;\r | |
395 | this.dispose();\r | |
396 | } else if (e.getSource() == jButtonPrevious) {\r | |
397 | this.setVisible(false);\r | |
398 | stepOne.setVisible(true);\r | |
399 | }\r | |
400 | }\r | |
401 | \r | |
402 | private boolean isPackagePathValid(File spdFile) {\r | |
403 | WorkspaceTools wt = new WorkspaceTools();\r | |
404 | List<PackageIdentification> allPackages = wt.getAllPackages();\r | |
405 | Iterator<PackageIdentification> iter = allPackages.iterator();\r | |
406 | \r | |
407 | while (iter.hasNext()) {\r | |
408 | PackageIdentification item = iter.next();\r | |
409 | if (isPathContainMutual(spdFile, item.getSpdFile())) {\r | |
410 | return false;\r | |
411 | }\r | |
412 | }\r | |
413 | return true;\r | |
414 | }\r | |
415 | \r | |
416 | private boolean isPlatformPathValid(File fpdFile) {\r | |
417 | WorkspaceTools wt = new WorkspaceTools();\r | |
418 | List<PlatformIdentification> allPlatforms = wt.getAllPlatforms();\r | |
419 | Iterator<PlatformIdentification> iter = allPlatforms.iterator();\r | |
420 | \r | |
421 | while (iter.hasNext()) {\r | |
422 | PlatformIdentification item = iter.next();\r | |
423 | if (isPathContainMutual(fpdFile, item.getFpdFile())) {\r | |
424 | return false;\r | |
425 | }\r | |
426 | }\r | |
427 | return true;\r | |
428 | }\r | |
429 | \r | |
430 | private boolean isPathContainMutual(File path1, File path2) {\r | |
ef6e2efe | 431 | String s1 = Tools.addFileSeparator(path1.getPath());\r |
432 | String s2 = Tools.addFileSeparator(path2.getParent());\r | |
433 | \r | |
434 | if (s1.length() > s2.length()) {\r | |
435 | if (s1.substring(0, s2.length()).equalsIgnoreCase(s2)) {\r | |
436 | return true;\r | |
437 | }\r | |
438 | } else {\r | |
439 | if (s2.substring(0, s1.length()).equalsIgnoreCase(s1)) {\r | |
440 | return true;\r | |
441 | }\r | |
5a24e806 | 442 | }\r |
443 | return false;\r | |
444 | }\r | |
445 | \r | |
446 | public void mousePressed(MouseEvent e) {\r | |
447 | // TODO Auto-generated method stub\r | |
448 | \r | |
449 | }\r | |
450 | \r | |
451 | public void mouseReleased(MouseEvent e) {\r | |
452 | // TODO Auto-generated method stub\r | |
453 | \r | |
454 | }\r | |
455 | \r | |
456 | public void mouseEntered(MouseEvent e) {\r | |
457 | // TODO Auto-generated method stub\r | |
458 | \r | |
459 | }\r | |
460 | \r | |
461 | public void mouseExited(MouseEvent e) {\r | |
462 | // TODO Auto-generated method stub\r | |
463 | \r | |
464 | }\r | |
465 | \r | |
466 | }\r | |
467 | \r | |
468 | class PartialEditableTableModel extends DefaultTableModel {\r | |
469 | /**\r | |
470 | * \r | |
471 | */\r | |
472 | private static final long serialVersionUID = 1L;\r | |
473 | \r | |
474 | public boolean isCellEditable(int row, int col) {\r | |
475 | switch (col) {\r | |
476 | case 3:\r | |
477 | return true;\r | |
478 | default:\r | |
479 | return false;\r | |
480 | }\r | |
481 | }\r | |
482 | }\r |