Bug 2073 - On restart of WRT tools - its hard to know which project the open file is in
--- a/org.symbian.tools.wrttools/plugin.xml Fri Feb 26 13:21:29 2010 -0800
+++ b/org.symbian.tools.wrttools/plugin.xml Fri Feb 26 16:55:03 2010 -0800
@@ -359,7 +359,9 @@
isRoot="true"
pattern="org.symbian.tools.wrttools.navigatorcontent"/>
<contentExtension pattern="org.eclipse.ui.navigator.resources.filters.*" />
- <contentExtension pattern="org.eclipse.ui.navigator.resources.linkHelper" />
+ <contentExtension
+ isRoot="true"
+ pattern="org.symbian.tools.wrttools.wrtLinkHelper"/>
</includes>
</viewerContentBinding>
<viewerActionBinding viewerId="org.symbian.tools.wrttools.wrtnavigator">
@@ -623,4 +625,29 @@
label="wrt, webruntime, web runtime, cwrt">
</keyword>
</extension>
+ <extension
+ point="org.eclipse.ui.navigator.linkHelper">
+ <linkHelper
+ class="org.symbian.tools.wrttools.navigator.WrtNavigatorLinkHelper"
+ id="org.symbian.tools.wrttools.wrtLinkHelper">
+ <editorInputEnablement>
+ <adapt
+ type="org.eclipse.ui.IFileEditorInput">
+ </adapt>
+ </editorInputEnablement>
+ <selectionEnablement>
+ <or>
+ <adapt
+ type="org.eclipse.wst.jsdt.core.IJavaScriptElement">
+ </adapt>
+ <instanceof
+ value="java.util.Collection">
+ </instanceof>
+ <adapt
+ type="org.eclipse.core.resources.IResource">
+ </adapt>
+ </or>
+ </selectionEnablement>
+ </linkHelper>
+ </extension>
</plugin>
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/navigator/WRTNavigatorContentProvider.java Fri Feb 26 13:21:29 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/navigator/WRTNavigatorContentProvider.java Fri Feb 26 16:55:03 2010 -0800
@@ -2,8 +2,8 @@
import java.util.Collection;
import java.util.Comparator;
-import java.util.TreeSet;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
@@ -117,7 +117,7 @@
}
}
- private IResourceChangeListener listener = new IResourceChangeListener() {
+ private final IResourceChangeListener listener = new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
IResource refresh = null;
if (event.getDelta() != null) {
@@ -144,33 +144,16 @@
super.dispose();
}
- private Object[] filter(IResource[] members) {
- TreeSet<Object> output = new TreeSet<Object>(
- new TreeElementsComparator());
- for (int i = 0; i < members.length; i++) {
- IResource resource = members[i];
- Object res = resource;
- if (resource.getType() == IResource.FILE) {
- IJavaScriptElement element = JavaScriptCore.create(resource);
- if (element != null) {
- res = element;
- }
- }
- output.add(res);
- }
- return output.toArray();
- }
-
@Override
protected Object[] getFolderContent(IFolder folder) throws CoreException {
- return filter(folder.members());
+ return folder.members();
}
@Override
protected Object[] getPackageFragmentRoots(IJavaScriptProject project)
throws JavaScriptModelException {
try {
- return filter(project.getProject().members());
+ return project.getProject().members();
} catch (CoreException e) {
Activator.log(e);
}
@@ -227,4 +210,16 @@
}
});
}
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof IFile) {
+ IFile file = (IFile) parentElement;
+ IJavaScriptElement element = JavaScriptCore.create(file);
+ if (element != null) {
+ return super.getChildren(element);
+ }
+ }
+ return super.getChildren(parentElement);
+ }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/navigator/WrtNavigatorLinkHelper.java Fri Feb 26 16:55:03 2010 -0800
@@ -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.navigator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.navigator.ILinkHelper;
+import org.eclipse.wst.jsdt.core.IJavaScriptElement;
+import org.symbian.tools.wrttools.Activator;
+
+public class WrtNavigatorLinkHelper implements ILinkHelper {
+
+ public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
+ IResource selection = filter(aSelection.toArray());
+ if (selection == null) {
+ return;
+ }
+ IEditorReference[] references = aPage.getEditorReferences();
+ for (IEditorReference editorReference : references) {
+ IEditorInput input;
+ try {
+ input = editorReference.getEditorInput();
+ Object resource = input.getAdapter(IResource.class);
+ if (resource != null && selection.equals(resource)) {
+ IWorkbenchPart part = editorReference.getPart(true);
+ if (part != null) {
+ aPage.activate(part);
+ }
+ return;
+ }
+ } catch (PartInitException e) {
+ Activator.log(e);
+ }
+ }
+ }
+
+ private IResource filter(Object[] array) {
+ IResource selection = null;
+ for (Object object : array) {
+ IResource resource = null;
+ if (object instanceof IResource) {
+ resource = (IResource) object;
+ } else if (object instanceof IJavaScriptElement) {
+ resource = ((IJavaScriptElement) object).getResource();
+ }
+ if (selection == null) {
+ selection = resource;
+ } else if (!selection.equals(resource)) {
+ return null;
+ }
+ }
+ return selection;
+ }
+
+ public IStructuredSelection findSelection(IEditorInput anInput) {
+ final IFileEditorInput input = (IFileEditorInput) anInput.getAdapter(IFileEditorInput.class);
+ IFile file = input.getFile();
+ return new StructuredSelection(file);
+ }
+}