Bug 2214 - Debugger is not updated when JS file is edited.
authorEugene Ostroukhov <eugeneo@symbian.org>
Tue, 16 Mar 2010 17:22:32 -0700
changeset 272 c91ee4e0a0ad
parent 271 4ff7e6f31c66
child 273 b1f63c2c240c
Bug 2214 - Debugger is not updated when JS file is edited.
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/IConstants.java
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/DebugConnectionJob.java
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/DebugUtil.java
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/ResourcesChangeListener.java
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WidgetLaunchDelegate.java
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/ui/DebugPreferencePage.java
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/IConstants.java	Tue Mar 16 12:13:22 2010 -0700
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/IConstants.java	Tue Mar 16 17:22:32 2010 -0700
@@ -21,4 +21,5 @@
 public interface IConstants {
 	String PREF_NAME_CHROME_LOCATION="chrome.location";
 	String PROP_PROJECT_NAME = "projectName";
+    String PREF_SHOW_RESOURCE_CHANGE_ERROR = "show.resourceChange.warning";
 }
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/DebugConnectionJob.java	Tue Mar 16 12:13:22 2010 -0700
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/DebugConnectionJob.java	Tue Mar 16 17:22:32 2010 -0700
@@ -30,6 +30,7 @@
 import org.chromium.debug.core.model.JavascriptVmEmbedder.ConnectionToRemote;
 import org.chromium.sdk.ConnectionLogger;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.debug.core.DebugPlugin;
@@ -122,6 +123,7 @@
 
 			// All OK
 			destructingGuard.discharge();
+            addResourceListenerIfNotInstalled();
 		} catch (CoreException e) {
 			DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
 			throw e;
@@ -130,4 +132,15 @@
 		}
 		return true;
 	}
+
+    private static boolean listenerAdded = false;
+
+    private void addResourceListenerIfNotInstalled() {
+        synchronized (DebugConnectionJob.class) {
+            if (!listenerAdded) {
+                ResourcesPlugin.getWorkspace().addResourceChangeListener(new ResourcesChangeListener());
+                listenerAdded = true;
+            }
+        }
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/DebugUtil.java	Tue Mar 16 17:22:32 2010 -0700
@@ -0,0 +1,68 @@
+/**
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.debug.internal.launch;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchManager;
+import org.symbian.tools.wrttools.debug.internal.Activator;
+import org.symbian.tools.wrttools.debug.internal.IConstants;
+
+public class DebugUtil {
+    public static CoreException createCoreException(String message, Throwable exeption) {
+        return new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, exeption));
+    }
+
+    public static IProject getProject(ILaunchConfiguration configuration) throws CoreException {
+        String projectName = configuration.getAttribute(IConstants.PROP_PROJECT_NAME, (String) null);
+        if (projectName == null) {
+            throw createCoreException("Project is not selected", null);
+        }
+
+        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+        if (!project.isAccessible()) {
+            throw createCoreException(MessageFormat.format("Project {0} is not opened", projectName), null);
+        }
+        return project;
+    }
+
+    public static boolean isProjectDebugged(IProject project, ILaunchManager launchManager, ILaunch l)
+            throws CoreException {
+        ILaunch[] launches = launchManager.getLaunches();
+        for (ILaunch launch : launches) {
+            ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
+            if ((l == null || !l.equals(launch)) && !launch.isTerminated()
+                    && WidgetLaunchDelegate.ID.equals(launchConfiguration.getType().getIdentifier())) {
+                IProject p2 = getProject(launchConfiguration);
+                if (project.equals(p2)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/ResourcesChangeListener.java	Tue Mar 16 17:22:32 2010 -0700
@@ -0,0 +1,84 @@
+/**
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.debug.internal.launch;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+import org.symbian.tools.wrttools.debug.internal.Activator;
+import org.symbian.tools.wrttools.debug.internal.IConstants;
+
+public class ResourcesChangeListener implements IResourceChangeListener {
+    public class ProjectListGatherer implements IResourceDeltaVisitor {
+        public final Collection<IProject> projects = new HashSet<IProject>();
+        private final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+
+        public boolean visit(IResourceDelta delta) throws CoreException {
+            if (delta.getResource().getType() == IResource.PROJECT) {
+                IProject project = delta.getResource().getProject();
+                if (DebugUtil.isProjectDebugged(project, launchManager, null)) {
+                    projects.add(project);
+                }
+                return false;
+            }
+            return true;
+        }
+
+    }
+
+    public void resourceChanged(IResourceChangeEvent event) {
+        if (event.getDelta() != null
+                && !MessageDialogWithToggle.ALWAYS.equals(Activator.getDefault().getPreferenceStore().getString(
+                        IConstants.PREF_SHOW_RESOURCE_CHANGE_ERROR))) {
+            ProjectListGatherer gatherer = new ProjectListGatherer();
+            try {
+                event.getDelta().accept(gatherer);
+            } catch (CoreException e) {
+                Activator.log(e);
+            }
+            int size = gatherer.projects.size();
+            if (size > 0) {
+                Display.getDefault().asyncExec(new Runnable() {
+                    public void run() {
+                        String message = "Debug browser is not updated when the files are updated. You may notice discrepancies between your workspace contents and debug session. You should either refresh the browser or restart debugging session to see the latest changes made to the workspace.";
+                        MessageDialogWithToggle.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+                                .getShell(), "WebRuntime Debugger", message,
+                                "Do not show this warning on code changes", false, Activator.getDefault()
+                                        .getPreferenceStore(), IConstants.PREF_SHOW_RESOURCE_CHANGE_ERROR);
+                        ResourcesPlugin.getWorkspace().removeResourceChangeListener(ResourcesChangeListener.this);
+                    }
+                });
+            }
+        }
+    }
+
+}
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WidgetLaunchDelegate.java	Tue Mar 16 12:13:22 2010 -0700
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WidgetLaunchDelegate.java	Tue Mar 16 17:22:32 2010 -0700
@@ -22,11 +22,8 @@
 import java.text.MessageFormat;
 
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.debug.core.DebugPlugin;
 import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.ILaunchConfiguration;
@@ -36,7 +33,6 @@
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
 import org.symbian.tools.wrttools.debug.internal.Activator;
-import org.symbian.tools.wrttools.debug.internal.IConstants;
 import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
 
 public class WidgetLaunchDelegate implements ILaunchConfigurationDelegate {
@@ -61,8 +57,11 @@
 		boolean debug = mode.equals(ILaunchManager.DEBUG_MODE);
 		try {
 			// 1. Load all parameters
-			IProject project = getProject(configuration);
-			isProjectDebugged(project, launchManager, launch);
+			IProject project = DebugUtil.getProject(configuration);
+            if (DebugUtil.isProjectDebugged(project, launchManager, launch)) {
+                throw DebugUtil.createCoreException(MessageFormat.format("Project {0} is already running.", project.getName()),
+                        null);
+            }
 
 			int port = PortPolicy.getPortNumber();
 			final URI uri = prepareDebugger(project, debug, launch, port);
@@ -78,21 +77,7 @@
 		monitor.done();
 	}
 
-	private void isProjectDebugged(IProject project, ILaunchManager launchManager, ILaunch l) throws CoreException {
-		ILaunch[] launches = launchManager.getLaunches();
-		for (ILaunch launch : launches) {
-			ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
-			if (!l.equals(launch) && ID.equals(launchConfiguration.getType().getIdentifier())) {
-				IProject p2 = getProject(launchConfiguration);
-				if (project.equals(p2)) {
-					throw createCoreException(MessageFormat
-							.format("Project {0} is already running.", project.getName()), null);
-				}
-			}
-		}
-	}
-
-	private URI prepareDebugger(IProject project, boolean debug, final ILaunch launch, final int port) {
+    private URI prepareDebugger(IProject project, boolean debug, final ILaunch launch, final int port) {
 		if (debug) {
 			final DebugConnectionJob job = new DebugConnectionJob(project, port, launch);
 			return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project, job);
@@ -100,21 +85,4 @@
 			return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project);
 		}
 	}
-
-	private IProject getProject(ILaunchConfiguration configuration) throws CoreException {
-		String projectName = configuration.getAttribute(IConstants.PROP_PROJECT_NAME, (String) null);
-		if (projectName == null) {
-			throw createCoreException("Project is not selected", null);
-		}
-
-		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
-		if (!project.isAccessible()) {
-			throw createCoreException(MessageFormat.format("Project {0} is not opened", projectName), null);
-		}
-		return project;
-	}
-
-	private CoreException createCoreException(String message, Throwable exeption) {
-		return new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, exeption));
-	}
 }
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/ui/DebugPreferencePage.java	Tue Mar 16 12:13:22 2010 -0700
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/ui/DebugPreferencePage.java	Tue Mar 16 17:22:32 2010 -0700
@@ -18,8 +18,12 @@
  *******************************************************************************/
 package org.symbian.tools.wrttools.debug.ui;
 
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
 import org.eclipse.jface.preference.DirectoryFieldEditor;
 import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
 import org.symbian.tools.wrttools.debug.internal.Activator;
@@ -28,7 +32,9 @@
 public class DebugPreferencePage extends FieldEditorPreferencePage implements
 		IWorkbenchPreferencePage {
 
-	public DebugPreferencePage() {
+    private Button check;
+
+    public DebugPreferencePage() {
 		super(GRID);
 		setPreferenceStore(Activator.getDefault().getPreferenceStore());
 		setDescription("WRT debugger settings");
@@ -39,8 +45,31 @@
 		DirectoryFieldEditor editor = new DirectoryFieldEditor("chrome", "Chrome Install Location:", getFieldEditorParent());
 		editor.setPreferenceName(IConstants.PREF_NAME_CHROME_LOCATION);
 		addField(editor);
+
+        check = new Button(getFieldEditorParent(), SWT.CHECK);
+        check.setText("Show warning dialog when resources in the debugged project were changed");
+        check.setLayoutData(new GridData(GridData.BEGINNING, GridData.END, false, false, 3, 1));
+
+        check.setSelection(MessageDialogWithToggle.ALWAYS.equals(getPreferenceStore().getString(
+                IConstants.PREF_SHOW_RESOURCE_CHANGE_ERROR)));
 	}
 
+    @Override
+    protected void performDefaults() {
+        super.performDefaults();
+        check.setSelection(false);
+    }
+
+    @Override
+    public boolean performOk() {
+        if (check.getSelection()) {
+            getPreferenceStore().setValue(IConstants.PREF_SHOW_RESOURCE_CHANGE_ERROR, MessageDialogWithToggle.ALWAYS);
+        } else {
+            getPreferenceStore().setToDefault(IConstants.PREF_SHOW_RESOURCE_CHANGE_ERROR);
+        }
+        return super.performOk();
+    }
+
 	public void init(IWorkbench workbench) {
 		// Do nothing
 	}