blob: af68bd503e66f3212c337daf6129d8910b7776ad [file] [log] [blame]
/*
* 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 static com.google.eclipse.protobuf.ui.util.Workbenches.activeWorkbenchPage;
import org.eclipse.core.filesystem.*;
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.Uris;
import com.google.inject.*;
/**
* Utility methods related to open file from different type of locations.
*
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton public class FileOpener {
@Inject private Uris uris;
public IEditorPart openProtoFileInWorkspace(URI uri) throws PartInitException {
IFile file = uris.referredFile(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 = activeWorkbenchPage();
return page.openEditor(editorInput, "com.google.eclipse.protobuf.Protobuf");
}
}