]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/far/updateui/UpdateStepTwo.java
1. Support to Create/Update/Delete/Install far file
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / far / updateui / UpdateStepTwo.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.updateui;
15
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;
22
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;
31
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;
39
40 public class UpdateStepTwo extends IDialog implements MouseListener {
41
42 /**
43 *
44 */
45 private static final long serialVersionUID = -4400145363721213110L;
46
47 private JPanel jContentPane = null;
48
49 private JTextArea jTextArea = null;
50
51 private UpdateStepOne stepOne = null;
52
53 private JButton jButtonCancel = null;
54
55 private JButton jButtonFinish = null;
56
57 private JButton jButtonPrevious = null;
58
59 private JScrollPane jScrollPane = null;
60
61 private JLabel jLabel = null;
62
63 private JTable jTablePackage = null;
64
65 private PartialTableModel model = null;
66
67 public UpdateStepTwo(IDialog iDialog, boolean modal, UpdateStepOne stepOne) {
68 this(iDialog, modal);
69 this.stepOne = stepOne;
70 }
71
72 /**
73 * This method initializes jTextArea
74 *
75 * @return javax.swing.JTextArea
76 */
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);
83 }
84 return jTextArea;
85 }
86
87 /**
88 * This method initializes jButtonCancel
89 *
90 * @return javax.swing.JButton
91 */
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);
98 }
99 return jButtonCancel;
100 }
101
102 /**
103 * This method initializes jButtonFinish
104 *
105 * @return javax.swing.JButton
106 */
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);
113 }
114 return jButtonFinish;
115 }
116
117 /**
118 * This method initializes jButtonPrevious
119 *
120 * @return javax.swing.JButton
121 */
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);
128 }
129 return jButtonPrevious;
130 }
131
132 /**
133 * This method initializes jScrollPane
134 *
135 * @return javax.swing.JScrollPane
136 */
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());
142 }
143 return jScrollPane;
144 }
145
146 /**
147 * This method initializes jTablePackage
148 *
149 * @return javax.swing.JTable
150 */
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");
162
163 jTablePackage.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
164 }
165 return jTablePackage;
166 }
167
168 public void prepareTable() {
169 model.setRowCount(0);
170 try {
171 Far far = stepOne.getFar();
172 List<PackageIdentification> packagesInFar = far.mainfest.getPackageList();
173
174 WorkspaceTools wt = new WorkspaceTools();
175 List<PackageIdentification> packagesInDb = wt.getAllPackages();
176
177 List<PackageIdentification> result = AggregationOperation.intersection(packagesInDb, packagesInFar);
178 //
179 // Change here to get packages and platforms from FAR
180 //
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()));
189 model.addRow(str);
190 }
191 } catch (Exception ex) {
192 ex.printStackTrace();
193 }
194 }
195
196 /**
197 * This is the default constructor
198 */
199 public UpdateStepTwo(IDialog iDialog, boolean modal) {
200 super(iDialog, modal);
201 initialize();
202 }
203
204 /**
205 * This method initializes this
206 *
207 * @return void
208 */
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);
215 }
216
217 /**
218 * This method initializes jContentPane
219 *
220 * @return javax.swing.JPanel
221 */
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);
235 }
236 return jContentPane;
237 }
238
239 public void mouseClicked(MouseEvent e) {
240 if (e.getSource() == jButtonCancel) {
241 this.setVisible(false);
242 } else if (e.getSource() == jButtonFinish) {
243 //
244 // Check depedency ?
245 //
246
247 //
248 // Remove all update packages
249 //
250
251 //
252 // Install all update packages
253 //
254
255 this.setVisible(false);
256 } else if (e.getSource() == jButtonPrevious) {
257 this.setVisible(false);
258 stepOne.setVisible(true);
259 }
260 }
261
262 public void mousePressed(MouseEvent e) {
263 // TODO Auto-generated method stub
264
265 }
266
267 public void mouseReleased(MouseEvent e) {
268 // TODO Auto-generated method stub
269
270 }
271
272 public void mouseEntered(MouseEvent e) {
273 // TODO Auto-generated method stub
274
275 }
276
277 public void mouseExited(MouseEvent e) {
278 // TODO Auto-generated method stub
279
280 }
281
282 }
283
284 class PartialTableModel extends DefaultTableModel {
285 /**
286 *
287 */
288 private static final long serialVersionUID = 1L;
289
290 public boolean isCellEditable(int row, int col) {
291 switch (col) {
292 case 3:
293 return false;
294 default:
295 return false;
296 }
297 }
298 }