1 /** |
|
2 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 */ |
|
19 package org.symbian.tools.mtw.ui.commands; |
|
20 |
|
21 import java.lang.reflect.InvocationTargetException; |
|
22 |
|
23 import org.eclipse.core.commands.AbstractHandler; |
|
24 import org.eclipse.core.commands.ExecutionEvent; |
|
25 import org.eclipse.core.commands.ExecutionException; |
|
26 import org.eclipse.core.runtime.IProgressMonitor; |
|
27 import org.eclipse.jface.dialogs.MessageDialog; |
|
28 import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
|
29 import org.eclipse.jface.operation.IRunnableWithProgress; |
|
30 import org.eclipse.jface.wizard.WizardDialog; |
|
31 import org.eclipse.ui.IPageLayout; |
|
32 import org.eclipse.ui.IWorkbenchWindow; |
|
33 import org.eclipse.ui.PartInitException; |
|
34 import org.eclipse.ui.handlers.HandlerUtil; |
|
35 import org.symbian.tools.mtw.core.MTWCore; |
|
36 import org.symbian.tools.mtw.core.projects.IMTWProject; |
|
37 import org.symbian.tools.mtw.ui.UIUtils; |
|
38 import org.symbian.tools.mtw.ui.deployment.DeployWizard; |
|
39 |
|
40 /** |
|
41 * Our sample handler extends AbstractHandler, an IHandler base class. |
|
42 * @see org.eclipse.core.commands.IHandler |
|
43 * @see org.eclipse.core.commands.AbstractHandler |
|
44 */ |
|
45 public class DeployHandler extends AbstractHandler { |
|
46 /** |
|
47 * The constructor. |
|
48 */ |
|
49 public DeployHandler() { |
|
50 } |
|
51 |
|
52 /** |
|
53 * the command has been executed, so extract extract the needed information |
|
54 * from the application context. |
|
55 */ |
|
56 public Object execute(ExecutionEvent event) throws ExecutionException { |
|
57 final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); |
|
58 |
|
59 final IMTWProject project = UIUtils.getProjectFromCommandContext(event); |
|
60 if (project != null) { |
|
61 window.getActivePage().saveAllEditors(true); |
|
62 if (validate(project, window)) { |
|
63 new WizardDialog(window.getShell(), new DeployWizard(project)).open(); |
|
64 } |
|
65 } |
|
66 |
|
67 return null; |
|
68 } |
|
69 |
|
70 private boolean validate(final IMTWProject project, final IWorkbenchWindow window) { |
|
71 final boolean[] retvalue = { false }; |
|
72 final ProgressMonitorDialog dialog = new ProgressMonitorDialog(window.getShell()); |
|
73 try { |
|
74 dialog.run(true, true, new IRunnableWithProgress() { |
|
75 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { |
|
76 retvalue[0] = project.validate(monitor); |
|
77 } |
|
78 }); |
|
79 } catch (InvocationTargetException e) { |
|
80 MTWCore.log(null, e); |
|
81 } catch (InterruptedException e) { |
|
82 MTWCore.log(null, e); |
|
83 } |
|
84 if (!retvalue[0]) { |
|
85 retvalue[0] = MessageDialog.openQuestion(window.getShell(), "Deploying Mobile Web Project", |
|
86 String.format("Project %s has errors. Are you sure you want to deploy it?", project.getName())); |
|
87 if (!retvalue[0]) { |
|
88 try { |
|
89 window.getActivePage().showView(IPageLayout.ID_PROBLEM_VIEW); |
|
90 } catch (PartInitException e) { |
|
91 MTWCore.log(null, e); |
|
92 } |
|
93 } |
|
94 } |
|
95 return retvalue[0]; |
|
96 } |
|
97 |
|
98 } |
|