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