|
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.internal.deployment.externalapp; |
|
20 |
|
21 import java.io.File; |
|
22 |
|
23 import org.eclipse.core.runtime.CoreException; |
|
24 import org.eclipse.core.runtime.IProgressMonitor; |
|
25 import org.eclipse.core.runtime.IStatus; |
|
26 import org.eclipse.core.runtime.PlatformObject; |
|
27 import org.eclipse.core.runtime.Status; |
|
28 import org.eclipse.core.runtime.jobs.ISchedulingRule; |
|
29 import org.eclipse.swt.program.Program; |
|
30 import org.eclipse.ui.IMemento; |
|
31 import org.symbian.tools.mtw.core.MTWCore; |
|
32 import org.symbian.tools.mtw.core.projects.IMTWProject; |
|
33 import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime; |
|
34 import org.symbian.tools.mtw.core.runtimes.IPackager; |
|
35 import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; |
|
36 import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; |
|
37 |
|
38 public class ExternalApplicationDeploymentType extends PlatformObject implements IDeploymentTargetType, |
|
39 IDeploymentTarget { |
|
40 |
|
41 private IMTWProject project; |
|
42 |
|
43 public IStatus deploy(IMTWProject project, IMobileWebRuntime runtime, IProgressMonitor monitor) |
|
44 throws CoreException { |
|
45 Program app = getExternalApp(project); |
|
46 IPackager packager = MTWCore.getDefault().getRuntimesManager().getPackager(project, runtime); |
|
47 File file = packager.packageApplication(project, runtime, monitor); |
|
48 if (file != null) { |
|
49 app.execute(file.toString()); |
|
50 return new Status( |
|
51 IStatus.OK, |
|
52 MTWCore.PLUGIN_ID, |
|
53 "Mobile web application was passed as an argument to external application. Please follow its prompts to complete deployment."); |
|
54 } else { |
|
55 return new Status(IStatus.ERROR, MTWCore.PLUGIN_ID, "Application packaging failed"); |
|
56 } |
|
57 } |
|
58 |
|
59 public void discoverTargets(IProgressMonitor monitor) throws CoreException { |
|
60 // Do nothing |
|
61 } |
|
62 |
|
63 public IDeploymentTarget findTarget(IMTWProject project, String id) { |
|
64 if (getExternalApp(project) != null) { |
|
65 return this; |
|
66 } else { |
|
67 return null; |
|
68 } |
|
69 } |
|
70 |
|
71 public String getDescription() { |
|
72 return getExternalApp(project).getName(); |
|
73 } |
|
74 |
|
75 private Program getExternalApp(IMTWProject project) { |
|
76 this.project = project; |
|
77 IPackager packager = MTWCore.getDefault().getRuntimesManager().getPackager(project); |
|
78 if (packager != null) { |
|
79 return Program.findProgram(packager.getFileType(project)); |
|
80 } else { |
|
81 return null; |
|
82 } |
|
83 } |
|
84 |
|
85 public String getId() { |
|
86 return "mtw.externalapp"; |
|
87 } |
|
88 |
|
89 public String getName() { |
|
90 return "Use external application"; |
|
91 } |
|
92 |
|
93 public Program getProgram() { |
|
94 return getExternalApp(project); |
|
95 } |
|
96 |
|
97 public ISchedulingRule getSchedulingRule(IDeploymentTarget target) { |
|
98 return null; |
|
99 } |
|
100 |
|
101 public IDeploymentTarget[] getTargets(IMTWProject project) { |
|
102 if (getExternalApp(project) != null) { |
|
103 return new IDeploymentTarget[] { this }; |
|
104 } else { |
|
105 return null; |
|
106 } |
|
107 } |
|
108 |
|
109 public void load(IMemento memento) { |
|
110 // Do nothing |
|
111 } |
|
112 |
|
113 public void save(IMemento memento) { |
|
114 // Do nothing |
|
115 } |
|
116 |
|
117 public boolean targetsDiscovered() { |
|
118 return true; |
|
119 } |
|
120 } |