|
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; |
|
20 |
|
21 import org.eclipse.core.runtime.CoreException; |
|
22 import org.eclipse.core.runtime.IProgressMonitor; |
|
23 import org.eclipse.core.runtime.IStatus; |
|
24 import org.eclipse.jface.resource.ImageDescriptor; |
|
25 import org.eclipse.ui.IMemento; |
|
26 import org.eclipse.ui.model.IWorkbenchAdapter; |
|
27 import org.eclipse.ui.model.WorkbenchAdapter; |
|
28 import org.symbian.tools.mtw.core.projects.IMTWProject; |
|
29 import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime; |
|
30 import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; |
|
31 import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetProvider; |
|
32 |
|
33 public class DeploymentTargetWrapper implements IDeploymentTarget { |
|
34 public class TargetWorkbenchAdapter extends WorkbenchAdapter { |
|
35 @Override |
|
36 public String getLabel(Object object) { |
|
37 return getName(); |
|
38 } |
|
39 |
|
40 @Override |
|
41 public ImageDescriptor getImageDescriptor(Object object) { |
|
42 return provider.getImageDescriptor(); |
|
43 } |
|
44 } |
|
45 |
|
46 private final DeploymentTargetProviderDescriptor provider; |
|
47 private final IDeploymentTarget target; |
|
48 |
|
49 public DeploymentTargetWrapper(IDeploymentTarget target, DeploymentTargetProviderDescriptor provider) { |
|
50 this.target = target; |
|
51 this.provider = provider; |
|
52 } |
|
53 |
|
54 public IStatus deploy(IMTWProject project, IMobileWebRuntime runtime, IProgressMonitor monitor) |
|
55 throws CoreException { |
|
56 return target.deploy(project, runtime, monitor); |
|
57 } |
|
58 |
|
59 @Override |
|
60 public boolean equals(Object obj) { |
|
61 if (this == obj) { |
|
62 return true; |
|
63 } |
|
64 if (obj == null) { |
|
65 return false; |
|
66 } |
|
67 if (getClass() != obj.getClass()) { |
|
68 return false; |
|
69 } |
|
70 DeploymentTargetWrapper other = (DeploymentTargetWrapper) obj; |
|
71 if (target == null) { |
|
72 if (other.target != null) { |
|
73 return false; |
|
74 } |
|
75 } else if (!target.equals(other.target)) { |
|
76 return false; |
|
77 } |
|
78 return true; |
|
79 } |
|
80 |
|
81 public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { |
|
82 Object ad = target.getAdapter(adapter); |
|
83 if (ad == null && adapter.equals(IWorkbenchAdapter.class)) { |
|
84 return new TargetWorkbenchAdapter(); |
|
85 } |
|
86 return ad; |
|
87 } |
|
88 |
|
89 public int getCategory() { |
|
90 return provider.getPriority() * 0xFFFF + (provider.getId().hashCode() & 0xFFFF); |
|
91 } |
|
92 |
|
93 public String getId() { |
|
94 return target.getId(); |
|
95 } |
|
96 |
|
97 public String getName() { |
|
98 return target.getName(); |
|
99 } |
|
100 |
|
101 public String getProviderId() { |
|
102 return provider.getId(); |
|
103 } |
|
104 |
|
105 @Override |
|
106 public int hashCode() { |
|
107 final int prime = 31; |
|
108 int result = 1; |
|
109 result = prime * result + ((target == null) ? 0 : target.hashCode()); |
|
110 return result; |
|
111 } |
|
112 |
|
113 public void save(IMemento child) { |
|
114 target.save(child); |
|
115 } |
|
116 |
|
117 public void load(IMemento child) { |
|
118 target.load(child); |
|
119 } |
|
120 |
|
121 public IDeploymentTargetProvider getProvider() { |
|
122 return provider; |
|
123 } |
|
124 |
|
125 public IDeploymentTarget getActualTarget() { |
|
126 return target; |
|
127 } |
|
128 } |