Code cleanup.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOpener.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOpener.java
new file mode 100644
index 0000000..c2653de
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOpener.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.editor;
+
+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.ui.*;
+import org.eclipse.ui.ide.FileStoreEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+
+import com.google.eclipse.protobuf.ui.util.Resources;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+/**
+ * Utility methods related to open file from different type of locations.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+@Singleton
+public class FileOpener {
+
+ @Inject private Resources resources;
+
+ public IEditorPart openProtoFileInWorkspace(URI uri) throws PartInitException {
+ IFile file = resources.file(uri);
+ IEditorInput editorInput = new FileEditorInput(file);
+ return openFile(editorInput);
+ }
+
+ public IEditorPart openProtoFileInFileSystem(URI uri) throws PartInitException {
+ IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(uri.toFileString()));
+ IEditorInput editorInput = new FileStoreEditorInput(fileStore);
+ return openFile(editorInput/*"org.eclipse.ui.DefaultTextEditor"*/);
+ }
+
+ public IEditorPart openProtoFileInPlugin(URI uri) throws PartInitException {
+ IEditorInput editorInput = new UriEditorInput(uri);
+ return openFile(editorInput);
+ }
+
+ private IEditorPart openFile(IEditorInput editorInput) throws PartInitException {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ return page.openEditor(editorInput, "com.google.eclipse.protobuf.Protobuf");
+ }
+
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/ProtobufUriEditorOpener.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/ProtobufUriEditorOpener.java
index acdcd3a..c529cc8 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/ProtobufUriEditorOpener.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/ProtobufUriEditorOpener.java
@@ -17,7 +17,6 @@
import org.eclipse.ui.PartInitException;
import org.eclipse.xtext.ui.editor.LanguageSpecificURIEditorOpener;
-import com.google.eclipse.protobuf.ui.util.Resources;
import com.google.inject.Inject;
/**
@@ -27,12 +26,12 @@
private static Logger logger = Logger.getLogger(ProtobufUriEditorOpener.class);
- @Inject private Resources resources;
+ @Inject private FileOpener fileOpener;
/** {@inheritDoc} */
@Override public IEditorPart open(URI uri, EReference crossReference, int indexInList, boolean select) {
try {
- IEditorPart editor = editorFor(uri);
+ IEditorPart editor = editorFor(uri.trimFragment());
if (editor != null) {
selectAndReveal(editor, uri, crossReference, indexInList, select);
return getXtextEditor(editor);
@@ -45,9 +44,9 @@
private IEditorPart editorFor(URI uri) throws PartInitException {
if (uri.isFile())
- return resources.openProtoFileInFileSystem(uri.trimFragment());
+ return fileOpener.openProtoFileInFileSystem(uri);
if (uri.isPlatformPlugin())
- return resources.openProtoFileInPlugin(uri);
+ return fileOpener.openProtoFileInPlugin(uri);
return null;
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ImportHyperlink.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ImportHyperlink.java
index 9aef26d..89459ad 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ImportHyperlink.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ImportHyperlink.java
@@ -14,7 +14,7 @@
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.ui.PartInitException;
-import com.google.eclipse.protobuf.ui.util.Resources;
+import com.google.eclipse.protobuf.ui.editor.FileOpener;
/**
* A hyperlink for imported .proto files.
@@ -27,25 +27,25 @@
private final URI importUri;
private final IRegion region;
- private final Resources resources;
+ private final FileOpener fileOpener;
- ImportHyperlink(URI importUri, IRegion region, Resources resources) {
+ ImportHyperlink(URI importUri, IRegion region, FileOpener fileOpener) {
this.importUri = importUri;
this.region = region;
- this.resources = resources;
+ this.fileOpener = fileOpener;
}
public void open() {
try {
if (importUri.isPlatformResource()) {
- resources.openProtoFileInWorkspace(importUri);
+ fileOpener.openProtoFileInWorkspace(importUri);
return;
}
if (importUri.isPlatformPlugin()) {
- resources.openProtoFileInPlugin(importUri);
+ fileOpener.openProtoFileInPlugin(importUri);
return;
}
- if (importUri.isFile()) resources.openProtoFileInFileSystem(importUri);
+ if (importUri.isFile()) fileOpener.openProtoFileInFileSystem(importUri);
} catch (PartInitException e) {
logger.error("Unable to open " + importUri.toString(), e);
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ProtobufHyperlinkDetector.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ProtobufHyperlinkDetector.java
index 8cfd4e1..aa7f948 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ProtobufHyperlinkDetector.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ProtobufHyperlinkDetector.java
@@ -22,7 +22,7 @@
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import com.google.eclipse.protobuf.protobuf.Import;
-import com.google.eclipse.protobuf.ui.util.Resources;
+import com.google.eclipse.protobuf.ui.editor.FileOpener;
import com.google.inject.Inject;
/**
@@ -38,7 +38,7 @@
private static final char QUOTE = '\"';
@Inject private EObjectAtOffsetHelper eObjectAtOffsetHelper;
- @Inject private Resources resources;
+ @Inject private FileOpener fileOpener;
@Override public IHyperlink[] detectHyperlinks(ITextViewer textViewer, final IRegion region,
final boolean canShowMultipleHyperlinks) {
@@ -65,7 +65,7 @@
return NO_HYPERLINKS;
}
String importUri = anImport.getImportURI();
- IHyperlink hyperlink = new ImportHyperlink(createURI(importUri), importUriRegion, resources);
+ IHyperlink hyperlink = new ImportHyperlink(createURI(importUri), importUriRegion, fileOpener);
return new IHyperlink[] { hyperlink };
}
});
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 966017a..c350afb 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
@@ -8,19 +8,14 @@
*/
package com.google.eclipse.protobuf.ui.util;
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.*;
-import org.eclipse.ui.ide.FileStoreEditorInput;
-import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.views.navigator.ResourceNavigator;
-import com.google.eclipse.protobuf.ui.editor.UriEditorInput;
import com.google.inject.Singleton;
/**
@@ -68,41 +63,6 @@
}
/**
- * Opens the .proto file identified by the given URI that exists in the workspace.
- * @param uri the URI of the file to open.
- * @return an open and active editor, or {@code null} if an external editor was opened.
- * @throws PartInitException if the editor cannot be opened or initialized.
- */
- public IEditorPart openProtoFileInWorkspace(URI uri) throws PartInitException {
- IFile file = file(uri);
- IEditorInput editorInput = new FileEditorInput(file);
- return openFile(editorInput);
- }
-
- /**
- * Opens the .proto file identified by the given URI that does not exist in the workspace, therefore is
- * opened from the file system.
- * @param uri the URI of the file to open.
- * @return an open and active editor, or {@code null} if an external editor was opened.
- * @throws PartInitException if the editor cannot be created or initialized.
- */
- public IEditorPart openProtoFileInFileSystem(URI uri) throws PartInitException {
- IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(uri.toFileString()));
- IEditorInput editorInput = new FileStoreEditorInput(fileStore);
- return openFile(editorInput/*"org.eclipse.ui.DefaultTextEditor"*/);
- }
-
- public IEditorPart openProtoFileInPlugin(URI uri) throws PartInitException {
- IEditorInput editorInput = new UriEditorInput(uri);
- return openFile(editorInput);
- }
-
- private IEditorPart openFile(IEditorInput editorInput) throws PartInitException {
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- return page.openEditor(editorInput, "com.google.eclipse.protobuf.Protobuf");
- }
-
- /**
* Returns a handle to a workspace file identified by the given URI.
* @param uri the given URI.
* @return a handle to a workspace file identified by the given URI or {@code null} if the URI does not belong to a