Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Null Pointer Exception while opening xtext editor with a non workspace file
Null Pointer Exception while opening xtext editor with a non workspace file [message #762806] Thu, 08 December 2011 16:37 Go to next message
Arvind Sharma is currently offline Arvind SharmaFriend
Messages: 17
Registered: December 2011
Junior Member
I am developing an RCP application which has a multipage editor. I have added XText editor to first page. When i open a file which is insde workspace it works perfectly but when i try to open a file external to workspace i am getting null pointer exception

java.lang.NullPointerException
at org.eclipse.xtext.ui.editor.folding.DefaultFoldingStructureProvider.handleProjectionEnabled(DefaultFoldingStructureProvider.java:100)
at org.eclipse.xtext.ui.editor.folding.DefaultFoldingStructureProvider$ProjectionChangeListener.projectionEnabled(DefaultFoldingStructureProvider.java:186)
at org.eclipse.jface.text.source.projection.ProjectionViewer.fireProjectionEnabled(ProjectionViewer.java:489)
at org.eclipse.jface.text.source.projection.ProjectionViewer.enableProjection(ProjectionViewer.java:537)
at org.eclipse.jface.text.source.projection.ProjectionViewer.doOperation(ProjectionViewer.java:1441)
at org.eclipse.xtext.ui.editor.XtextEditor.installFoldingSupport(XtextEditor.java:446)
at org.eclipse.xtext.ui.editor.XtextEditor.createPartControl(XtextEditor.java:428)
at org.eclipse.ui.part.MultiPageEditorPart.addPage(MultiPageEditorPart.java:241)
at org.eclipse.ui.part.MultiPageEditorPart.addPage(MultiPageEditorPart.java:211)

I have used following code to open the external file

IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();

FileDialog openDialog = new FileDialog(window.getShell(), SWT.OPEN);
openDialog.setText("Open VizJSON File");
String filePath = openDialog.open();

// Creating the IFile
if (filePath == null)
return;
IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(path));
if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
try {
IDE.openEditorOnFileStore(page, fileStore);
} catch (Exception e) {
e.printStackTrace();
}
}

I am not able to find a proper solution to this problem. If someone know the solution please help.
Re: Null Pointer Exception while opening xtext editor with a non workspace file [message #762839 is a reply to message #762806] Thu, 08 December 2011 17:32 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
You can only edit files that are in the workspace (physically or
linked). Many of the features of Xtext require this.

In Eclipse/b3 I implemented a solution that links all external files to
a hidden project (and unlinks them when the editor is closed). That
works fine, but was a bit kludgy to implement. Feel free to look at the
b3 code for this.

I gets a lot more complicated when you consider linking, and control of
visibility. I.e. when a file is linked to the hidden project, what
controls its visibility into other elements? In b3, the hidden project
only sees the default runtime - that was good enough.

You will save yourself a lot of trouble by requiring that files are kept
in a workspace.

Hope that helps.
Regards
- henrik

On 2011-08-12 17:37, Arvind Sharma wrote:
> I am developing an RCP application which has a multipage editor. I have
> added XText editor to first page. When i open a file which is insde
> workspace it works perfectly but when i try to open a file external to
> workspace i am getting null pointer exception
>
> java.lang.NullPointerException
> at
> org.eclipse.xtext.ui.editor.folding.DefaultFoldingStructureProvider.handleProjectionEnabled(DefaultFoldingStructureProvider.java:100)
>
> at
> org.eclipse.xtext.ui.editor.folding.DefaultFoldingStructureProvider$ProjectionChangeListener.projectionEnabled(DefaultFoldingStructureProvider.java:186)
>
> at
> org.eclipse.jface.text.source.projection.ProjectionViewer.fireProjectionEnabled(ProjectionViewer.java:489)
>
> at
> org.eclipse.jface.text.source.projection.ProjectionViewer.enableProjection(ProjectionViewer.java:537)
>
> at
> org.eclipse.jface.text.source.projection.ProjectionViewer.doOperation(ProjectionViewer.java:1441)
>
> at
> org.eclipse.xtext.ui.editor.XtextEditor.installFoldingSupport(XtextEditor.java:446)
>
> at
> org.eclipse.xtext.ui.editor.XtextEditor.createPartControl(XtextEditor.java:428)
>
> at
> org.eclipse.ui.part.MultiPageEditorPart.addPage(MultiPageEditorPart.java:241)
>
> at
> org.eclipse.ui.part.MultiPageEditorPart.addPage(MultiPageEditorPart.java:211)
>
>
> I have used following code to open the external file
> IWorkbench wb = PlatformUI.getWorkbench();
> IWorkbenchWindow workbenchWindow = wb.getActiveWorkbenchWindow();
> IWorkbenchPage page = workbenchWindow.getActivePage();
>
> FileDialog openDialog = new FileDialog(window.getShell(), SWT.OPEN);
> openDialog.setText("Open VizJSON File");
> String filePath = openDialog.open();
>
> // Creating the IFile
> if (filePath == null)
> return;
> IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(path));
> if (!fileStore.fetchInfo().isDirectory() &&
> fileStore.fetchInfo().exists()) {
> try {
> IDE.openEditorOnFileStore(page, fileStore);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> I am not able to find a proper solution to this problem. If someone know
> the solution please help.
Previous Topic:Inserting copyright information in generated code
Next Topic:Column oriented editors
Goto Forum:
  


Current Time: Thu Apr 25 23:27:36 GMT 2024

Powered by FUDForum. Page generated in 0.03042 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top