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
.updateui
;
16 import java
.awt
.Dimension
;
17 import java
.awt
.Toolkit
;
18 import java
.awt
.event
.MouseEvent
;
19 import java
.awt
.event
.MouseListener
;
20 import java
.util
.Iterator
;
21 import java
.util
.List
;
23 import javax
.swing
.JPanel
;
24 import javax
.swing
.JTextArea
;
25 import javax
.swing
.JButton
;
26 import javax
.swing
.JScrollPane
;
27 import javax
.swing
.JLabel
;
28 import javax
.swing
.JTable
;
29 import javax
.swing
.ListSelectionModel
;
30 import javax
.swing
.table
.DefaultTableModel
;
32 import org
.tianocore
.frameworkwizard
.common
.Tools
;
33 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
34 import org
.tianocore
.frameworkwizard
.far
.AggregationOperation
;
35 import org
.tianocore
.frameworkwizard
.far
.Far
;
36 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
37 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
38 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
40 public class UpdateStepTwo
extends IDialog
implements MouseListener
{
45 private static final long serialVersionUID
= -4400145363721213110L;
47 private JPanel jContentPane
= null;
49 private JTextArea jTextArea
= null;
51 private UpdateStepOne stepOne
= null;
53 private JButton jButtonCancel
= null;
55 private JButton jButtonFinish
= null;
57 private JButton jButtonPrevious
= null;
59 private JScrollPane jScrollPane
= null;
61 private JLabel jLabel
= null;
63 private JTable jTablePackage
= null;
65 private PartialTableModel model
= null;
67 public UpdateStepTwo(IDialog iDialog
, boolean modal
, UpdateStepOne stepOne
) {
69 this.stepOne
= stepOne
;
73 * This method initializes jTextArea
75 * @return javax.swing.JTextArea
77 private JTextArea
getJTextArea() {
78 if (jTextArea
== null) {
79 jTextArea
= new JTextArea();
80 jTextArea
.setBounds(new java
.awt
.Rectangle(30, 7, 642, 50));
81 jTextArea
.setText("Step 2: Summary. \n");
82 jTextArea
.setEditable(false);
88 * This method initializes jButtonCancel
90 * @return javax.swing.JButton
92 private JButton
getJButtonCancel() {
93 if (jButtonCancel
== null) {
94 jButtonCancel
= new JButton();
95 jButtonCancel
.setBounds(new java
.awt
.Rectangle(570, 330, 90, 20));
96 jButtonCancel
.setText("Cancel");
97 jButtonCancel
.addMouseListener(this);
103 * This method initializes jButtonFinish
105 * @return javax.swing.JButton
107 private JButton
getJButtonFinish() {
108 if (jButtonFinish
== null) {
109 jButtonFinish
= new JButton();
110 jButtonFinish
.setBounds(new java
.awt
.Rectangle(470, 330, 90, 20));
111 jButtonFinish
.setText("Finish");
112 jButtonFinish
.addMouseListener(this);
114 return jButtonFinish
;
118 * This method initializes jButtonPrevious
120 * @return javax.swing.JButton
122 private JButton
getJButtonPrevious() {
123 if (jButtonPrevious
== null) {
124 jButtonPrevious
= new JButton();
125 jButtonPrevious
.setBounds(new java
.awt
.Rectangle(370, 330, 90, 20));
126 jButtonPrevious
.setText("Previous");
127 jButtonPrevious
.addMouseListener(this);
129 return jButtonPrevious
;
133 * This method initializes jScrollPane
135 * @return javax.swing.JScrollPane
137 private JScrollPane
getJScrollPane() {
138 if (jScrollPane
== null) {
139 jScrollPane
= new JScrollPane();
140 jScrollPane
.setBounds(new java
.awt
.Rectangle(30, 98, 570, 170));
141 jScrollPane
.setViewportView(getJTablePackage());
147 * This method initializes jTablePackage
149 * @return javax.swing.JTable
151 private JTable
getJTablePackage() {
152 if (jTablePackage
== null) {
153 jTablePackage
= new JTable();
154 model
= new PartialTableModel();
155 jTablePackage
= new JTable(model
);
156 jTablePackage
.setRowHeight(20);
157 jTablePackage
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_SUBSEQUENT_COLUMNS
);
158 model
.addColumn("Name");
159 model
.addColumn("Version");
160 model
.addColumn("Guid");
161 model
.addColumn("Path");
163 jTablePackage
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
165 return jTablePackage
;
168 public void prepareTable() {
169 model
.setRowCount(0);
171 Far far
= stepOne
.getFar();
172 List
<PackageIdentification
> packagesInFar
= far
.mainfest
.getPackageList();
174 WorkspaceTools wt
= new WorkspaceTools();
175 List
<PackageIdentification
> packagesInDb
= wt
.getAllPackages();
177 List
<PackageIdentification
> result
= AggregationOperation
.intersection(packagesInDb
, packagesInFar
);
179 // Change here to get packages and platforms from FAR
181 Iterator
<PackageIdentification
> iter
= result
.iterator();//packageList.iterator();
182 while (iter
.hasNext()) {
183 String
[] str
= new String
[4];
184 PackageIdentification item
= iter
.next();
185 str
[0] = item
.getName();
186 str
[1] = item
.getVersion();
187 str
[2] = item
.getGuid();
188 str
[3] = Tools
.getFilePathOnly(Tools
.getRelativePath(item
.getPath(), Workspace
.getCurrentWorkspace()));
191 } catch (Exception ex
) {
192 ex
.printStackTrace();
197 * This is the default constructor
199 public UpdateStepTwo(IDialog iDialog
, boolean modal
) {
200 super(iDialog
, modal
);
205 * This method initializes this
209 private void initialize() {
210 this.setSize(700, 400);
211 this.setContentPane(getJContentPane());
212 this.setTitle("Update Framework Archive(FAR) - Step 2: Summary");
213 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
214 this.setLocation((d
.width
- this.getSize().width
) / 2, (d
.height
- this.getSize().height
) / 2);
218 * This method initializes jContentPane
220 * @return javax.swing.JPanel
222 private JPanel
getJContentPane() {
223 if (jContentPane
== null) {
224 jLabel
= new JLabel();
225 jLabel
.setBounds(new java
.awt
.Rectangle(30, 70, 281, 20));
226 jLabel
.setText("Following packages will be updated: ");
227 jContentPane
= new JPanel();
228 jContentPane
.setLayout(null);
229 jContentPane
.add(getJTextArea(), null);
230 jContentPane
.add(getJButtonCancel(), null);
231 jContentPane
.add(getJButtonFinish(), null);
232 jContentPane
.add(getJButtonPrevious(), null);
233 jContentPane
.add(getJScrollPane(), null);
234 jContentPane
.add(jLabel
, null);
239 public void mouseClicked(MouseEvent e
) {
240 if (e
.getSource() == jButtonCancel
) {
241 this.setVisible(false);
242 } else if (e
.getSource() == jButtonFinish
) {
248 // Remove all update packages
252 // Install all update packages
255 this.setVisible(false);
256 } else if (e
.getSource() == jButtonPrevious
) {
257 this.setVisible(false);
258 stepOne
.setVisible(true);
262 public void mousePressed(MouseEvent e
) {
263 // TODO Auto-generated method stub
267 public void mouseReleased(MouseEvent e
) {
268 // TODO Auto-generated method stub
272 public void mouseEntered(MouseEvent e
) {
273 // TODO Auto-generated method stub
277 public void mouseExited(MouseEvent e
) {
278 // TODO Auto-generated method stub
284 class PartialTableModel
extends DefaultTableModel
{
288 private static final long serialVersionUID
= 1L;
290 public boolean isCellEditable(int row
, int col
) {