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