]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/CreateMdkPkg/src/org/tianocore/packaging/workspace/ui/SelectDestinationDirectory.java
Initial import.
[mirror_edk2.git] / Tools / Source / CreateMdkPkg / src / org / tianocore / packaging / workspace / ui / SelectDestinationDirectory.java
1 /** @file
2
3 The file is used to show a Select Destination Directory page in
4 the process of setup
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 package org.tianocore.packaging.workspace.ui;
18
19 import java.awt.event.ActionEvent;
20 import java.awt.event.ActionListener;
21 import java.awt.event.WindowEvent;
22
23 import javax.swing.JButton;
24 import javax.swing.JFileChooser;
25 import javax.swing.JLabel;
26 import javax.swing.JOptionPane;
27 import javax.swing.JPanel;
28 import javax.swing.JTextArea;
29 import javax.swing.JTextField;
30
31 import org.tianocore.common.Log;
32 import org.tianocore.packaging.common.ui.IFrame;
33 import org.tianocore.packaging.workspace.command.InstallWorkspace;
34
35 /**
36 The class is used to show a Select Destination Directory page in
37 the process of setup
38
39 @since CreateMdkPkg 1.0
40
41 **/
42 public class SelectDestinationDirectory extends IFrame implements ActionListener {
43
44 ///
45 /// Define class Serial Version UID
46 ///
47 private static final long serialVersionUID = -2924500118774744205L;
48
49 //
50 // Define class members
51 //
52 private JPanel jContentPane = null;
53
54 private JTextArea jTextArea = null;
55
56 private JTextArea jTextArea1 = null;
57
58 private JPanel jPanel = null;
59
60 private JButton jButtonBack = null;
61
62 private JButton jButtonNext = null;
63
64 private JButton jButtonCancel = null;
65
66 private JLabel jLabel = null;
67
68 private JLabel jLabel1 = null;
69
70 private JTextField jTextFieldInstallDir = null;
71
72 private JButton jButtonBrowse = null;
73
74 private JLabel jLabel2 = null;
75
76 private LicenseAgreement la = null;
77
78 /**
79 This method initializes jTextArea
80
81 @return javax.swing.JTextArea jTextArea
82
83 **/
84 private JTextArea getJTextArea() {
85 if (jTextArea == null) {
86 jTextArea = new JTextArea();
87 jTextArea.setLocation(new java.awt.Point(0, 0));
88 jTextArea.setText(" Select Destination Directory");
89 jTextArea.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 14));
90 jTextArea.setEditable(false);
91 jTextArea.setSize(new java.awt.Dimension(495, 20));
92 }
93 return jTextArea;
94 }
95
96 /**
97 This method initializes jTextArea1
98
99 @return javax.swing.JTextArea jTextArea1
100
101 **/
102 private JTextArea getJTextArea1() {
103 if (jTextArea1 == null) {
104 jTextArea1 = new JTextArea();
105 jTextArea1.setLocation(new java.awt.Point(0, 20));
106 jTextArea1.setText(" Where should MDK package be installed?");
107 jTextArea1.setEditable(false);
108 jTextArea1.setSize(new java.awt.Dimension(495, 35));
109 }
110 return jTextArea1;
111 }
112
113 /**
114 This method initializes jPanel
115
116 @return javax.swing.JPanel jPanel
117
118 **/
119 private JPanel getJPanel() {
120 if (jPanel == null) {
121 jLabel2 = new JLabel();
122 jLabel2.setText("At least 10 MB of free disk space is required");
123 jLabel2.setLocation(new java.awt.Point(30, 225));
124 jLabel2.setSize(new java.awt.Dimension(290, 20));
125 jLabel1 = new JLabel();
126 jLabel1.setText("To continue, click Next. If you wuold like to select different folder, click Browse.");
127 jLabel1.setLocation(new java.awt.Point(30, 55));
128 jLabel1.setSize(new java.awt.Dimension(435, 20));
129 jLabel = new JLabel();
130 jLabel.setText("Setup will install MDK package into the following folders:");
131 jLabel.setLocation(new java.awt.Point(30, 15));
132 jLabel.setSize(new java.awt.Dimension(435, 20));
133 jPanel = new JPanel();
134 jPanel.setLayout(null);
135 jPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
136 jPanel.setSize(new java.awt.Dimension(494, 251));
137 jPanel.setLocation(new java.awt.Point(0, 55));
138 jPanel.add(jLabel, null);
139 jPanel.add(jLabel1, null);
140 jPanel.add(getJTextField(), null);
141 jPanel.add(getJButtonBrowse(), null);
142 jPanel.add(jLabel2, null);
143 }
144 return jPanel;
145 }
146
147 /**
148 This method initializes jButtonBack
149
150 @return javax.swing.JButton jButtonBack
151
152 **/
153 private JButton getJButtonBack() {
154 if (jButtonBack == null) {
155 jButtonBack = new JButton();
156 jButtonBack.setText("Back");
157 jButtonBack.setSize(new java.awt.Dimension(90, 20));
158 jButtonBack.setLocation(new java.awt.Point(200, 315));
159 jButtonBack.setMnemonic('B');
160 jButtonBack.addActionListener(this);
161 }
162 return jButtonBack;
163 }
164
165 /**
166 This method initializes jButtonNext
167
168 @return javax.swing.JButton jButtonNext
169
170 **/
171 private JButton getJButtonNext() {
172 if (jButtonNext == null) {
173 jButtonNext = new JButton();
174 jButtonNext.setText("Next");
175 jButtonNext.setBounds(new java.awt.Rectangle(292, 315, 90, 20));
176 jButtonNext.setEnabled(true);
177 jButtonNext.setMnemonic('N');
178 jButtonNext.addActionListener(this);
179 }
180 return jButtonNext;
181 }
182
183 /**
184 This method initializes jButtonCancel
185
186 @return javax.swing.JButton jButtonCancel
187
188 **/
189 private JButton getJButtonCancel() {
190 if (jButtonCancel == null) {
191 jButtonCancel = new JButton();
192 jButtonCancel.setText("Cancel");
193 jButtonCancel.setBounds(new java.awt.Rectangle(390, 315, 90, 20));
194 jButtonCancel.setMnemonic('C');
195 jButtonCancel.addActionListener(this);
196 }
197 return jButtonCancel;
198 }
199
200 /**
201 This method initializes jTextFieldInstallDir
202
203 @return javax.swing.JTextField jTextFieldInstallDir
204
205 **/
206 private JTextField getJTextField() {
207 if (jTextFieldInstallDir == null) {
208 jTextFieldInstallDir = new JTextField();
209 jTextFieldInstallDir.setLocation(new java.awt.Point(30, 90));
210 jTextFieldInstallDir.setSize(new java.awt.Dimension(320, 20));
211 jTextFieldInstallDir.setText("C:\\MyWorkspace");
212 }
213 return jTextFieldInstallDir;
214 }
215
216 /**
217 This method initializes jButtonBrowse
218
219 @return javax.swing.JButton jButtonBrowse
220
221 **/
222 private JButton getJButtonBrowse() {
223 if (jButtonBrowse == null) {
224 jButtonBrowse = new JButton();
225 jButtonBrowse.setText("Browse");
226 jButtonBrowse.setSize(new java.awt.Dimension(90, 20));
227 jButtonBrowse.setLocation(new java.awt.Point(370, 90));
228 jButtonBrowse.addActionListener(this);
229 }
230 return jButtonBrowse;
231 }
232
233 /**
234 Main class, used for test
235
236 @param args
237
238 **/
239 public static void main(String[] args) {
240 SelectDestinationDirectory sdd = new SelectDestinationDirectory();
241 sdd.setVisible(true);
242 }
243
244 /**
245 This is the default constructor
246
247 **/
248 public SelectDestinationDirectory() {
249 super();
250 init();
251 }
252
253 /**
254 This is the override constructor
255
256 @param licenseagreement The input data of licenseagreement
257
258 **/
259 public SelectDestinationDirectory(LicenseAgreement licenseagreement) {
260 super();
261 init();
262 la = licenseagreement;
263 }
264
265 /**
266 This method initializes this
267
268 **/
269 private void init() {
270 this.setSize(500, 390);
271 this.setTitle("Setup - Select Destination Directory");
272 this.setContentPane(getJContentPane());
273 this.centerWindow();
274 this.getRootPane().setDefaultButton(jButtonNext);
275 }
276
277 /**
278 This method initializes jContentPane
279
280 @return javax.swing.JPanel jContentPane
281
282 **/
283 private JPanel getJContentPane() {
284 if (jContentPane == null) {
285 jContentPane = new JPanel();
286 jContentPane.setLayout(null);
287 jContentPane.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
288 jContentPane.add(getJTextArea(), null);
289 jContentPane.add(getJTextArea1(), null);
290 jContentPane.add(getJPanel(), null);
291 jContentPane.add(getJButtonBack(), null);
292 jContentPane.add(getJButtonNext(), null);
293 jContentPane.add(getJButtonCancel(), null);
294 }
295 return jContentPane;
296 }
297
298 /* (non-Javadoc)
299 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
300 *
301 * Override actionPerformed to listen all actions
302 *
303 */
304 public void actionPerformed(ActionEvent arg0) {
305 Object obj = arg0.getSource();
306
307 if (obj == jButtonBack) {
308 this.setVisible(false);
309 la.setVisible(true);
310 }
311
312 //
313 // Show next page if click button Next
314 //
315 if (obj == jButtonNext) {
316 if (createWorkspace(jTextFieldInstallDir.getText())) {
317 if (initWorkspace(jTextFieldInstallDir.getText())) {
318 this.setVisible(false);
319 Finish f = new Finish(jTextFieldInstallDir.getText());
320 f.setVisible(true);
321 }
322 }
323 }
324
325 if (obj == jButtonCancel) {
326 this.onExit();
327 }
328
329 if (obj == jButtonBrowse) {
330 JFileChooser fc = new JFileChooser();
331 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
332 int result = fc.showOpenDialog(new JPanel());
333 if (result == JFileChooser.APPROVE_OPTION) {
334 jTextFieldInstallDir.setText(fc.getCurrentDirectory().toString() + System.getProperty("file.separator")
335 + fc.getSelectedFile().getName());
336 }
337 }
338 }
339
340 /**
341 Create workspace to target dir
342
343 @param strInstallDir The install target dir
344 @retval true - Create success
345 @retval false - Create fail
346
347 **/
348 private boolean createWorkspace(String strInstallDir) {
349 boolean bolCreateDirectory = true;
350 int intResult;
351
352 //
353 //Check if the Install Dir exists
354 //
355 Log.log("is Exist Install Dir");
356 if (InstallWorkspace.isExistInstallDir(strInstallDir)) {
357 intResult = JOptionPane.showConfirmDialog(null, strInstallDir + " already exists, continue anyway?",
358 "Override", JOptionPane.YES_NO_OPTION);
359 if (intResult != JOptionPane.YES_OPTION) {
360 return false;
361 } else {
362 bolCreateDirectory = false;
363 }
364 }
365
366 //
367 //Create the directory
368 //
369 Log.log("Create Directory");
370 if (bolCreateDirectory) {
371 if (!InstallWorkspace.createInstallDir(strInstallDir)) {
372 intResult = JOptionPane.showConfirmDialog(null, "Cannot create direcotry " + strInstallDir
373 + " in system. Click OK to exist.", "Error",
374 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
375 return false;
376 }
377 }
378 return true;
379 }
380
381 /**
382 Init created workspace
383
384 @param strInstallDir The dir of workspace
385 @retval true - Init Success
386 @retval false - Init fail
387
388 **/
389 private boolean initWorkspace(String strInstallDir) {
390 String strJarFile = System.getProperty("user.dir") + System.getProperty("file.separator") + "CreateMdkPkg.jar";
391
392 //
393 //Install package
394 //
395 Log.log("Install Package");
396 try {
397 if (!InstallWorkspace.installPackage(strInstallDir, strJarFile)) {
398 JOptionPane.showConfirmDialog(null, "Cannot intall package in system. Click OK to exist.", "Error",
399 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
400 return false;
401 }
402 } catch (Exception e) {
403 e.printStackTrace();
404 }
405
406 //
407 //Update framework database
408 //
409 Log.log("Set Framework Database");
410 if (!InstallWorkspace.setFrameworkDatabase()) {
411 JOptionPane.showConfirmDialog(null, "Cannot create workspace database in system. Click OK to exist.",
412 "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
413 return false;
414 }
415
416 //
417 //Set System Environment
418 //
419 Log.log("Set System Environment");
420 if (!InstallWorkspace.setSystemEnvironment()) {
421 JOptionPane.showConfirmDialog(null, "Cannot set WORKSPACE variable in system. Click OK to exist.", "Error",
422 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
423 return false;
424 }
425
426 //
427 //Set Tool Chain Path
428 //
429 Log.log("Set Tool Chain Path");
430 if (!InstallWorkspace.setToolChainPath()) {
431 JOptionPane.showConfirmDialog(null, "Cannot set Tool Chain path variable in system. Click OK to exist.",
432 "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
433 return false;
434 }
435
436 //
437 //Install tool chain
438 //
439 Log.log("Set Tool Chain");
440 if (!InstallWorkspace.setToolChain()) {
441 JOptionPane.showConfirmDialog(null, "Cannot set Tool Chain in system. Click OK to exist.", "Error",
442 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
443 return false;
444 }
445
446 //
447 //Delete setup files
448 //
449 Log.log("Delete Setup Files");
450 try {
451 InstallWorkspace.delSetupPackage(strInstallDir + System.getProperty("file.separator") + "org");
452 } catch (Exception e) {
453 e.printStackTrace();
454 Log.log(e.getMessage());
455 }
456
457 return true;
458 }
459
460 /* (non-Javadoc)
461 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
462 *
463 * Override windowClosing to show confirm quit dialog
464 *
465 */
466 public void windowClosing(WindowEvent arg0) {
467 this.onExit();
468 }
469 }