Refactoring server-side preview code
authorEugene Ostroukhov <eugeneo@symbian.org>
Wed, 14 Apr 2010 11:17:26 -0700
changeset 304 d92630dec325
parent 303 a619b3ef3095
child 305 be8783adb3a8
Refactoring server-side preview code
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.previewer/preview/wrt_preview.html
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/PreviewerUtil.java
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/EmulatorContext.java
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/HttpPreviewer.java
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WebAppInterface.java
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WorkspaceResourcesServlet.java
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/PreviewerStaticResourceProvider.java
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/RefreshJob.java
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/ResourcesChangeListener.java	Tue Apr 13 16:04:08 2010 -0700
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/ResourcesChangeListener.java	Wed Apr 14 11:17:26 2010 -0700
@@ -18,57 +18,24 @@
  */
 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.IFile;
 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;
+import org.symbian.tools.wrttools.previewer.PreviewerUtil;
 
 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 {
-            int d = delta.getFlags()
-                    & (IResourceDelta.CONTENT | IResourceDelta.OPEN | IResourceDelta.MOVED_TO
-                            | IResourceDelta.MOVED_FROM | IResourceDelta.SYNC | IResourceDelta.REPLACED);
-            if (delta.getKind() != IResourceDelta.CHANGED || d != 0) {
-                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) {
+            IFile[] changes = PreviewerUtil.getWebChanges(event.getDelta());
+            if (changes.length > 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.";
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WidgetLaunchDelegate.java	Tue Apr 13 16:04:08 2010 -0700
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WidgetLaunchDelegate.java	Wed Apr 14 11:17:26 2010 -0700
@@ -78,11 +78,10 @@
 	}
 
     private URI prepareDebugger(IProject project, boolean debug, final ILaunch launch, final int port) {
+        DebugConnectionJob job = null;
 		if (debug) {
-			final DebugConnectionJob job = new DebugConnectionJob(project, port, launch);
-			return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project, job);
-		} else {
-			return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project);
+            job = new DebugConnectionJob(project, port, launch);
 		}
+        return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project, job);
 	}
 }
--- a/org.symbian.tools.wrttools.previewer/preview/wrt_preview.html	Tue Apr 13 16:04:08 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/wrt_preview.html	Wed Apr 14 11:17:26 2010 -0700
@@ -70,7 +70,7 @@
 				</th>
 				<td>
 					<select id="resOptions">
-						<option selected="true" value="http://www.forum.nokia.com/devices/matrix_240x320_1.html">240x320</option>
+						<option selected="selected" value="http://www.forum.nokia.com/devices/matrix_240x320_1.html">240x320</option>
 						<option value="http://www.forum.nokia.com/devices/matrix_320x240_1.html">320x240</option>
 						<option value="http://www.forum.nokia.com/devices/matrix_360x640_1.html">360x640</option>
 						<option value="http://www.forum.nokia.com/devices/E90_Communicator">800x352</option>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/PreviewerUtil.java	Wed Apr 14 11:17:26 2010 -0700
@@ -0,0 +1,100 @@
+/**
+ * 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.previewer;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.symbian.tools.wrttools.util.ProjectUtils;
+
+public class PreviewerUtil {
+    public static final class ChangedResourcesCollector implements IResourceDeltaVisitor {
+        public final Collection<IFile> files = new HashSet<IFile>();
+        public final Collection<IProject> deleted = new HashSet<IProject>();
+        public final Map<IProject, IPath> renamed = new HashMap<IProject, IPath>();
+
+        public boolean visit(IResourceDelta delta) throws CoreException {
+            IResource resource = delta.getResource();
+            if (resource.getType() == IResource.PROJECT) {
+                if (delta.getKind() == IResourceDelta.REMOVED) {
+                    if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
+                        renamed.put(resource.getProject(), delta.getMovedToPath());
+                    } else {
+                        deleted.add((IProject) resource);
+                    }
+                    return false;
+                }
+            } else if (isRelevantResource(resource)) {
+                if (delta.getKind() == IResourceDelta.ADDED | delta.getKind() == IResourceDelta.REMOVED) {
+                    if (!ProjectUtils.isExcluded(resource)) {
+                        files.add((IFile) resource);
+                    }
+                } else if ((delta.getFlags() & (IResourceDelta.CONTENT | IResourceDelta.ENCODING
+                        | IResourceDelta.LOCAL_CHANGED | IResourceDelta.REPLACED | IResourceDelta.SYNC)) != 0) {
+                    if (!ProjectUtils.isExcluded(resource)) {
+                        files.add((IFile) resource);
+                    }
+                } else if (delta.getMarkerDeltas().length != 0) {
+                    for (IMarkerDelta markerDelta : delta.getMarkerDeltas()) {
+                        if (markerDelta.getType().equals(ProjectUtils.EXCLUDE_MARKER_ID)) {
+                            files.add((IFile) resource);
+                            break;
+                        }
+                    }
+                }
+            }
+            return true;
+        }
+    }
+
+    public static boolean isRelevantResource(IResource resource) {
+        if (resource.getType() == IResource.FILE) {
+            return !resource.getFullPath().segment(1).equalsIgnoreCase("preview")
+                    && !"wgz".equalsIgnoreCase(resource.getFileExtension())
+                    && !(PreviewerPlugin.PLUGIN_ID + ".xml").equals(resource.getName());
+        }
+        return false;
+    }
+
+    public static IFile[] getWebChanges(final IResourceDelta delta) {
+        ChangedResourcesCollector visitor = collectResourceChanges(delta);
+        final Collection<IFile> files = visitor.files;
+        return files.toArray(new IFile[files.size()]);
+    }
+
+    public static ChangedResourcesCollector collectResourceChanges(final IResourceDelta delta) {
+        ChangedResourcesCollector visitor = new ChangedResourcesCollector();
+        try {
+            delta.accept(visitor);
+        } catch (CoreException e) {
+            PreviewerPlugin.log(e);
+        }
+        return visitor;
+    }
+}
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/EmulatorContext.java	Tue Apr 13 16:04:08 2010 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 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.previewer.http;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.osgi.service.http.HttpContext;
-
-public class EmulatorContext implements HttpContext {
-
-	public String getMimeType(String name) {
-		return null;
-	}
-
-	public URL getResource(String name) {
-		try {
-			return new URL("file:///e:/maven-prefs.png");
-		} catch (MalformedURLException e) {
-			return null;
-		}
-	}
-
-	public boolean handleSecurity(HttpServletRequest request,
-			HttpServletResponse response) throws IOException {
-		return true;
-	}
-
-}
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/HttpPreviewer.java	Tue Apr 13 16:04:08 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/HttpPreviewer.java	Wed Apr 14 11:17:26 2010 -0700
@@ -1,42 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.previewer.http;
 
 import java.io.File;
 import java.net.URI;
-import java.net.URISyntaxException;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 
 public class HttpPreviewer {
+    public IFile getFileFromUrl(String name) {
+        return WorkspaceResourcesServlet.getFileFromUrl(name);
+    }
 
-	public URI previewProject(IProject project) {
-		WebAppInterface.getInstance(); // Ensure server is up
-		try {
-			return new URI(WorkspaceResourcesServlet.getPreviewerStartingPage(project.getName()));
-		} catch (URISyntaxException e) {
-			return null;
-		}
-	}
+    public String getHttpUrl(IResource resource) {
+        return WorkspaceResourcesServlet.getHttpUrl(resource);
+    }
 
-	public IFile getFileFromUrl(String name) {
-		return WorkspaceResourcesServlet.getFileFromUrl(name);
-	}
-
-	public String getHttpUrl(IResource resource) {
-		return WorkspaceResourcesServlet.getHttpUrl(resource);
-	}
-
-	public URI previewProject(IProject project, IPreviewStartupListener listener) {
-		if (listener == null) {
-			return previewProject(project);
-		} else {
-			return WebAppInterface.getInstance().prepareDebugger(project, listener);
-		}
-	}
+    public URI previewProject(IProject project, IPreviewStartupListener listener) {
+        WebAppInterface.getInstance(); // Ensure server is up
+        if (listener == null) {
+            return WorkspaceResourcesServlet.getPreviewerStartingPage(project.getName());
+        } else {
+            return WebAppInterface.getInstance().prepareDebugger(project, listener);
+        }
+    }
 
     public File getLocalFile(String name) {
         return WorkspaceResourcesServlet.getPreviewerResource(name);
     }
-
 }
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WebAppInterface.java	Tue Apr 13 16:04:08 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WebAppInterface.java	Wed Apr 14 11:17:26 2010 -0700
@@ -70,7 +70,7 @@
 	}
 
 	public static String getUrl(String widget, String id) {
-		return getInstance().complete(widget, id);
+        return getInstance().complete(widget, id).toASCIIString();
 	}
 
 	public static boolean isConnected(String widget, String id) {
@@ -97,7 +97,7 @@
 		}
 	}
 
-	private synchronized String complete(String widget, String id) {
+    private synchronized URI complete(String widget, String id) {
 		return WorkspaceResourcesServlet.getPreviewerStartingPage(widget);
 	}
 
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WorkspaceResourcesServlet.java	Tue Apr 13 16:04:08 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WorkspaceResourcesServlet.java	Wed Apr 14 11:17:26 2010 -0700
@@ -24,6 +24,8 @@
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
@@ -107,7 +109,7 @@
     }
 
     public static String getHttpUrl(IResource file) {
-        String uri = getServerURIForResource(file != null ? file.getFullPath().toString() : "/");
+        String uri = getServerURIForResource(file != null ? file.getFullPath().toString() : "/").toASCIIString();
         if (uri != null) {
             return uri;
         } else {
@@ -127,7 +129,8 @@
         try {
             IPath path = getProjectRelativePath(name);
             if (path != null) {
-                if (path.segmentCount() == 2 && PreviewerStaticResourceProvider.STARTING_PAGE.equals(path.segment(1))) {
+                if (path.segmentCount() == 2
+                        && PreviewerStaticResourceProvider.PREVIEW_STARTING_PAGE.equals(path.segment(1))) {
                     path = new Path(PreviewerStaticResourceProvider.PREVIEW_START);
                 } else if (path.segmentCount() > 2
                         && PreviewerStaticResourceProvider.PREVIEW_PATH.equals(path.segment(1))) {
@@ -149,8 +152,8 @@
         return null;
     }
 
-    public static String getPreviewerStartingPage(String widget) {
-        return getServerURIForResource(new Path(widget).append(PreviewerStaticResourceProvider.STARTING_PAGE)
+    public static URI getPreviewerStartingPage(String widget) {
+        return getServerURIForResource(new Path(widget).append(PreviewerStaticResourceProvider.PREVIEW_STARTING_PAGE)
                 .makeAbsolute().toString());
     }
 
@@ -185,7 +188,7 @@
         }
     }
 
-    private static String getServerURIForResource(String resourcePath) {
+    private static URI getServerURIForResource(String resourcePath) {
         Path p = new Path(resourcePath);
         if (p.segmentCount() > 1) {
             IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(p.segment(0));
@@ -206,7 +209,11 @@
         } catch (MalformedURLException e) {
             uri = null;
         }
-        return uri;
+        try {
+            return new URI(uri);
+        } catch (URISyntaxException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     private final Providers providers = new Providers();
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/PreviewerStaticResourceProvider.java	Tue Apr 13 16:04:08 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/PreviewerStaticResourceProvider.java	Wed Apr 14 11:17:26 2010 -0700
@@ -32,17 +32,18 @@
 import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
 
 public class PreviewerStaticResourceProvider implements ResourceProvider {
-    public static final String STARTING_PAGE = "preview-frame.html";
+    public static final String PREVIEW_STARTING_PAGE = "preview-frame.html";
+    public static final String DEBUG_STARTING_PAGE = "debug-frame.html";
     public static final String PREVIEW_PATH = "preview";
     public static final String PREVIEW_START = "/preview/wrt_preview.html";
 
     public String[] getPaths() {
-        return new String[] { STARTING_PAGE, PREVIEW_PATH };
+        return new String[] { PREVIEW_STARTING_PAGE, PREVIEW_PATH, DEBUG_STARTING_PAGE };
     }
 
     public InputStream getResourceStream(IProject project, IPath resource, Map<String, String> parameters)
             throws IOException {
-        if (STARTING_PAGE.equals(resource.toString())) {
+        if (PREVIEW_STARTING_PAGE.equals(resource.toString()) || DEBUG_STARTING_PAGE.equals(resource.toString())) {
             resource = new Path(PREVIEW_START);
         }
         URL url = FileLocator.find(PreviewerPlugin.getDefault().getBundle(), resource, null);
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java	Tue Apr 13 16:04:08 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java	Wed Apr 14 11:17:26 2010 -0700
@@ -80,7 +80,7 @@
     protected abstract Browser createBrowser(Composite parent);
 
     private URI getURI() {
-        return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project);
+        return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project, null);
     }
 
     @Override
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/RefreshJob.java	Tue Apr 13 16:04:08 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/RefreshJob.java	Wed Apr 14 11:17:26 2010 -0700
@@ -18,74 +18,20 @@
  */
 package org.symbian.tools.wrttools.previewer.preview;
 
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
 import java.util.Map.Entry;
 
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarkerDelta;
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
 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.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
-import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
-import org.symbian.tools.wrttools.util.ProjectUtils;
+import org.symbian.tools.wrttools.previewer.PreviewerUtil;
+import org.symbian.tools.wrttools.previewer.PreviewerUtil.ChangedResourcesCollector;
 
 public class RefreshJob extends Job {
-    private static final class ChangedResourcesCollector implements IResourceDeltaVisitor {
-        public final Collection<IFile> files = new HashSet<IFile>();
-        public final Collection<IProject> deleted = new HashSet<IProject>();
-        public final Map<IProject, IPath> renamed = new HashMap<IProject, IPath>();
-
-        public boolean visit(IResourceDelta delta) throws CoreException {
-            IResource resource = delta.getResource();
-            if (resource.getType() == IResource.PROJECT) {
-                if (delta.getKind() == IResourceDelta.REMOVED) {
-                    if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
-                        renamed.put(resource.getProject(), delta.getMovedToPath());
-                    } else {
-                        deleted.add((IProject) resource);
-                    }
-                    return false;
-                }
-            } else if (isRelevantResource(resource)) {
-                if (delta.getKind() == IResourceDelta.ADDED | delta.getKind() == IResourceDelta.REMOVED) {
-                    if (!ProjectUtils.isExcluded(resource)) {
-                        files.add((IFile) resource);
-                    }
-                } else if ((delta.getFlags() & (IResourceDelta.CONTENT | IResourceDelta.ENCODING
-                        | IResourceDelta.LOCAL_CHANGED | IResourceDelta.REPLACED | IResourceDelta.SYNC)) != 0) {
-                    if (!ProjectUtils.isExcluded(resource)) {
-                        files.add((IFile) resource);
-                    }
-                } else if (delta.getMarkerDeltas().length != 0) {
-                    for (IMarkerDelta markerDelta : delta.getMarkerDeltas()) {
-                        if (markerDelta.getType().equals(ProjectUtils.EXCLUDE_MARKER_ID)) {
-                            files.add((IFile) resource);
-                            break;
-                        }
-                    }
-                }
-            }
-            return true;
-        }
-    }
-
-    public static boolean isRelevantResource(IResource resource) {
-        return resource.getType() == IResource.FILE && !resource.getFullPath().segment(1).equalsIgnoreCase("preview")
-                && !"wgz".equalsIgnoreCase(resource.getFileExtension())
-                && !(PreviewerPlugin.PLUGIN_ID + ".xml").equals(resource.getName());
-    }
-
     private final IResourceDelta delta;
     private final PreviewView view;
 
@@ -99,12 +45,7 @@
 
     @Override
     protected IStatus run(IProgressMonitor monitor) {
-        ChangedResourcesCollector visitor = new ChangedResourcesCollector();
-        try {
-            delta.accept(visitor);
-        } catch (CoreException e) {
-            PreviewerPlugin.log(e);
-        }
+        final ChangedResourcesCollector visitor = PreviewerUtil.collectResourceChanges(delta);
         for (Entry<IProject, IPath> entry : visitor.renamed.entrySet()) {
             view.projectRenamed(entry.getKey(), entry.getValue());
         }