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
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.
14 package org
.tianocore
.frameworkwizard
.far
.installui
;
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
;
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
;
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
;
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
.packaging
.PackageIdentification
;
45 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
46 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
47 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
49 public class InstallStepTwo
extends IDialog
implements MouseListener
{
54 private static final long serialVersionUID
= 4583090421587036969L;
56 private JPanel jContentPane
= null;
58 private JTextArea jTextArea
= null;
60 private PartialEditableTableModel packageModel
= null;
62 private PartialEditableTableModel platformModel
= null;
64 private InstallStepOne stepOne
= null;
66 private JButton jButtonCancel
= null;
68 private JButton jButtonFinish
= null;
70 private JButton jButtonPrevious
= null;
72 private JLabel jLabel
= null;
74 private JScrollPane jScrollPane
= null;
76 private JTable jTablePackage
= null;
78 private JLabel jLabel1
= null;
80 private JScrollPane jScrollPane1
= null;
82 private JTable jTablePlatform
= null;
84 List
<PlatformIdentification
> platformVector
= null;
86 List
<PackageIdentification
> packageVector
= null;
88 public InstallStepTwo(IDialog iDialog
, boolean modal
, InstallStepOne stepOne
) {
90 this.stepOne
= stepOne
;
94 * This method initializes jTextArea
96 * @return javax.swing.JTextArea
98 private JTextArea
getJTextArea() {
99 if (jTextArea
== null) {
100 jTextArea
= new JTextArea();
101 jTextArea
.setBounds(new java
.awt
.Rectangle(30, 7, 642, 50));
102 jTextArea
.setText("Step 2: Set Path for Packages and Platforms. \n");
103 jTextArea
.setCaretColor(Color
.RED
);
104 jTextArea
.append("Note that path is relative to WORKSPACE. ");
105 jTextArea
.setEditable(false);
111 * This method initializes jButtonCancel
113 * @return javax.swing.JButton
115 private JButton
getJButtonCancel() {
116 if (jButtonCancel
== null) {
117 jButtonCancel
= new JButton();
118 jButtonCancel
.setBounds(new java
.awt
.Rectangle(570, 330, 90, 20));
119 jButtonCancel
.setText("Cancel");
120 jButtonCancel
.addMouseListener(this);
122 return jButtonCancel
;
126 * This method initializes jButtonFinish
128 * @return javax.swing.JButton
130 private JButton
getJButtonFinish() {
131 if (jButtonFinish
== null) {
132 jButtonFinish
= new JButton();
133 jButtonFinish
.setBounds(new java
.awt
.Rectangle(470, 330, 90, 20));
134 jButtonFinish
.setText("Finish");
135 jButtonFinish
.addMouseListener(this);
137 return jButtonFinish
;
141 * This method initializes jButtonPrevious
143 * @return javax.swing.JButton
145 private JButton
getJButtonPrevious() {
146 if (jButtonPrevious
== null) {
147 jButtonPrevious
= new JButton();
148 jButtonPrevious
.setBounds(new java
.awt
.Rectangle(370, 330, 90, 20));
149 jButtonPrevious
.setText("Previous");
150 jButtonPrevious
.addMouseListener(this);
152 return jButtonPrevious
;
156 * This method initializes jScrollPane
158 * @return javax.swing.JScrollPane
160 private JScrollPane
getJScrollPane() {
161 if (jScrollPane
== null) {
162 jScrollPane
= new JScrollPane();
163 jScrollPane
.setBounds(new java
.awt
.Rectangle(30, 80, 642, 110));
164 jScrollPane
.setViewportView(getJTablePackage());
170 * This method initializes jTable
172 * @return javax.swing.JTable
174 private JTable
getJTablePackage() {
175 if (jTablePackage
== null) {
176 jTablePackage
= new JTable();
177 packageModel
= new PartialEditableTableModel();
178 jTablePackage
= new JTable(packageModel
);
179 jTablePackage
.setRowHeight(20);
180 jTablePackage
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_SUBSEQUENT_COLUMNS
);
181 packageModel
.addColumn("Name");
182 packageModel
.addColumn("Version");
183 packageModel
.addColumn("Default Path");
184 packageModel
.addColumn("Install To");
186 jTablePackage
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
188 return jTablePackage
;
191 public void preparePackageTable() {
192 packageModel
.setRowCount(0);
194 // Change here to get packages and platforms from FAR
197 Far far
= stepOne
.getFar();
199 packageVector
= far
.mainfest
.getPackageList();
200 Iterator
<PackageIdentification
> iter
= packageVector
.iterator();
201 while (iter
.hasNext()) {
202 String
[] str
= new String
[4];
203 PackageIdentification item
= iter
.next();
204 str
[0] = item
.getName();
205 str
[1] = item
.getVersion();
206 str
[2] = Tools
.getFilePathOnly(Tools
.getRelativePath(item
.getPath(), Workspace
.getCurrentWorkspace()));
207 str
[3] = Tools
.getFilePathOnly(Tools
.getRelativePath(item
.getPath(), Workspace
.getCurrentWorkspace()));
208 packageModel
.addRow(str
);
210 } catch (Exception e
) {
215 * This method initializes jScrollPane1
217 * @return javax.swing.JScrollPane
219 private JScrollPane
getJScrollPane1() {
220 if (jScrollPane1
== null) {
221 jScrollPane1
= new JScrollPane();
222 jScrollPane1
.setBounds(new java
.awt
.Rectangle(30, 215, 642, 110));
223 jScrollPane1
.setViewportView(getJTablePlatform());
229 * This method initializes jTablePlatform
231 * @return javax.swing.JTable
233 private JTable
getJTablePlatform() {
234 if (jTablePlatform
== null) {
235 jTablePlatform
= new JTable();
236 platformModel
= new PartialEditableTableModel();
237 jTablePlatform
= new JTable(platformModel
);
238 jTablePlatform
.setRowHeight(20);
239 jTablePlatform
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_SUBSEQUENT_COLUMNS
);
240 platformModel
.addColumn("Name");
241 platformModel
.addColumn("Version");
242 platformModel
.addColumn("Default Path");
243 platformModel
.addColumn("Install To");
245 jTablePlatform
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
246 preparePlatformTable();
248 return jTablePlatform
;
251 public void preparePlatformTable() {
252 platformModel
.setRowCount(0);
254 // Change here to get packages and platforms from FAR
257 Far far
= stepOne
.getFar();
259 platformVector
= far
.mainfest
.getPlatformList();
260 Iterator
<PlatformIdentification
> iter
= platformVector
.iterator();
261 while (iter
.hasNext()) {
262 String
[] str
= new String
[4];
263 PlatformIdentification item
= iter
.next();
264 str
[0] = item
.getName();
265 str
[1] = item
.getVersion();
266 str
[2] = Tools
.getFilePathOnly(Tools
.getRelativePath(item
.getPath(), Workspace
.getCurrentWorkspace()));
267 str
[3] = Tools
.getFilePathOnly(Tools
.getRelativePath(item
.getPath(), Workspace
.getCurrentWorkspace()));
268 platformModel
.addRow(str
);
270 } catch (Exception e
) {
275 * This is the default constructor
277 public InstallStepTwo(IDialog iDialog
, boolean modal
) {
278 super(iDialog
, modal
);
283 * This method initializes this
287 private void initialize() {
288 this.setSize(700, 400);
289 this.setContentPane(getJContentPane());
290 this.setTitle("Install Framework Archive(FAR) - Step 2: Set Path for Packages and Platforms");
291 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
292 this.setLocation((d
.width
- this.getSize().width
) / 2, (d
.height
- this.getSize().height
) / 2);
296 * This method initializes jContentPane
298 * @return javax.swing.JPanel
300 private JPanel
getJContentPane() {
301 if (jContentPane
== null) {
302 jLabel1
= new JLabel();
303 jLabel1
.setBounds(new java
.awt
.Rectangle(30, 195, 348, 18));
304 jLabel1
.setText("Edit pathes for platforms: ");
305 jLabel
= new JLabel();
306 jLabel
.setBounds(new java
.awt
.Rectangle(29, 60, 366, 20));
307 jLabel
.setText("Edit pathes for packages");
308 jContentPane
= new JPanel();
309 jContentPane
.setLayout(null);
310 jContentPane
.add(getJTextArea(), null);
311 jContentPane
.add(getJButtonCancel(), null);
312 jContentPane
.add(getJButtonFinish(), null);
313 jContentPane
.add(getJButtonPrevious(), null);
314 jContentPane
.add(jLabel
, null);
315 jContentPane
.add(getJScrollPane(), null);
316 jContentPane
.add(jLabel1
, null);
317 jContentPane
.add(getJScrollPane1(), null);
322 public void mouseClicked(MouseEvent e
) {
323 if (e
.getSource() == jButtonCancel
) {
324 this.setVisible(false);
326 } else if (e
.getSource() == jButtonFinish
) {
327 List
<String
> packageList
= new ArrayList
<String
>();
328 List
<String
> platformList
= new ArrayList
<String
>();
330 // Add some logic process here
331 // Guid Check, File Check etc.
333 Set
<File
> allNewPath
= new LinkedHashSet
<File
>();
334 Map
<PackageIdentification
, File
> packageMap
= new LinkedHashMap
<PackageIdentification
, File
>();
335 for (int i
= 0; i
< packageModel
.getRowCount(); i
++) {
336 File toFile
= new File(Workspace
.getCurrentWorkspace() + File
.separatorChar
337 + packageModel
.getValueAt(i
, 3));
338 if (!isPackagePathValid(toFile
)) {
339 Log
.err(packageVector
.get(i
) + " path already has package now. ");
342 if (allNewPath
.contains(toFile
)) {
343 Log
.err("Path " + packageModel
.getValueAt(i
, 3) + " is specified by twice. ");
346 allNewPath
.add(toFile
);
347 File spdFile
= new File((String
) packageModel
.getValueAt(i
, 3) + File
.separatorChar
348 + packageVector
.get(i
).getSpdFile().getName());
349 packageList
.add(spdFile
.getPath());
350 packageMap
.put(packageVector
.get(i
), toFile
);
353 Map
<PlatformIdentification
, File
> platformMap
= new LinkedHashMap
<PlatformIdentification
, File
>();
354 for (int i
= 0; i
< platformModel
.getRowCount(); i
++) {
355 File toFile
= new File(Workspace
.getCurrentWorkspace() + File
.separatorChar
356 + platformModel
.getValueAt(i
, 3));
357 if (!isPlatformPathValid(toFile
)) {
358 Log
.err(platformVector
.get(i
) + " path already has platform now. ");
361 File fpdFile
= new File((String
) platformModel
.getValueAt(i
, 3) + File
.separatorChar
362 + platformVector
.get(i
).getFpdFile().getName());
363 platformList
.add(fpdFile
.getPath());
364 platformMap
.put(platformVector
.get(i
), toFile
);
370 Far far
= stepOne
.getFar();
372 far
.InstallFar(platformMap
, packageMap
);
376 WorkspaceTools wt
= new WorkspaceTools();
377 wt
.addFarToDb(packageList
, platformList
, far
.mainfest
.getHeader());
378 } catch (Exception ex
) {
379 ex
.printStackTrace();
380 Log
.err("Install error. ");
384 this.setVisible(false);
385 this.stepOne
.returnType
= DataType
.RETURN_TYPE_OK
;
387 } else if (e
.getSource() == jButtonPrevious
) {
388 this.setVisible(false);
389 stepOne
.setVisible(true);
393 private boolean isPackagePathValid(File spdFile
) {
394 WorkspaceTools wt
= new WorkspaceTools();
395 List
<PackageIdentification
> allPackages
= wt
.getAllPackages();
396 Iterator
<PackageIdentification
> iter
= allPackages
.iterator();
398 while (iter
.hasNext()) {
399 PackageIdentification item
= iter
.next();
400 if (isPathContainMutual(spdFile
, item
.getSpdFile())) {
407 private boolean isPlatformPathValid(File fpdFile
) {
408 WorkspaceTools wt
= new WorkspaceTools();
409 List
<PlatformIdentification
> allPlatforms
= wt
.getAllPlatforms();
410 Iterator
<PlatformIdentification
> iter
= allPlatforms
.iterator();
412 while (iter
.hasNext()) {
413 PlatformIdentification item
= iter
.next();
414 if (isPathContainMutual(fpdFile
, item
.getFpdFile())) {
421 private boolean isPathContainMutual(File path1
, File path2
) {
422 if (path1
.getPath().startsWith(path2
.getParent())) {
425 if (path2
.getPath().startsWith(path1
.getPath())) {
431 public void mousePressed(MouseEvent e
) {
432 // TODO Auto-generated method stub
436 public void mouseReleased(MouseEvent e
) {
437 // TODO Auto-generated method stub
441 public void mouseEntered(MouseEvent e
) {
442 // TODO Auto-generated method stub
446 public void mouseExited(MouseEvent e
) {
447 // TODO Auto-generated method stub
453 class PartialEditableTableModel
extends DefaultTableModel
{
457 private static final long serialVersionUID
= 1L;
459 public boolean isCellEditable(int row
, int col
) {