Minor 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
index af68bd5..f45cb2c 100644
--- 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
@@ -10,6 +10,9 @@
import static com.google.eclipse.protobuf.ui.util.Workbenches.activeWorkbenchPage;
+import com.google.eclipse.protobuf.ui.util.Uris;
+import com.google.inject.*;
+
import org.eclipse.core.filesystem.*;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Path;
@@ -18,9 +21,6 @@
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.part.FileEditorInput;
-import com.google.eclipse.protobuf.ui.util.Uris;
-import com.google.inject.*;
-
/**
* Utility methods related to open file from different type of locations.
*
@@ -30,24 +30,35 @@
@Inject private Uris uris;
public IEditorPart openProtoFileInWorkspace(URI uri) throws PartInitException {
+ IWorkbenchPage page = activeWorkbenchPage();
+ if (page == null) {
+ return null;
+ }
IFile file = uris.referredFile(uri);
IEditorInput editorInput = new FileEditorInput(file);
- return openFile(editorInput);
+ return openFile(editorInput, page);
}
public IEditorPart openProtoFileInFileSystem(URI uri) throws PartInitException {
+ IWorkbenchPage page = activeWorkbenchPage();
+ if (page == null) {
+ return null;
+ }
IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(uri.toFileString()));
IEditorInput editorInput = new FileStoreEditorInput(fileStore);
- return openFile(editorInput/* "org.eclipse.ui.DefaultTextEditor" */);
+ return openFile(editorInput, page);
}
public IEditorPart openProtoFileInPlugin(URI uri) throws PartInitException {
+ IWorkbenchPage page = activeWorkbenchPage();
+ if (page == null) {
+ return null;
+ }
IEditorInput editorInput = new UriEditorInput(uri);
- return openFile(editorInput);
+ return openFile(editorInput, page);
}
- private IEditorPart openFile(IEditorInput editorInput) throws PartInitException {
- IWorkbenchPage page = activeWorkbenchPage();
+ private IEditorPart openFile(IEditorInput editorInput, IWorkbenchPage page) throws PartInitException {
return page.openEditor(editorInput, "com.google.eclipse.protobuf.Protobuf");
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/DocumentContentsFactoryRegistry.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/DocumentContentsFactoryRegistry.java
deleted file mode 100644
index afb9873..0000000
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/DocumentContentsFactoryRegistry.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.model;
-
-import java.util.List;
-
-import org.eclipse.ui.IEditorInput;
-
-import com.google.common.collect.Lists;
-import com.google.inject.Inject;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class DocumentContentsFactoryRegistry {
- private final List<DocumentContentsFactory> factories;
-
- @Inject
- DocumentContentsFactoryRegistry(FileStoreDocumentContentsFactory f1, UriDocumentContentsFactory f2) {
- factories = Lists.newArrayList(f1, f2);
- }
-
- DocumentContentsFactory findFactory(Object element) {
- if (element instanceof IEditorInput) {
- IEditorInput input = (IEditorInput) element;
- for (DocumentContentsFactory factory : factories) {
- if (factory.supportsEditorInputType(input)) {
- return factory;
- }
- }
- }
- return null;
- }
-}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java
index a32555e..d6ffe95 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java
@@ -9,12 +9,17 @@
*/
package com.google.eclipse.protobuf.ui.editor.model;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.eclipse.protobuf.ui.exception.CoreExceptions.error;
import static com.google.eclipse.protobuf.util.Encodings.UTF_8;
import static org.eclipse.core.filebuffers.FileBuffers.getTextFileBufferManager;
import static org.eclipse.core.filebuffers.LocationKind.*;
import static org.eclipse.text.undo.DocumentUndoManagerRegistry.getDocumentUndoManager;
+import com.google.eclipse.protobuf.ui.preferences.editor.save.core.SaveActionsPreferences;
+import com.google.eclipse.protobuf.ui.util.editor.ChangedLineRegionCalculator;
+import com.google.inject.Inject;
+
import org.eclipse.core.filebuffers.*;
import org.eclipse.core.runtime.*;
import org.eclipse.jface.text.*;
@@ -25,9 +30,7 @@
import org.eclipse.xtext.ui.editor.model.*;
import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess;
-import com.google.eclipse.protobuf.ui.preferences.editor.save.core.SaveActionsPreferences;
-import com.google.eclipse.protobuf.ui.util.editor.ChangedLineRegionCalculator;
-import com.google.inject.Inject;
+import java.util.List;
/**
* @author alruiz@google.com (Alex Ruiz)
@@ -36,12 +39,17 @@
private static final IRegion[] NO_CHANGE = new IRegion[0];
@Inject private ChangedLineRegionCalculator calculator;
- @Inject private DocumentContentsFactoryRegistry documentContentsFactories;
@Inject private IPreferenceStoreAccess storeAccess;
@Inject private SaveActions saveActions;
+ private final List<DocumentContentsFactory> documentFactories;
+
+ @Inject public ProtobufDocumentProvider(FileStoreDocumentContentsFactory f1, UriDocumentContentsFactory f2) {
+ documentFactories = newArrayList(f1, f2);
+ }
+
@Override protected ElementInfo createElementInfo(Object element) throws CoreException {
- if (documentContentsFactories.findFactory(element) != null) {
+ if (findDocumentFactory(element) != null) {
return createElementInfo((IEditorInput) element);
}
return super.createElementInfo(element);
@@ -67,13 +75,24 @@
}
@Override protected IDocument createDocument(Object element) throws CoreException {
- DocumentContentsFactory factory = documentContentsFactories.findFactory(element);
+ DocumentContentsFactory factory = findDocumentFactory(element);
if (factory != null) {
return createDocument(factory, element);
}
return super.createDocument(element);
}
+ private DocumentContentsFactory findDocumentFactory(Object element) {
+ if (element instanceof IEditorInput) {
+ IEditorInput input = (IEditorInput) element;
+ for (DocumentContentsFactory factory : documentFactories) {
+ if (factory.supportsEditorInputType(input)) {
+ return factory;
+ }
+ }
+ }
+ return null;
+ }
private IDocument createDocument(DocumentContentsFactory contentsFactory, Object element) throws CoreException {
XtextDocument document = createEmptyDocument();
contentsFactory.createContents(document, element);