]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/far/installui/InstallStepOne.java
1. Wrap text by word when showing a message box
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / far / installui / InstallStepOne.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.installui;
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.io.File;
21 import java.util.List;
22 import java.util.jar.JarFile;
23 import java.util.Iterator;
24
25 import javax.swing.JFileChooser;
26 import javax.swing.JPanel;
27 import javax.swing.JButton;
28 import javax.swing.JTextArea;
29 import javax.swing.JLabel;
30 import javax.swing.JTextField;
31 import javax.swing.ListSelectionModel;
32
33 import org.tianocore.frameworkwizard.common.DataType;
34 import org.tianocore.frameworkwizard.common.IFileFilter;
35 import org.tianocore.frameworkwizard.common.Log;
36 import org.tianocore.frameworkwizard.common.Tools;
37 import org.tianocore.frameworkwizard.common.ui.IDialog;
38 import org.tianocore.frameworkwizard.common.ui.IFrame;
39 import org.tianocore.frameworkwizard.far.DistributeRule;
40 import org.tianocore.frameworkwizard.far.Far;
41 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
42 import org.tianocore.frameworkwizard.workspace.Workspace;
43
44 import javax.swing.JScrollPane;
45 import javax.swing.JTable;
46 import javax.swing.table.DefaultTableModel;
47
48 public class InstallStepOne extends IDialog implements MouseListener {
49
50 /**
51 *
52 */
53 private static final long serialVersionUID = -8821906198791949544L;
54
55 private JPanel jContentPane = null;
56
57 private JButton jButtonCancel = null;
58
59 private JButton jButtonNext = null;
60
61 private JTextArea jTextArea = null;
62
63 private JLabel jLabel = null;
64
65 private JTextField jTextFieldFarFile = null;
66
67 private JButton jButtonBrowser = null;
68
69 private InstallStepTwo stepTwo = null;
70
71 Far far = null;
72
73 private JLabel jLabelWarning = null;
74
75 private JScrollPane jScrollPane = null;
76
77 private JTable jTable = null;
78
79 private PartialTableModel model = null;
80
81 /**
82 * This method initializes jButtonCancel
83 *
84 * @return javax.swing.JButton
85 */
86 private JButton getJButtonCancel() {
87 if (jButtonCancel == null) {
88 jButtonCancel = new JButton();
89 jButtonCancel.setBounds(new java.awt.Rectangle(570, 330, 90, 20));
90 jButtonCancel.setText("Cancel");
91 jButtonCancel.addMouseListener(this);
92 }
93 return jButtonCancel;
94 }
95
96 /**
97 * This method initializes jButtonNext
98 *
99 * @return javax.swing.JButton
100 */
101 private JButton getJButtonNext() {
102 if (jButtonNext == null) {
103 jButtonNext = new JButton();
104 jButtonNext.setBounds(new java.awt.Rectangle(470, 330, 90, 20));
105 jButtonNext.setText("Next");
106 jButtonNext.addMouseListener(this);
107 }
108 return jButtonNext;
109 }
110
111 /**
112 * This method initializes jTextArea
113 *
114 * @return javax.swing.JTextArea
115 */
116 private JTextArea getJTextArea() {
117 if (jTextArea == null) {
118 jTextArea = new JTextArea();
119 jTextArea.setBounds(new java.awt.Rectangle(30, 7, 642, 50));
120 jTextArea.setText("Step 1: Choose a framework archive(FAR) file. \n");
121 jTextArea.setEditable(false);
122 }
123 return jTextArea;
124 }
125
126 /**
127 * This method initializes jTextField
128 *
129 * @return javax.swing.JTextField
130 */
131 private JTextField getJTextFieldFarFile() {
132 if (jTextFieldFarFile == null) {
133 jTextFieldFarFile = new JTextField();
134 jTextFieldFarFile.setBounds(new java.awt.Rectangle(140, 80, 423, 20));
135 }
136 return jTextFieldFarFile;
137 }
138
139 /**
140 * This method initializes jButtonBrowser
141 *
142 * @return javax.swing.JButton
143 */
144 private JButton getJButtonBrowser() {
145 if (jButtonBrowser == null) {
146 jButtonBrowser = new JButton();
147 jButtonBrowser.setBounds(new java.awt.Rectangle(570, 80, 100, 20));
148 jButtonBrowser.setText("Browser...");
149 jButtonBrowser.addMouseListener(this);
150 }
151 return jButtonBrowser;
152 }
153
154 /**
155 * This method initializes jScrollPane
156 *
157 * @return javax.swing.JScrollPane
158 */
159 private JScrollPane getJScrollPane() {
160 if (jScrollPane == null) {
161 jScrollPane = new JScrollPane();
162 jScrollPane.setBounds(new java.awt.Rectangle(30, 165, 642, 140));
163 jScrollPane.setViewportView(getJTable());
164 }
165 jScrollPane.setVisible(false);
166 return jScrollPane;
167 }
168
169 /**
170 * This method initializes jTable
171 *
172 * @return javax.swing.JTable
173 */
174 private JTable getJTable() {
175 if (jTable == null) {
176 jTable = new JTable();
177 model = new PartialTableModel();
178 jTable = new JTable(model);
179 jTable.setRowHeight(20);
180 jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
181 model.addColumn("Name");
182 model.addColumn("Version");
183 model.addColumn("GUID");
184
185 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
186 }
187 jTable.setVisible(false);
188 return jTable;
189 }
190
191 public void prepareTable(List<PackageIdentification> packageList) {
192 model.setRowCount(0);
193 //
194 // Change here to get packages and platforms from FAR
195 //
196 Iterator<PackageIdentification> iter = packageList.iterator();
197 while (iter.hasNext()) {
198 String[] str = new String[3];
199 PackageIdentification item = iter.next();
200 str[0] = item.getName();
201 str[1] = item.getVersion();
202 str[2] = item.getGuid();
203 model.addRow(str);
204 }
205 }
206
207 /**
208 * This is the default constructor
209 */
210 public InstallStepOne(IFrame iFrame, boolean modal) {
211 super(iFrame, modal);
212 initialize();
213 }
214
215 /**
216 * This method initializes this
217 *
218 * @return void
219 */
220 private void initialize() {
221 this.setSize(700, 400);
222 this.setContentPane(getJContentPane());
223 this.setTitle("Install Framework Archive(FAR) - Step 1: Choose FAR file");
224 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
225 this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);
226 }
227
228 /**
229 * This method initializes jContentPane
230 *
231 * @return javax.swing.JPanel
232 */
233 private JPanel getJContentPane() {
234 if (jContentPane == null) {
235 jLabelWarning = new JLabel();
236 jLabelWarning.setBounds(new java.awt.Rectangle(30, 125, 410, 20));
237 jLabelWarning.setText("Can't install this FAR, lack following packages in current workspace");
238 jLabelWarning.setVisible(false);
239 jLabel = new JLabel();
240 jLabel.setBounds(new java.awt.Rectangle(30, 80, 97, 20));
241 jLabel.setText("Choose FAR file: ");
242 jContentPane = new JPanel();
243 jContentPane.setLayout(null);
244 jContentPane.add(getJButtonCancel(), null);
245 jContentPane.add(getJButtonNext(), null);
246 jContentPane.add(getJTextArea(), null);
247 jContentPane.add(jLabel, null);
248 jContentPane.add(getJTextFieldFarFile(), null);
249 jContentPane.add(getJButtonBrowser(), null);
250 jContentPane.add(jLabelWarning, null);
251 jContentPane.add(getJScrollPane(), null);
252 }
253 return jContentPane;
254 }
255
256 public void mouseClicked(MouseEvent e) {
257 if (e.getSource() == jButtonCancel) {
258 this.setVisible(false);
259 } else if (e.getSource() == jButtonNext) {
260 //
261 // Add some logic process here
262 //
263 File farFile = new File(jTextFieldFarFile.getText());
264 if (!farFile.exists() || !farFile.isFile()) {
265 Log.wrn("Install far", "Please choose a FAR file already exists. ");
266 return;
267 }
268
269 //
270 // Verify Far
271 //
272 JarFile jarFar;
273 try {
274 jarFar = new JarFile(farFile);
275 far = new Far(jarFar);
276
277 //
278 // Far dependency check
279 //
280 List<PackageIdentification> pkgIdList = DistributeRule.installFarCheck(far);
281
282 if (pkgIdList.size() > 0) {
283 prepareTable(pkgIdList);
284 jLabelWarning.setVisible(true);
285 jTable.setVisible(true);
286 jScrollPane.setVisible(true);
287 return;
288 }
289
290 } catch (Exception exp) {
291 Log.wrn("Install far" + exp.getMessage());
292 Log.err("Install far" + exp.getMessage());
293 }
294
295 if (stepTwo == null) {
296 stepTwo = new InstallStepTwo(this, true, this);
297 }
298 this.setVisible(false);
299
300 //
301 // Refresh table
302 //
303 stepTwo.preparePackageTable();
304 stepTwo.preparePlatformTable();
305 stepTwo.setVisible(true);
306 } else if (e.getSource() == jButtonBrowser) {
307 JFileChooser fc = new JFileChooser();
308 fc.setAcceptAllFileFilterUsed(false);
309 fc.addChoosableFileFilter(new IFileFilter(DataType.FAR_SURFACE_AREA_EXT));
310 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
311
312 int result = fc.showSaveDialog(new JPanel());
313 if (result == JFileChooser.APPROVE_OPTION) {
314 jLabelWarning.setVisible(false);
315 jTable.setVisible(false);
316 jScrollPane.setVisible(false);
317 this.jTextFieldFarFile.setText(Tools.addPathExt(fc.getSelectedFile().getPath(),
318 DataType.RETURN_TYPE_FAR_SURFACE_AREA));
319 }
320 }
321 }
322
323 public void mousePressed(MouseEvent e) {
324 // TODO Auto-generated method stub
325
326 }
327
328 public void mouseReleased(MouseEvent e) {
329 // TODO Auto-generated method stub
330
331 }
332
333 public void mouseEntered(MouseEvent e) {
334 // TODO Auto-generated method stub
335
336 }
337
338 public void mouseExited(MouseEvent e) {
339 // TODO Auto-generated method stub
340
341 }
342
343 public Far getFar() {
344 return far;
345 }
346
347 }
348
349 class PartialTableModel extends DefaultTableModel {
350 /**
351 *
352 */
353 private static final long serialVersionUID = 1L;
354
355 public boolean isCellEditable(int row, int col) {
356 switch (col) {
357 default:
358 return false;
359 }
360 }
361 }