1 /******************************************************************************* |
|
2 * Copyright (c) 2009 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.wrttools.debug.internal.launch; |
|
20 |
|
21 import java.net.URI; |
|
22 import java.text.MessageFormat; |
|
23 |
|
24 import org.eclipse.core.resources.IProject; |
|
25 import org.eclipse.core.runtime.CoreException; |
|
26 import org.eclipse.core.runtime.IProgressMonitor; |
|
27 import org.eclipse.debug.core.DebugPlugin; |
|
28 import org.eclipse.debug.core.ILaunch; |
|
29 import org.eclipse.debug.core.ILaunchConfiguration; |
|
30 import org.eclipse.debug.core.ILaunchManager; |
|
31 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; |
|
32 import org.eclipse.ui.IWorkbench; |
|
33 import org.eclipse.ui.IWorkbenchWindow; |
|
34 import org.eclipse.ui.PlatformUI; |
|
35 import org.symbian.tools.tmw.previewer.PreviewerPlugin; |
|
36 import org.symbian.tools.wrttools.debug.internal.Activator; |
|
37 |
|
38 public class WidgetLaunchDelegate implements ILaunchConfigurationDelegate { |
|
39 public static final String ID = "org.symbian.tools.wrttools.debug.widget"; |
|
40 |
|
41 public void launch(ILaunchConfiguration configuration, String mode, final ILaunch launch, IProgressMonitor monitor) |
|
42 throws CoreException { |
|
43 monitor.beginTask("Preparing Mobile Web Debugger", IProgressMonitor.UNKNOWN); |
|
44 ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); |
|
45 final IWorkbench workbench = PlatformUI.getWorkbench(); |
|
46 final IWorkbenchWindow window = workbench.getWorkbenchWindows()[0]; |
|
47 final boolean[] retvalue = new boolean[1]; |
|
48 window.getShell().getDisplay().syncExec(new Runnable() { |
|
49 public void run() { |
|
50 retvalue[0] = workbench.saveAllEditors(true); |
|
51 } |
|
52 }); |
|
53 if (!retvalue[0]) { |
|
54 launchManager.removeLaunch(launch); |
|
55 return; |
|
56 } |
|
57 boolean debug = mode.equals(ILaunchManager.DEBUG_MODE); |
|
58 try { |
|
59 // 1. Load all parameters |
|
60 IProject project = DebugUtil.getProject(configuration); |
|
61 if (DebugUtil.isProjectDebugged(project, launchManager, launch)) { |
|
62 throw DebugUtil.createCoreException(MessageFormat.format("Project {0} is already running.", project.getName()), |
|
63 null); |
|
64 } |
|
65 |
|
66 int port = PortPolicy.getPortNumber(); |
|
67 final URI uri = prepareDebugger(project, debug, launch, port); |
|
68 |
|
69 Activator.getDefault().getChromeInstancesManager().startChrome(launch, port, uri.toASCIIString()); |
|
70 } catch (CoreException e) { |
|
71 launchManager.removeLaunch(launch); |
|
72 throw e; |
|
73 } |
|
74 if (!debug) { |
|
75 launchManager.removeLaunch(launch); |
|
76 } |
|
77 monitor.done(); |
|
78 } |
|
79 |
|
80 private URI prepareDebugger(IProject project, boolean debug, final ILaunch launch, final int port) { |
|
81 DebugConnectionJob job = null; |
|
82 if (debug) { |
|
83 job = new DebugConnectionJob(project, port, launch); |
|
84 } |
|
85 return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project, job); |
|
86 } |
|
87 } |
|