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.swt.graphics.FontData; |
|
26 import org.eclipse.swt.graphics.RGB; |
|
27 import org.eclipse.ui.IMemento; |
|
28 import org.eclipse.ui.model.IWorkbenchAdapter; |
|
29 import org.eclipse.ui.model.IWorkbenchAdapter2; |
|
30 import org.symbian.tools.mtw.core.projects.IMTWProject; |
|
31 import org.symbian.tools.mtw.core.runtimes.IPackager; |
|
32 import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; |
|
33 |
|
34 public class DeploymentTargetWrapper implements IDeploymentTarget { |
|
35 public class WorkbenchAdapter2Wrapper implements IWorkbenchAdapter2 { |
|
36 private final IWorkbenchAdapter2 adapter; |
|
37 |
|
38 public WorkbenchAdapter2Wrapper(IWorkbenchAdapter2 adapter) { |
|
39 this.adapter = adapter; |
|
40 } |
|
41 |
|
42 public RGB getForeground(Object element) { |
|
43 return adapter.getForeground(((DeploymentTargetWrapper) element).getActualTarget()); |
|
44 } |
|
45 |
|
46 public RGB getBackground(Object element) { |
|
47 return adapter.getBackground(((DeploymentTargetWrapper) element).getActualTarget()); |
|
48 } |
|
49 |
|
50 public FontData getFont(Object element) { |
|
51 return adapter.getFont(((DeploymentTargetWrapper) element).getActualTarget()); |
|
52 } |
|
53 } |
|
54 |
|
55 public class WorkbenchAdapterWrapper implements IWorkbenchAdapter { |
|
56 private final IWorkbenchAdapter adapter; |
|
57 |
|
58 public WorkbenchAdapterWrapper(IWorkbenchAdapter adapter) { |
|
59 this.adapter = adapter; |
|
60 } |
|
61 |
|
62 public Object[] getChildren(Object o) { |
|
63 return adapter.getChildren(((DeploymentTargetWrapper) o).getActualTarget()); |
|
64 } |
|
65 |
|
66 public ImageDescriptor getImageDescriptor(Object object) { |
|
67 return adapter.getImageDescriptor(((DeploymentTargetWrapper) object).getActualTarget()); |
|
68 } |
|
69 |
|
70 public String getLabel(Object o) { |
|
71 return adapter.getLabel(((DeploymentTargetWrapper) o).getActualTarget()); |
|
72 } |
|
73 |
|
74 public Object getParent(Object o) { |
|
75 return adapter.getParent(((DeploymentTargetWrapper) o).getActualTarget()); |
|
76 } |
|
77 } |
|
78 |
|
79 private final DeploymentTargetTypeDescriptor type; |
|
80 private final IDeploymentTarget target; |
|
81 |
|
82 public void save(IMemento memento) { |
|
83 target.save(memento); |
|
84 } |
|
85 |
|
86 public void init(IMTWProject project, IPackager packager, IMemento memento) { |
|
87 target.init(project, packager, memento); |
|
88 } |
|
89 |
|
90 public DeploymentTargetWrapper(IDeploymentTarget target, DeploymentTargetTypeDescriptor type) { |
|
91 this.target = target; |
|
92 this.type = type; |
|
93 } |
|
94 |
|
95 public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) |
|
96 throws CoreException { |
|
97 return target.deploy(project, packager, monitor); |
|
98 } |
|
99 |
|
100 @Override |
|
101 public boolean equals(Object obj) { |
|
102 if (this == obj) { |
|
103 return true; |
|
104 } |
|
105 if (obj == null) { |
|
106 return false; |
|
107 } |
|
108 if (getClass() != obj.getClass()) { |
|
109 return false; |
|
110 } |
|
111 DeploymentTargetWrapper other = (DeploymentTargetWrapper) obj; |
|
112 if (target == null) { |
|
113 if (other.target != null) { |
|
114 return false; |
|
115 } |
|
116 } else if (!target.equals(other.target)) { |
|
117 return false; |
|
118 } |
|
119 return true; |
|
120 } |
|
121 |
|
122 public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { |
|
123 Object a = target.getAdapter(adapter); |
|
124 if (IWorkbenchAdapter.class.isAssignableFrom(adapter)) { |
|
125 return a == null ? new TargetWorkbenchAdapter(this) : new WorkbenchAdapterWrapper((IWorkbenchAdapter) a); |
|
126 } else if (IWorkbenchAdapter2.class.isAssignableFrom(adapter)) { |
|
127 return a == null ? new TargetWorkbenchAdapter(this) : new WorkbenchAdapter2Wrapper((IWorkbenchAdapter2) a); |
|
128 } else { |
|
129 return a; |
|
130 } |
|
131 } |
|
132 |
|
133 public int getCategory() { |
|
134 return type.getPriority() * 0xFFFF + (type.getId().hashCode() & 0xFFFF); |
|
135 } |
|
136 |
|
137 public String getId() { |
|
138 return target.getId(); |
|
139 } |
|
140 |
|
141 public String getName() { |
|
142 return target.getName(); |
|
143 } |
|
144 |
|
145 public String getProviderId() { |
|
146 return type.getId(); |
|
147 } |
|
148 |
|
149 @Override |
|
150 public int hashCode() { |
|
151 final int prime = 31; |
|
152 int result = 1; |
|
153 result = prime * result + ((target == null) ? 0 : target.hashCode()); |
|
154 return result; |
|
155 } |
|
156 |
|
157 public DeploymentTargetTypeDescriptor getType() { |
|
158 return type; |
|
159 } |
|
160 |
|
161 public IDeploymentTarget getActualTarget() { |
|
162 return target; |
|
163 } |
|
164 |
|
165 public String getDescription() { |
|
166 return target.getDescription(); |
|
167 } |
|
168 } |
|