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
) {
328 if (jTablePackage
.isEditing()) {
329 jTablePackage
.getCellEditor().stopCellEditing();
332 if (jTablePlatform
.isEditing()) {
333 jTablePlatform
.getCellEditor().stopCellEditing();
336 List
<String
> packageList
= new ArrayList
<String
>();
337 List
<String
> platformList
= new ArrayList
<String
>();
339 // Add some logic process here
340 // Guid Check, File Check etc.
342 Set
<File
> allNewPath
= new LinkedHashSet
<File
>();
343 Map
<PackageIdentification
, File
> packageMap
= new LinkedHashMap
<PackageIdentification
, File
>();
344 for (int i
= 0; i
< packageModel
.getRowCount(); i
++) {
345 File toFile
= new File(Workspace
.getCurrentWorkspace() + File
.separatorChar
346 + packageModel
.getValueAt(i
, 3));
347 if (!isPackagePathValid(toFile
)) {
348 Log
.err(packageVector
.get(i
) + " path already has package now. ");
351 if (allNewPath
.contains(toFile
)) {
352 Log
.err("Path " + packageModel
.getValueAt(i
, 3) + " is specified by twice. ");
355 allNewPath
.add(toFile
);
356 File spdFile
= new File((String
) packageModel
.getValueAt(i
, 3) + File
.separatorChar
357 + packageVector
.get(i
).getSpdFile().getName());
358 packageList
.add(spdFile
.getPath());
359 packageMap
.put(packageVector
.get(i
), toFile
);
362 Map
<PlatformIdentification
, File
> platformMap
= new LinkedHashMap
<PlatformIdentification
, File
>();
363 for (int i
= 0; i
< platformModel
.getRowCount(); i
++) {
364 File toFile
= new File(Workspace
.getCurrentWorkspace() + File
.separatorChar
365 + platformModel
.getValueAt(i
, 3));
366 if (!isPlatformPathValid(toFile
)) {
367 Log
.err(platformVector
.get(i
) + " path already has platform now. ");
370 File fpdFile
= new File((String
) platformModel
.getValueAt(i
, 3) + File
.separatorChar
371 + platformVector
.get(i
).getFpdFile().getName());
372 platformList
.add(fpdFile
.getPath());
373 platformMap
.put(platformVector
.get(i
), toFile
);
379 Far far
= stepOne
.getFar();
381 far
.InstallFar(platformMap
, packageMap
);
385 WorkspaceTools wt
= new WorkspaceTools();
386 wt
.addFarToDb(packageList
, platformList
, far
.mainfest
.getHeader());
387 } catch (Exception ex
) {
388 ex
.printStackTrace();
389 Log
.err("Install error. ");
393 this.setVisible(false);
394 this.stepOne
.returnType
= DataType
.RETURN_TYPE_OK
;
396 } else if (e
.getSource() == jButtonPrevious
) {
397 this.setVisible(false);
398 stepOne
.setVisible(true);
402 private boolean isPackagePathValid(File spdFile
) {
403 WorkspaceTools wt
= new WorkspaceTools();
404 List
<PackageIdentification
> allPackages
= wt
.getAllPackages();
405 Iterator
<PackageIdentification
> iter
= allPackages
.iterator();
407 while (iter
.hasNext()) {
408 PackageIdentification item
= iter
.next();
409 if (isPathContainMutual(spdFile
, item
.getSpdFile())) {
416 private boolean isPlatformPathValid(File fpdFile
) {
417 WorkspaceTools wt
= new WorkspaceTools();
418 List
<PlatformIdentification
> allPlatforms
= wt
.getAllPlatforms();
419 Iterator
<PlatformIdentification
> iter
= allPlatforms
.iterator();
421 while (iter
.hasNext()) {
422 PlatformIdentification item
= iter
.next();
423 if (isPathContainMutual(fpdFile
, item
.getFpdFile())) {
430 private boolean isPathContainMutual(File path1
, File path2
) {
431 String s1
= Tools
.addFileSeparator(path1
.getPath());
432 String s2
= Tools
.addFileSeparator(path2
.getParent());
434 if (s1
.length() > s2
.length()) {
435 if (s1
.substring(0, s2
.length()).equalsIgnoreCase(s2
)) {
439 if (s2
.substring(0, s1
.length()).equalsIgnoreCase(s1
)) {
446 public void mousePressed(MouseEvent e
) {
447 // TODO Auto-generated method stub
451 public void mouseReleased(MouseEvent e
) {
452 // TODO Auto-generated method stub
456 public void mouseEntered(MouseEvent e
) {
457 // TODO Auto-generated method stub
461 public void mouseExited(MouseEvent e
) {
462 // TODO Auto-generated method stub
468 class PartialEditableTableModel
extends DefaultTableModel
{
472 private static final long serialVersionUID
= 1L;
474 public boolean isCellEditable(int row
, int col
) {