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
.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
;
50 public class InstallStepTwo
extends IDialog
implements MouseListener
{
55 private static final long serialVersionUID
= 4583090421587036969L;
57 private JPanel jContentPane
= null;
59 private JTextArea jTextArea
= null;
61 private PartialEditableTableModel packageModel
= null;
63 private PartialEditableTableModel platformModel
= null;
65 private InstallStepOne stepOne
= null;
67 private JButton jButtonCancel
= null;
69 private JButton jButtonFinish
= null;
71 private JButton jButtonPrevious
= null;
73 private JLabel jLabel
= null;
75 private JScrollPane jScrollPane
= null;
77 private JTable jTablePackage
= null;
79 private JLabel jLabel1
= null;
81 private JScrollPane jScrollPane1
= null;
83 private JTable jTablePlatform
= null;
85 List
<PlatformIdentification
> platformVector
= null;
87 List
<PackageIdentification
> packageVector
= null;
89 public InstallStepTwo(IDialog iDialog
, boolean modal
, InstallStepOne stepOne
) {
91 this.stepOne
= stepOne
;
95 * This method initializes jTextArea
97 * @return javax.swing.JTextArea
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 Path for Packages and Platforms. \n");
104 jTextArea
.setCaretColor(Color
.RED
);
105 jTextArea
.append("Note that path is relative to WORKSPACE. ");
106 jTextArea
.setEditable(false);
112 * This method initializes jButtonCancel
114 * @return javax.swing.JButton
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);
123 return jButtonCancel
;
127 * This method initializes jButtonFinish
129 * @return javax.swing.JButton
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);
138 return jButtonFinish
;
142 * This method initializes jButtonPrevious
144 * @return javax.swing.JButton
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);
153 return jButtonPrevious
;
157 * This method initializes jScrollPane
159 * @return javax.swing.JScrollPane
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());
171 * This method initializes jTable
173 * @return javax.swing.JTable
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");
187 jTablePackage
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
189 return jTablePackage
;
192 public void preparePackageTable() {
193 packageModel
.setRowCount(0);
195 // Change here to get packages and platforms from FAR
198 Far far
= stepOne
.getFar();
200 packageVector
= far
.mainfest
.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
);
211 } catch (Exception e
) {
216 * This method initializes jScrollPane1
218 * @return javax.swing.JScrollPane
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());
230 * This method initializes jTablePlatform
232 * @return javax.swing.JTable
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");
246 jTablePlatform
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
247 preparePlatformTable();
249 return jTablePlatform
;
252 public void preparePlatformTable() {
253 platformModel
.setRowCount(0);
255 // Change here to get packages and platforms from FAR
258 Far far
= stepOne
.getFar();
260 platformVector
= far
.mainfest
.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
);
271 } catch (Exception e
) {
276 * This is the default constructor
278 public InstallStepTwo(IDialog iDialog
, boolean modal
) {
279 super(iDialog
, modal
);
284 * This method initializes this
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);
297 * This method initializes jContentPane
299 * @return javax.swing.JPanel
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 pathes for platforms: ");
306 jLabel
= new JLabel();
307 jLabel
.setBounds(new java
.awt
.Rectangle(29, 60, 366, 20));
308 jLabel
.setText("Edit pathes 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);
323 public void mouseClicked(MouseEvent e
) {
324 if (e
.getSource() == jButtonCancel
) {
325 this.setVisible(false);
327 } else if (e
.getSource() == jButtonFinish
) {
329 if (jTablePackage
.isEditing()) {
330 jTablePackage
.getCellEditor().stopCellEditing();
333 if (jTablePlatform
.isEditing()) {
334 jTablePlatform
.getCellEditor().stopCellEditing();
337 List
<String
> packageList
= new ArrayList
<String
>();
338 List
<String
> platformList
= new ArrayList
<String
>();
340 // Add some logic process here
341 // Guid Check, File Check etc.
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 has package now. ");
352 if (allNewPath
.contains(toFile
)) {
353 Log
.wrn("Install far", "Path " + packageModel
.getValueAt(i
, 3) + " is specified by twice. ");
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
);
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 has platform now. ");
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
);
380 Far far
= stepOne
.getFar();
382 far
.InstallFar(platformMap
, packageMap
);
386 WorkspaceTools wt
= new WorkspaceTools();
387 wt
.addFarToDb(packageList
, platformList
, far
.mainfest
.getHeader());
388 } catch (Exception ex
) {
389 Log
.wrn("Install far", ex
.getMessage());
390 Log
.err("Install far", ex
.getMessage());
394 this.setVisible(false);
395 this.stepOne
.returnType
= DataType
.RETURN_TYPE_OK
;
397 } else if (e
.getSource() == jButtonPrevious
) {
398 this.setVisible(false);
399 stepOne
.setVisible(true);
403 private boolean isPackagePathValid(File spdFile
) {
404 WorkspaceTools wt
= new WorkspaceTools();
405 List
<PackageIdentification
> allPackages
= wt
.getAllPackages();
406 Iterator
<PackageIdentification
> iter
= allPackages
.iterator();
408 while (iter
.hasNext()) {
409 PackageIdentification item
= iter
.next();
410 if (isPathContainMutual(spdFile
, item
.getSpdFile())) {
417 private boolean isPlatformPathValid(File fpdFile
) {
418 WorkspaceTools wt
= new WorkspaceTools();
419 List
<PlatformIdentification
> allPlatforms
= wt
.getAllPlatforms();
420 Iterator
<PlatformIdentification
> iter
= allPlatforms
.iterator();
422 while (iter
.hasNext()) {
423 PlatformIdentification item
= iter
.next();
424 if (isPathContainMutual(fpdFile
, item
.getFpdFile())) {
431 private boolean isPathContainMutual(File path1
, File path2
) {
432 String s1
= Tools
.addFileSeparator(path1
.getPath());
433 String s2
= Tools
.addFileSeparator(path2
.getParent());
435 if (s1
.length() > s2
.length()) {
436 if (s1
.substring(0, s2
.length()).equalsIgnoreCase(s2
)) {
440 if (s2
.substring(0, s1
.length()).equalsIgnoreCase(s1
)) {
447 public void mousePressed(MouseEvent e
) {
448 // TODO Auto-generated method stub
452 public void mouseReleased(MouseEvent e
) {
453 // TODO Auto-generated method stub
457 public void mouseEntered(MouseEvent e
) {
458 // TODO Auto-generated method stub
462 public void mouseExited(MouseEvent e
) {
463 // TODO Auto-generated method stub
469 class PartialEditableTableModel
extends DefaultTableModel
{
473 private static final long serialVersionUID
= 1L;
475 public boolean isCellEditable(int row
, int col
) {