19 package org.symbian.tools.mtw.internal.deployment; |
19 package org.symbian.tools.mtw.internal.deployment; |
20 |
20 |
21 import java.lang.reflect.InvocationTargetException; |
21 import java.lang.reflect.InvocationTargetException; |
22 import java.text.MessageFormat; |
22 import java.text.MessageFormat; |
23 import java.util.HashMap; |
23 import java.util.HashMap; |
|
24 import java.util.HashSet; |
24 import java.util.Map; |
25 import java.util.Map; |
|
26 import java.util.Set; |
25 |
27 |
26 import org.eclipse.core.runtime.CoreException; |
28 import org.eclipse.core.runtime.CoreException; |
27 import org.eclipse.core.runtime.IProgressMonitor; |
29 import org.eclipse.core.runtime.IProgressMonitor; |
28 import org.eclipse.core.runtime.IStatus; |
30 import org.eclipse.core.runtime.IStatus; |
29 import org.eclipse.core.runtime.SubProgressMonitor; |
31 import org.eclipse.core.runtime.SubProgressMonitor; |
51 import org.eclipse.swt.widgets.Button; |
53 import org.eclipse.swt.widgets.Button; |
52 import org.eclipse.swt.widgets.Composite; |
54 import org.eclipse.swt.widgets.Composite; |
53 import org.eclipse.swt.widgets.Control; |
55 import org.eclipse.swt.widgets.Control; |
54 import org.eclipse.ui.model.WorkbenchLabelProvider; |
56 import org.eclipse.ui.model.WorkbenchLabelProvider; |
55 import org.eclipse.ui.part.PageBook; |
57 import org.eclipse.ui.part.PageBook; |
|
58 import org.symbian.tools.mtw.core.MTWCore; |
|
59 import org.symbian.tools.mtw.core.runtimes.IPackager; |
56 import org.symbian.tools.mtw.ui.MTWCoreUI; |
60 import org.symbian.tools.mtw.ui.MTWCoreUI; |
57 import org.symbian.tools.mtw.ui.ProjectMemo; |
61 import org.symbian.tools.mtw.ui.ProjectMemo; |
58 import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; |
62 import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget; |
59 import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; |
63 import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType; |
60 import org.symbian.tools.mtw.ui.deployment.ITargetDetailsPane; |
64 import org.symbian.tools.mtw.ui.deployment.ITargetDetailsPane; |
61 |
65 |
62 public class DeploymentTargetWizardPage extends WizardPage { |
66 public class DeploymentTargetWizardPage extends WizardPage implements ITargetDetailsPane.Context { |
63 private final DeployWizardContext context; |
67 private final DeployWizardContext context; |
|
68 private PageBook descriptions; |
|
69 private Control emptyness; |
|
70 private final Set<IDeploymentTarget> inited = new HashSet<IDeploymentTarget>(); |
64 private TableViewer list; |
71 private TableViewer list; |
|
72 private final Map<IDeploymentTargetType, ITargetDetailsPane> panes = new HashMap<IDeploymentTargetType, ITargetDetailsPane>(); |
65 private final IDeploymentTarget prev; |
73 private final IDeploymentTarget prev; |
66 private PageBook descriptions; |
|
67 private final Map<IDeploymentTargetType, ITargetDetailsPane> panes = new HashMap<IDeploymentTargetType, ITargetDetailsPane>(); |
|
68 private Control emptyness; |
|
69 |
74 |
70 public DeploymentTargetWizardPage(DeployWizardContext context, ProjectMemo memo) { |
75 public DeploymentTargetWizardPage(DeployWizardContext context, ProjectMemo memo) { |
71 super("TargetPage", "Select Deployment Target", null); |
76 super("TargetPage", "Select Deployment Target", null); |
72 this.context = context; |
77 this.context = context; |
73 prev = memo.getPreviousDeploymentTarget(); |
78 prev = memo.getPreviousDeploymentTarget(); |
121 |
126 |
122 FormData data = new FormData(); |
127 FormData data = new FormData(); |
123 data.left = new FormAttachment(0, 5); |
128 data.left = new FormAttachment(0, 5); |
124 data.right = new FormAttachment(100, -5); |
129 data.right = new FormAttachment(100, -5); |
125 data.bottom = new FormAttachment(100, -5); |
130 data.bottom = new FormAttachment(100, -5); |
126 data.height = 50; |
131 data.height = 80; |
127 descriptions.setLayoutData(data); |
132 descriptions.setLayoutData(data); |
128 |
133 |
129 data = new FormData(); |
134 data = new FormData(); |
130 data.top = new FormAttachment(0, 5); |
135 data.top = new FormAttachment(0, 5); |
131 data.right = new FormAttachment(100, -5); |
136 data.right = new FormAttachment(100, -5); |
136 data.top = new FormAttachment(0, 5); |
141 data.top = new FormAttachment(0, 5); |
137 data.bottom = new FormAttachment(descriptions, -10); |
142 data.bottom = new FormAttachment(descriptions, -10); |
138 data.right = new FormAttachment(search, -10); |
143 data.right = new FormAttachment(search, -10); |
139 |
144 |
140 list.getControl().setLayoutData(data); |
145 list.getControl().setLayoutData(data); |
141 |
|
142 list.setInput(context.getDeploymentTargets()); |
146 list.setInput(context.getDeploymentTargets()); |
143 |
|
144 setPageComplete(false); |
147 setPageComplete(false); |
|
148 |
145 if (prev != null) { |
149 if (prev != null) { |
146 list.setSelection(new StructuredSelection(prev)); |
150 list.setSelection(new StructuredSelection(prev)); |
147 } |
151 } |
148 |
|
149 if (!context.areTargetsReady()) { |
|
150 setMessage("Press \"Discover\" to find more deployment targets", IStatus.WARNING); |
|
151 } |
|
152 |
|
153 setControl(root); |
152 setControl(root); |
154 } |
|
155 |
|
156 protected void toggleLogging(boolean logging) { |
|
157 context.setLogging(logging); |
|
158 } |
153 } |
159 |
154 |
160 protected void doBluetoothSearch(final Button search) { |
155 protected void doBluetoothSearch(final Button search) { |
161 try { |
156 try { |
162 final ISelection sel = list.getSelection(); |
157 final ISelection sel = list.getSelection(); |
172 search.getDisplay().asyncExec(new Runnable() { |
167 search.getDisplay().asyncExec(new Runnable() { |
173 public void run() { |
168 public void run() { |
174 list.setInput(context.getDeploymentTargets()); |
169 list.setInput(context.getDeploymentTargets()); |
175 if (!sel.isEmpty()) { |
170 if (!sel.isEmpty()) { |
176 list.setSelection(sel); |
171 list.setSelection(sel); |
177 selectDeploymentTarget((DeploymentTargetWrapper) ((IStructuredSelection)sel).getFirstElement()); |
172 selectDeploymentTarget((DeploymentTargetWrapper) ((IStructuredSelection) sel) |
|
173 .getFirstElement()); |
178 } else { |
174 } else { |
179 DeploymentTargetWrapper[] deploymentTargets = context.getDeploymentTargets(); |
175 DeploymentTargetWrapper[] deploymentTargets = context.getDeploymentTargets(); |
180 if (deploymentTargets.length == 0) { |
176 if (deploymentTargets.length == 0) { |
181 selectDeploymentTarget(null); |
177 selectDeploymentTarget(null); |
182 } else { |
178 } else { |
193 } catch (InterruptedException e) { |
189 } catch (InterruptedException e) { |
194 MTWCoreUI.log(e); |
190 MTWCoreUI.log(e); |
195 } |
191 } |
196 } |
192 } |
197 |
193 |
|
194 private IPackager getPackager() { |
|
195 return MTWCore.getDefault().getRuntimesManager().getPackager(context.getProject()); |
|
196 } |
|
197 |
198 protected void selectDeploymentTarget(DeploymentTargetWrapper target) { |
198 protected void selectDeploymentTarget(DeploymentTargetWrapper target) { |
199 if (target != null) { |
199 if (target != null) { |
|
200 if (!inited.contains(target)) { |
|
201 target.init(context.getProject(), getPackager(), |
|
202 MTWCoreUI.getMemo(context.getProject()).getMemo(target.getType().getId(), target)); |
|
203 inited.add(target); |
|
204 } |
200 context.setTarget(target); |
205 context.setTarget(target); |
201 setMessage(null); |
|
202 setErrorMessage(null); |
|
203 setPageComplete(true); |
|
204 |
206 |
205 IDeploymentTargetType type = target.getType(); |
207 IDeploymentTargetType type = target.getType(); |
206 ITargetDetailsPane pane = panes.get(type); |
208 ITargetDetailsPane pane = panes.get(type); |
207 if (pane == null) { |
209 if (pane == null) { |
208 pane = MTWCoreUI.getDefault().getPresentations().createDetailsPane(type); |
210 pane = MTWCoreUI.getDefault().getPresentations().createDetailsPane(type); |
215 } else { |
217 } else { |
216 descriptions.showPage(emptyness); |
218 descriptions.showPage(emptyness); |
217 context.setTarget(null); |
219 context.setTarget(null); |
218 setPageComplete(false); |
220 setPageComplete(false); |
219 setMessage(null); |
221 setMessage(null); |
220 setErrorMessage("Select device or emulator to deploy the application"); |
222 } |
221 } |
223 revalidate(); |
|
224 } |
|
225 |
|
226 protected void toggleLogging(boolean logging) { |
|
227 context.setLogging(logging); |
|
228 } |
|
229 |
|
230 public void revalidate() { |
|
231 String error = null; |
|
232 String warning = !context.areTargetsReady() ? "Press \"Discover\" to find more deployment targets" : null; |
|
233 if (context.getTarget() == null) { |
|
234 error = "Select device or emulator to deploy the application"; |
|
235 } else { |
|
236 final IStatus validate = panes.get(context.getTarget().getType()).validate(); |
|
237 if (validate.getSeverity() == IStatus.ERROR) { |
|
238 error = validate.getMessage(); |
|
239 } else if (validate.getSeverity() == IStatus.WARNING) { |
|
240 warning = validate.getMessage(); |
|
241 } |
|
242 } |
|
243 setErrorMessage(error); |
|
244 setMessage(warning, IStatus.WARNING); |
|
245 setPageComplete(error == null); |
222 } |
246 } |
223 |
247 |
224 } |
248 } |