|
From: <caw...@us...> - 2007-03-09 14:33:31
|
Revision: 2111
http://svn.sourceforge.net/rubyeclipse/?rev=2111&view=rev
Author: cawilliams
Date: 2007-03-09 06:33:27 -0800 (Fri, 09 Mar 2007)
Log Message:
-----------
handle external files...
Modified Paths:
--------------
trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/ViewContentProvider.java
Modified: trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/ViewContentProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/ViewContentProvider.java 2007-03-09 14:31:01 UTC (rev 2110)
+++ trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/ViewContentProvider.java 2007-03-09 14:33:27 UTC (rev 2111)
@@ -28,6 +28,7 @@
package org.rubypeople.rdt.astviewer.views;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
@@ -36,7 +37,9 @@
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
@@ -77,9 +80,12 @@
RubyParserPool.getInstance().returnParser(parser);
}
- protected IFile getFile()
- {
- return ((IFileEditorInput) editor.getEditorInput()).getFile();
+ protected IFile getFile() {
+ IEditorInput input = editor.getEditorInput();
+ if (input instanceof IFileEditorInput) {
+ return ((IFileEditorInput) input).getFile();
+ }
+ return null;
}
public Object[] getElements(Object parent) {
@@ -114,13 +120,35 @@
public Node getRootNode() {
LexerSource lexerSource;
try {
- lexerSource = new LexerSource(getFile().getName(), new InputStreamReader(getFile().getContents()));
+ lexerSource = new LexerSource(getName(), new InputStreamReader(getContents()));
return parser.parse(new RubyParserConfiguration(), lexerSource).getAST();
} catch (CoreException e) {
return null;
}
}
+ private String getName() throws CoreException {
+ IFile file = getFile();
+ if (file != null) return file.getName();
+ IEditorInput input = editor.getEditorInput();
+ if (input instanceof IStorageEditorInput) {
+ IStorageEditorInput storageInput = (IStorageEditorInput) input;
+ return storageInput.getStorage().getName();
+ }
+ return "";
+ }
+
+ private InputStream getContents() throws CoreException {
+ IFile file = getFile();
+ if (file != null) return file.getContents();
+ IEditorInput input = editor.getEditorInput();
+ if (input instanceof IStorageEditorInput) {
+ IStorageEditorInput storageInput = (IStorageEditorInput) input;
+ return storageInput.getStorage().getContents();
+ }
+ return null;
+ }
+
private void initialize() {
updateContent();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|