Fixed: [ Issue 44 ] Add ability to hyperlink to imported files
https://code.google.com/p/protobuf-dt/issues/detail?id=44
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver_resolveUri_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver_resolveUri_Test.java
index fd213cf..6ec8b87 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver_resolveUri_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver_resolveUri_Test.java
@@ -14,14 +14,14 @@
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
-import org.eclipse.core.resources.IProject;
import org.eclipse.emf.common.util.URI;
import org.junit.*;
import com.google.eclipse.protobuf.ui.preferences.paths.PathsPreferences;
+import com.google.eclipse.protobuf.ui.util.Resources;
/**
- * Tests for <code>{@link SingleDirectoryFileResolver#resolveUri(String, URI, PathsPreferences, IProject)}</code>.
+ * Tests for <code>{@link SingleDirectoryFileResolver#resolveUri(String, URI, PathsPreferences)}</code>.
*
* @author alruiz@google.com (Alex Ruiz)
*/
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/ImportHyperlink.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/ImportHyperlink.java
index ea8f08f..7ea01d6 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/ImportHyperlink.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/ImportHyperlink.java
@@ -12,11 +12,12 @@
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.ui.*;
-import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.part.FileEditorInput;
import com.google.eclipse.protobuf.ui.util.Resources;
@@ -47,19 +48,19 @@
private void openFromWorkspace() {
IFile file = resources.file(importUri);
IEditorInput editorInput = new FileEditorInput(file);
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- try {
- page.openEditor(editorInput, "com.google.eclipse.protobuf.Protobuf");
- } catch (PartInitException e) {
- e.printStackTrace();
- }
+ openFile(editorInput, "com.google.eclipse.protobuf.Protobuf");
}
private void openFromFileSystem() {
- IFileStore fileStore = EFS.getLocalFileSystem().getStore(resources.pathOf(importUri));
+ IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(importUri.toFileString()));
+ IEditorInput editorInput = new FileStoreEditorInput(fileStore);
+ openFile(editorInput, "org.eclipse.ui.DefaultTextEditor");
+ }
+
+ private void openFile(IEditorInput editorInput, String editorId) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
- IDE.openEditorOnFileStore(page, fileStore);
+ page.openEditor(editorInput, editorId);
} catch (PartInitException e) {
e.printStackTrace();
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Resources.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Resources.java
index abe9f2d..62a381b 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Resources.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Resources.java
@@ -47,17 +47,12 @@
* @return a handle to file identified by the given URI.
*/
public IFile file(URI uri) {
- IPath resourcePath = pathOf(uri);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- return root.getFile(resourcePath);
+ return root.getFile(pathOf(uri));
}
- /**
- * Constructs a new path from the given URI.
- * @param uri the given URI.
- * @return the constructed path.
- */
- public IPath pathOf(URI uri) {
- return new Path(uri.toPlatformString(true));
+ private IPath pathOf(URI uri) {
+ String s = uri.toPlatformString(true);
+ return new Path(s);
}
}