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