]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/PkgInstallTypeChooser.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / PackageEditor / src / org / tianocore / packaging / PkgInstallTypeChooser.java
1 /** @file
2 Java class PkgInstallTypeChooser is GUI for upgrade package installation.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13 package org.tianocore.packaging;
14
15 import java.awt.Dimension;
16 import java.awt.Toolkit;
17 import java.awt.event.MouseEvent;
18 import java.awt.event.MouseListener;
19 import java.io.File;
20 import java.util.List;
21 import java.util.ListIterator;
22 import java.util.Vector;
23
24 import javax.swing.JFileChooser;
25 import javax.swing.JFrame;
26 import javax.swing.JOptionPane;
27 import javax.swing.JPanel;
28 import javax.swing.JDialog;
29 import javax.swing.JRadioButton;
30 import javax.swing.JButton;
31
32 import org.tianocore.PackageListDocument;
33 import javax.swing.JList;
34 import javax.swing.JTextField;
35 import javax.swing.JScrollPane;
36
37 /**
38 GUI for speicial circumstances of package installation.
39
40 @since PackageEditor 1.0
41 **/
42 public class PkgInstallTypeChooser extends JFrame implements MouseListener {
43
44 final static long serialVersionUID = 0;
45
46 static JFrame frame;
47
48 private JPanel jContentPane = null;
49
50 private JRadioButton jRadioButton = null;
51
52 private JRadioButton jRadioButton1 = null;
53
54 private JButton jButton = null;
55
56 private JButton jButton1 = null;
57
58 private String pn = null;
59
60 ///
61 /// list of package info from db file
62 ///
63 private List<PackageListDocument.PackageList.Package> dd = null;
64
65 private String wk = null;
66
67 private JList jList = null;
68
69 private JScrollPane jScrollPane = null;
70
71 private JTextField jTextField = null;
72
73 private JButton jButton2 = null;
74
75 private JFileChooser chooser = null;
76
77 /**
78 This is the default constructor
79 **/
80 public PkgInstallTypeChooser(String pkgName, String wkSpace, List<PackageListDocument.PackageList.Package> destDir) {
81 super();
82 pn = pkgName;
83 dd = destDir;
84 wk = wkSpace;
85 initialize();
86 }
87
88 /**
89 This method initializes this
90
91 @return void
92 **/
93 private void initialize() {
94 this.setSize(359, 328);
95 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
96 this.setTitle("Chooser Installation Type");
97 this.setContentPane(getJContentPane());
98 this.centerWindow();
99 this.insertList();
100 }
101
102 /**
103 Start the window at the center of screen
104
105 **/
106 protected void centerWindow(int intWidth, int intHeight) {
107 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
108 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
109 }
110
111 /**
112 Start the window at the center of screen
113
114 **/
115 protected void centerWindow() {
116 centerWindow(this.getSize().width, this.getSize().height);
117 }
118
119 /**
120 initialize jList with package info. from db file
121 **/
122 private void insertList() {
123
124 Vector<String> v = new Vector<String>();
125
126 ListIterator lpi = dd.listIterator();
127 while (lpi.hasNext()) {
128 PackageListDocument.PackageList.Package p = (PackageListDocument.PackageList.Package) lpi.next();
129 v.addElement(p.getPackageNameArray(0).getStringValue() + " " + p.getVersionArray(0) + " "
130 + p.getGuidArray(0).getStringValue());
131 }
132 jList.setListData(v);
133 }
134
135 /**
136 This method initializes jContentPane
137
138 @return javax.swing.JPanel
139 **/
140 private JPanel getJContentPane() {
141 if (jContentPane == null) {
142 jContentPane = new JPanel();
143 jContentPane.setLayout(null);
144 jContentPane.add(getJRadioButton(), null);
145 jContentPane.add(getJRadioButton1(), null);
146 jContentPane.add(getJButton(), null);
147 jContentPane.add(getJButton1(), null);
148 jContentPane.add(getJScrollPane(), null);
149 jContentPane.add(getJTextField(), null);
150 jContentPane.add(getJButton2(), null);
151 }
152 return jContentPane;
153 }
154
155
156 private JRadioButton getJRadioButton() {
157 if (jRadioButton == null) {
158 jRadioButton = new JRadioButton();
159 jRadioButton.setBounds(new java.awt.Rectangle(17, 39, 186, 21));
160 jRadioButton.setSelected(true);
161 jRadioButton.setText("Reinstall Existing Package");
162 jRadioButton.addMouseListener(new java.awt.event.MouseAdapter() {
163 public void mouseClicked(java.awt.event.MouseEvent e) {
164 if (jRadioButton.isSelected()) {
165 jRadioButton1.setSelected(false);
166 jButton2.setEnabled(false);
167 jTextField.setEnabled(false);
168 jList.setEnabled(true);
169 return;
170 }
171 if (jRadioButton1.isSelected()) {
172 jRadioButton.setSelected(true);
173 jRadioButton1.setSelected(false);
174 jList.setEnabled(true);
175 return;
176 }
177
178 }
179 });
180 }
181 return jRadioButton;
182 }
183
184 private JRadioButton getJRadioButton1() {
185 if (jRadioButton1 == null) {
186 jRadioButton1 = new JRadioButton();
187 jRadioButton1.setBounds(new java.awt.Rectangle(17, 155, 176, 21));
188 jRadioButton1.setText("Install to Directory");
189 jRadioButton1.addMouseListener(new java.awt.event.MouseAdapter() {
190 public void mouseClicked(java.awt.event.MouseEvent e) {
191 if (jRadioButton1.isSelected()) {
192 jRadioButton.setSelected(false);
193 jList.setEnabled(false);
194 jButton2.setEnabled(true);
195 jTextField.setEnabled(true);
196 return;
197 }
198 if (jRadioButton.isSelected()) {
199 jRadioButton1.setSelected(true);
200 jRadioButton.setSelected(false);
201 jButton2.setEnabled(true);
202 jTextField.setEnabled(true);
203 return;
204 }
205 }
206 });
207 }
208 return jRadioButton1;
209 }
210
211 private JButton getJButton() {
212 if (jButton == null) {
213 jButton = new JButton();
214 jButton.setPreferredSize(new java.awt.Dimension(34, 20));
215 jButton.setSize(new java.awt.Dimension(76, 20));
216 jButton.setText("Ok");
217 jButton.setLocation(new java.awt.Point(141, 241));
218 jButton.addMouseListener(new java.awt.event.MouseAdapter() {
219 public void mouseClicked(java.awt.event.MouseEvent e) {
220 try {
221 int i = -1;
222 //
223 // user selects replace existing package
224 //
225 if (jRadioButton.isSelected()) {
226 int j = jList.getSelectedIndex();
227 if (j == -1) {
228 JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
229 "Please Select One Package to Replace!");
230 return;
231 }
232 //
233 // the sequence of jList is the same with List
234 //
235 String destDir = dd.get(j).getPathArray(0).getStringValue();
236 ForceInstallPkg f = new ForceInstallPkg(pn, wk);
237 //
238 // record the package info. to be replaced
239 //
240 f.setOldVersion(dd.get(j).getVersionArray(0));
241 f.setOldGuid(dd.get(j).getGuidArray(0).getStringValue());
242 i = f.install(wk + System.getProperty("file.separator") + destDir);
243 } else {
244 //
245 // user selects install to another directory
246 //
247 File f = new File(wk + System.getProperty("file.separator") + FrameworkPkg.dbConfigFile);
248 if (new DbFileContents(f).checkDir(jTextField.getText().substring(wk.length() + 1)) != 0) {
249 throw new DirSame();
250 }
251 i = new ForceInstallPkg(pn, wk).install(jTextField.getText());
252 }
253 if (i == 0) {
254 JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Package " + pn
255 + " Installed Successfully!");
256 }
257 } catch (DirSame ds) {
258 System.out.println(ds.toString());
259 JOptionPane.showMessageDialog(frame,
260 "Another Package Exists There, Please Select Another Directory!");
261 } catch (Exception ee) {
262 System.out.println(ee.toString());
263 }
264 }
265 });
266 }
267 return jButton;
268 }
269
270 /**
271 * This method initializes jButton1
272 *
273 * @return javax.swing.JButton
274 */
275 private JButton getJButton1() {
276 if (jButton1 == null) {
277 jButton1 = new JButton();
278 jButton1.setBounds(new java.awt.Rectangle(238, 241, 78, 20));
279 jButton1.setText("Cancel");
280 jButton1.setPreferredSize(new java.awt.Dimension(34, 20));
281 jButton1.addMouseListener(this);
282 }
283 return jButton1;
284 }
285
286 public void mouseClicked(MouseEvent arg0) {
287 // TODO Auto-generated method stub
288 this.dispose();
289 }
290
291 public void mouseEntered(MouseEvent arg0) {
292 // TODO Auto-generated method stub
293
294 }
295
296 public void mouseExited(MouseEvent arg0) {
297 // TODO Auto-generated method stub
298
299 }
300
301 public void mousePressed(MouseEvent arg0) {
302 // TODO Auto-generated method stub
303
304 }
305
306 public void mouseReleased(MouseEvent arg0) {
307 // TODO Auto-generated method stub
308
309 }
310
311 private JScrollPane getJScrollPane() {
312 if (jScrollPane == null) {
313 jScrollPane = new JScrollPane();
314 jScrollPane.setBounds(new java.awt.Rectangle(22, 68, 318, 58));
315 jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
316 jScrollPane.setViewportView(getJList());
317 }
318 return jScrollPane;
319 }
320
321 private JList getJList() {
322 if (jList == null) {
323 jList = new JList();
324
325 jList.setBounds(new java.awt.Rectangle(22, 68, 318, 58));
326
327 }
328 return jList;
329 }
330
331 /**
332 * This method initializes jTextField
333 *
334 * @return javax.swing.JTextField
335 */
336 private JTextField getJTextField() {
337 if (jTextField == null) {
338 jTextField = new JTextField();
339 jTextField.setBounds(new java.awt.Rectangle(22, 184, 224, 20));
340 jTextField.setEnabled(false);
341 jTextField.setText(wk);
342 }
343 return jTextField;
344 }
345
346 private JButton getJButton2() {
347 if (jButton2 == null) {
348 jButton2 = new JButton();
349 jButton2.setLocation(new java.awt.Point(259, 183));
350 jButton2.setText("Browse");
351 jButton2.setEnabled(false);
352 jButton2.setSize(new java.awt.Dimension(81, 20));
353 jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
354 public void mouseClicked(java.awt.event.MouseEvent e) {
355 if (chooser == null) {
356 chooser = new JFileChooser(wk);
357 }
358 chooser.setMultiSelectionEnabled(false);
359 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
360
361 int retval = chooser.showOpenDialog(frame);
362 if (retval == JFileChooser.APPROVE_OPTION) {
363 jTextField.setText(chooser.getSelectedFile().getPath());
364
365 }
366
367 }
368 });
369 }
370 return jButton2;
371 }
372
373 } // @jve:decl-index=0:visual-constraint="134,45"