3 The file is used to show a Select Destination Directory page in
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
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.
17 package org
.tianocore
.packaging
.workspace
.ui
;
19 import java
.awt
.event
.ActionEvent
;
20 import java
.awt
.event
.ActionListener
;
21 import java
.awt
.event
.WindowEvent
;
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
;
31 import org
.tianocore
.common
.Log
;
32 import org
.tianocore
.packaging
.common
.ui
.IFrame
;
33 import org
.tianocore
.packaging
.workspace
.command
.InstallWorkspace
;
36 The class is used to show a Select Destination Directory page in
39 @since CreateMdkPkg 1.0
42 public class SelectDestinationDirectory
extends IFrame
implements ActionListener
{
45 /// Define class Serial Version UID
47 private static final long serialVersionUID
= -2924500118774744205L;
50 // Define class members
52 private JPanel jContentPane
= null;
54 private JTextArea jTextArea
= null;
56 private JTextArea jTextArea1
= null;
58 private JPanel jPanel
= null;
60 private JButton jButtonBack
= null;
62 private JButton jButtonNext
= null;
64 private JButton jButtonCancel
= null;
66 private JLabel jLabel
= null;
68 private JLabel jLabel1
= null;
70 private JTextField jTextFieldInstallDir
= null;
72 private JButton jButtonBrowse
= null;
74 private JLabel jLabel2
= null;
76 private LicenseAgreement la
= null;
79 This method initializes jTextArea
81 @return javax.swing.JTextArea jTextArea
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));
97 This method initializes jTextArea1
99 @return javax.swing.JTextArea jTextArea1
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));
114 This method initializes jPanel
116 @return javax.swing.JPanel jPanel
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);
148 This method initializes jButtonBack
150 @return javax.swing.JButton jButtonBack
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);
166 This method initializes jButtonNext
168 @return javax.swing.JButton jButtonNext
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);
184 This method initializes jButtonCancel
186 @return javax.swing.JButton jButtonCancel
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);
197 return jButtonCancel
;
201 This method initializes jTextFieldInstallDir
203 @return javax.swing.JTextField jTextFieldInstallDir
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");
213 return jTextFieldInstallDir
;
217 This method initializes jButtonBrowse
219 @return javax.swing.JButton jButtonBrowse
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);
230 return jButtonBrowse
;
234 Main class, used for test
239 public static void main(String
[] args
) {
240 SelectDestinationDirectory sdd
= new SelectDestinationDirectory();
241 sdd
.setVisible(true);
245 This is the default constructor
248 public SelectDestinationDirectory() {
254 This is the override constructor
256 @param licenseagreement The input data of licenseagreement
259 public SelectDestinationDirectory(LicenseAgreement licenseagreement
) {
262 la
= licenseagreement
;
266 This method initializes this
269 private void init() {
270 this.setSize(500, 390);
271 this.setTitle("Setup - Select Destination Directory");
272 this.setContentPane(getJContentPane());
274 this.getRootPane().setDefaultButton(jButtonNext
);
278 This method initializes jContentPane
280 @return javax.swing.JPanel jContentPane
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);
299 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
301 * Override actionPerformed to listen all actions
304 public void actionPerformed(ActionEvent arg0
) {
305 Object obj
= arg0
.getSource();
307 if (obj
== jButtonBack
) {
308 this.setVisible(false);
313 // Show next page if click button Next
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());
325 if (obj
== jButtonCancel
) {
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());
341 Create workspace to target dir
343 @param strInstallDir The install target dir
344 @retval true - Create success
345 @retval false - Create fail
348 private boolean createWorkspace(String strInstallDir
) {
349 boolean bolCreateDirectory
= true;
353 //Check if the Install Dir exists
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
) {
362 bolCreateDirectory
= false;
367 //Create the directory
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
);
382 Init created workspace
384 @param strInstallDir The dir of workspace
385 @retval true - Init Success
386 @retval false - Init fail
389 private boolean initWorkspace(String strInstallDir
) {
390 String strJarFile
= System
.getProperty("user.dir") + System
.getProperty("file.separator") + "CreateMdkPkg.jar";
395 Log
.log("Install Package");
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
);
402 } catch (Exception e
) {
407 //Update framework database
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
);
417 //Set System Environment
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
);
427 //Set Tool Chain Path
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
);
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
);
449 Log
.log("Delete Setup Files");
451 InstallWorkspace
.delSetupPackage(strInstallDir
+ System
.getProperty("file.separator") + "org");
452 } catch (Exception e
) {
454 Log
.log(e
.getMessage());
461 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
463 * Override windowClosing to show confirm quit dialog
466 public void windowClosing(WindowEvent arg0
) {