Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » NullPointer thrown by JSEditor.getLineStyleListener()
NullPointer thrown by JSEditor.getLineStyleListener() [message #151185] Fri, 09 December 2005 04:02 Go to next message
Eclipse UserFriend
Originally posted by: amitgolwala.gmail.com

Hi all,

I have coded a customized view which displays a list of all
JavaScript(.js) files. What I really want is that when the user double
clicks on any of the .js files the default JSEditor should open. In order
to open the editor I am making a funciton call in a following manner:-

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().
openEditor(new PathEditorInput(path),
" org.eclipse.wst.javascript.ui.internal.editor.JSMultiPageEdi torPart ");

PathEditorInput is the class that implements IEditorInput interface. The
editor id specified is the id of default JSEditor (I found it from the
plugin.xml file). Below mentioned is the error which i keep on getting
from the function call above. Also, the tragedy is that if I double click
on the .js file from "Package Explorer" view that does results in opening
of default JSEditor

waitingo for the help ......

java.lang.NullPointerException
at
org.eclipse.wst.javascript.ui.internal.editor.JSEditor.getLi neStyleListener(JSEditor.java:879)
at
org.eclipse.wst.javascript.ui.internal.editor.JSEditor.dispo se(JSEditor.java:753)
at
org.eclipse.wst.javascript.ui.internal.editor.JSEditor.doSet Input(JSEditor.java:803)
at
org.eclipse.ui.texteditor.AbstractTextEditor$16.run(Abstract TextEditor.java:2360)
at
org.eclipse.jface.operation.ModalContext.runInCurrentThread( ModalContext.java:346)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.ja va:291)
at
org.eclipse.jface.window.ApplicationWindow$1.run(Application Window.java:624)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:69)
at
org.eclipse.jface.window.ApplicationWindow.run(ApplicationWi ndow.java:621)
at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow. java:2134)
at
org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(Ab stractTextEditor.java:2378)
at
org.eclipse.ui.texteditor.AbstractTextEditor.init(AbstractTe xtEditor.java:2405)
at
org.eclipse.ui.internal.EditorManager.createSite(EditorManag er.java:773)
at
org.eclipse.ui.internal.EditorReference.createPartHelper(Edi torReference.java:572)
at
org.eclipse.ui.internal.EditorReference.createPart(EditorRef erence.java:365)
at
org.eclipse.ui.internal.WorkbenchPartReference.getPart(Workb enchPartReference.java:552)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:28 3)
at
org.eclipse.ui.internal.presentations.PresentablePart.setVis ible(PresentablePart.java:126)
at
org.eclipse.ui.internal.presentations.util.PresentablePartFo lder.select(PresentablePartFolder.java:268)
at
org.eclipse.ui.internal.presentations.util.LeftToRightTabOrd er.select(LeftToRightTabOrder.java:65)
at
org.eclipse.ui.internal.presentations.util.TabbedStackPresen tation.selectPart(TabbedStackPresentation.java:391)
at
org.eclipse.ui.internal.PartStack.refreshPresentationSelecti on(PartStack.java:1102)
at org.eclipse.ui.internal.PartStack.setSelection(PartStack.jav a:1051)
at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:12 56)
at org.eclipse.ui.internal.PartStack.add(PartStack.java:442)
at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:109 )
at
org.eclipse.ui.internal.EditorSashContainer.addEditor(Editor SashContainer.java:60)
at
org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorA reaHelper.java:212)
at
org.eclipse.ui.internal.EditorAreaHelper.addEditor(EditorAre aHelper.java:202)
at
org.eclipse.ui.internal.EditorManager.createEditorTab(Editor Manager.java:753)
at
org.eclipse.ui.internal.EditorManager.openEditorFromDescript or(EditorManager.java:665)
at
org.eclipse.ui.internal.EditorManager.openEditor(EditorManag er.java:628)
at
org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched( WorkbenchPage.java:2323)
at
org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(Workben chPage.java:2258)
at org.eclipse.ui.internal.WorkbenchPage.access$9(WorkbenchPage .java:2250)
at org.eclipse.ui.internal.WorkbenchPage$9.run(WorkbenchPage.ja va:2236)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:69)
at
org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPa ge.java:2231)
at
org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPa ge.java:2204)
at
com.tycoint.meridian.scripteditors.view.ScriptListView.openE ditor(ScriptListView.java:162)
at
com.tycoint.meridian.scripteditors.view.ScriptListView.acces s$2(ScriptListView.java:157)
at
com.tycoint.meridian.scripteditors.view.ScriptListView$1.dou bleClick(ScriptListView.java:153)
at
org.eclipse.jface.viewers.StructuredViewer$1.run(StructuredV iewer.java:720)
at
org.eclipse.core.internal.runtime.InternalPlatform.run(Inter nalPlatform.java:1044)
at org.eclipse.core.runtime.Platform.run(Platform.java:783)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:44)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:14 8)
at
org.eclipse.jface.viewers.StructuredViewer.fireDoubleClick(S tructuredViewer.java:718)
at
org.eclipse.jface.viewers.StructuredViewer.handleDoubleSelec t(StructuredViewer.java:950)
at
org.eclipse.jface.viewers.StructuredViewer$4.widgetDefaultSe lected(StructuredViewer.java:1057)
at
org.eclipse.jface.util.OpenStrategy.fireDefaultSelectionEven t(OpenStrategy.java:219)
at org.eclipse.jface.util.OpenStrategy.access$0(OpenStrategy.ja va:216)
at
org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrate gy.java:275)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:843)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3080)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2713)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1699)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1663)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:367)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:143)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplicatio n.java:103)
at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:226)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:376)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:334 )
at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
at org.eclipse.core.launcher.Main.run(Main.java:973)
at org.eclipse.core.launcher.Main.main(Main.java:948)
Re: NullPointer thrown by JSEditor.getLineStyleListener() [message #151274 is a reply to message #151185] Sat, 10 December 2005 03:17 Go to previous messageGo to next message
David Williams is currently offline David WilliamsFriend
Messages: 722
Registered: July 2009
Senior Member
>
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().
> openEditor(new PathEditorInput(path),
> " org.eclipse.wst.javascript.ui.internal.editor.JSMultiPageEdi torPart ")=
;
>
> .....
> waitingo for the help ......
>
> java.lang.NullPointerException
> at
> org.eclipse.wst.javascript.ui.internal.editor.JSEditor.getLi neStyleLis=
tener(JSEditor.java:879)
> at
> org.eclipse.wst.javascript.ui.internal.editor.JSEditor.dispo se(JSEdito=
r.java:753)
> at
> ........

I'll give a "guess". If you look at the source code for the methods invo=
lved,
you'll see
protected JSLineStyleListener getLineStyleListener() {
if (fLineStyleListener =3D=3D null) {
IDocument document =3D getDocumentProvider().getDocument(getEditorInp=
ut());
fLineStyleListener =3D new JSLineStyleListener(document, getSourceVie=
wer());
}
return fLineStyleListener;
}

so, only thing that could be null is getDocumentProvider.
Perhaps you need to set/provide one of those?

And ... when you use non-API in ways we have not really planned for, you=
will want to be
sure to open bugs and/or feature requests that explain what you are tryi=
ng a accomplish and what
you would like in some future version .... and, better, provide a fix/pa=
tch along with it! :)
Re: NullPointer thrown by JSEditor.getLineStyleListener() [message #151391 is a reply to message #151274] Sun, 11 December 2005 23:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: amitgolwala.gmail.com

David Williams wrote:
>>
>> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().
>> openEditor(new PathEditorInput(path),
>> " org.eclipse.wst.javascript.ui.internal.editor.JSMultiPageEdi torPart ");
>>
>> .....
>> waitingo for the help ......
>>
>> java.lang.NullPointerException
>> at
>>
org.eclipse.wst.javascript.ui.internal.editor.JSEditor.getLi neStyleListener(JSEditor.java:879)
>> at
>>
org.eclipse.wst.javascript.ui.internal.editor.JSEditor.dispo se(JSEditor.java:753)
>> at
>> ........

> I'll give a "guess". If you look at the source code for the methods involved,
> you'll see
> protected JSLineStyleListener getLineStyleListener() {
> if (fLineStyleListener == null) {
> IDocument document = getDocumentProvider().getDocument(getEditorInput());
> fLineStyleListener = new JSLineStyleListener(document, getSourceViewer());
> }
> return fLineStyleListener;
> }

> so, only thing that could be null is getDocumentProvider.
> Perhaps you need to set/provide one of those?

> And ... when you use non-API in ways we have not really planned for, you
will want to be
> sure to open bugs and/or feature requests that explain what you are trying a
accomplish and what
> you would like in some future version .... and, better, provide a fix/patch
along with it! :)Hi,

Yeah, what u r saying may be correct but then if u just have a look at the
openEditor() function call, then u can see that I m straight away making a
call to the Java Script Editor using its editors id. I m not at all using
any other class that extends JSEditor class or other relevant class. So in
that case how can I set the DocumentProvider for the editor.

Still wandering ......

If the above mentioned method is not appropriate for calling JSEditor then
do suggest the alternate way, if possible.

waiting for any of your replies...

Amit !!
Re: NullPointer thrown by JSEditor.getLineStyleListener() [message #151397 is a reply to message #151274] Sun, 11 December 2005 23:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: amitgolwala.gmail.com

Yeah, what u r saying may be correct but then if u just have a look at the
openEditor() function call, then u can see that I m straight away making a
call to the Java Script Editor using its editors id. I m not at all using
any other class that extends JSEditor class or other relevant class. So in
that case how can I set the DocumentProvider for the editor.

Still wandering ......

If the above mentioned method is not appropriate for calling JSEditor then
do suggest the alternate way, if possible.

waiting for any of your replies...

Amit !!
Re: NullPointer thrown by JSEditor.getLineStyleListener() [message #151412 is a reply to message #151391] Mon, 12 December 2005 01:57 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4434
Registered: July 2009
Senior Member

Amit wrote:
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().
>openEditor(new PathEditorInput(path), " org.eclipse.wst.javascript.ui.internal.editor.JSMultiPageEdi torPart ");

>PathEditorInput is the class that implements IEditorInput interface.

> Yeah, what u r saying may be correct but then if u just have a look at
> the openEditor() function call, then u can see that I m straight away
> making a call to the Java Script Editor using its editors id. I m not at
> all using any other class that extends JSEditor class or other relevant
> class. So in that case how can I set the DocumentProvider for the editor.

The platform uses the extension registry to map from IEditorInput
types to an appropriate IDocumentProvider. While everything's in
place for the IDocumentProviders included in the Platform, I'm
guessing that PathEditorInput is a new type you've created
implementing IPathEditorInput. If so, it sounds like you've not
registered a document provider for it. You'll need to add something
like this to your plugin.xml:

<extension point="org.eclipse.ui.editors.documentProviders">
<provider
inputTypes="PathEditorInput"
class="org.eclipse.ui.editors.text.TextFileDocumentProvider "
id="PathEditorInputTextFileDocumentProvider">
</provider>
</extension>

--
- Nitin


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: NullPointer thrown by JSEditor.getLineStyleListener() [message #151420 is a reply to message #151412] Mon, 12 December 2005 03:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: amitgolwala.gmail.com

Hi Nitin, thanks a lot for ur reply..

I have followed the steps as mentioned in the previous posting but the
result is the same. I still keep getting the same error. Can u please tell
me that registering "DocumentProvider" is enough? What I want to tell is
that, I am straight away calling the "JSEditor" using its plugin id
(" org.eclipse.wst.javascript.ui.internal.editor.JSMultiPageEdi torPart ")
along with PathEditorInput object (which implements IEditorInput
interface) using openEditor () function in one of my classes that extends
ViewPart. I am not at all extending any FormEditor, JSEditor, etc classes.
I am not sure whether thats appropriate or not !!

do reply asap...

waiting for the help !!
Re: NullPointer thrown by JSEditor.getLineStyleListener() [message #151428 is a reply to message #151412] Mon, 12 December 2005 04:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: amitgolwala.gmail.com

Nitin Dahyabhai wrote:

> <extension point="org.eclipse.ui.editors.documentProviders">
> <provider
> inputTypes="PathEditorInput"
> class="org.eclipse.ui.editors.text.TextFileDocumentProvider "
> id="PathEditorInputTextFileDocumentProvider">
> </provider>
> </extension>

I m sorry as I didnt posted my source code in last posting, but following
is the code for my Viewer:

public class SListView extends ViewPart {
private ListViewer viewer;
public SListView() {
super();
}
public void init(IViewSite site) throws PartInitException {
super.init(site);
}
public void createPartControl(Composite parent) {
viewer = new ListViewer(parent);
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setContentProvider(new ViewContentProvider());
this.setDoubleClickListener();
viewer.setInput(this.getViewSite());
}

private void setDoubleClickListener () {
viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick (DoubleClickEvent event) {
String token = new StringTokenizer(event.getSelection().toString(),
"[]").nextToken();
String fileName =
(String)fileNames.elementAt(categoryNames.indexOf(token));
openEditor (fileName.trim());
}
});
}
private void openEditor (String fileName) {
try {

IPath path = new Path (filePath.concat(fileName));
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().openEditor(
new PathEditorInput(path),
"org.eclipse.wst.javascript." +
"ui.internal.editor.JSMultiPageEditorPart");
} catch (Exception e) {
e.printStackTrace();
}
}
}

I do have codes for displaying the filenames in the above view along with
the ViewLabelProvider and ViewContentProvider. But showing them might
result in growing of the size of this posting !!

Follwing is the code of the class that implements IEditorInput:

lic class PathEditorInput implements IEditorInput {

private IPath path;
public PathEditorInput(IPath path) {
this.path = path;
}

public IPath getPath() {
return this.path;
}

public boolean exists() {
return this.path.toFile().exists();
}

public ImageDescriptor getImageDescriptor() {
return
PlatformUI.getWorkbench().getEditorRegistry().getImageDescri ptor(this.path.toString());
}

public String getName() {
return this.path.toFile().getName();
}

public IPersistableElement getPersistable() {
return null;
}

public String getToolTipText() {
return this.path.makeRelative().toString();
}

public Object getAdapter(Class adapter) {
return null;
}

/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof PathEditorInput))
return false;
PathEditorInput other = (PathEditorInput) obj;
return this.path.equals(other.path);
}

/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return this.path.hashCode();
}
}

waiting for the reply !!
Re: NullPointer thrown by JSEditor.getLineStyleListener() [message #151512 is a reply to message #151428] Mon, 12 December 2005 23:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: amywu.us.DELETETHISPART.ibm.com

Is there a reason why you are creating your own editor input?
You could use one of the openEditor methods in org.eclipse.ui.ide.IDE and
instead of an editor input, you would just need an IFile.
For example:
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
IFile file = null;
IFile[] files =
ResourcesPlugin.getWorkspace().getRoot().findFilesForLocatio n(new
Path(fileName));
for (int i = 0; i < files.length && file == null; i++)
if (files[i].exists())
file = files[i];
IDE.openEditor(page, file,
" org.eclipse.wst.javascript.ui.internal.editor.JSMultiPageEdi torPart ");

Of course, this can be cleaned up some more, but that's the main idea. You
can probably search around for others using similar code.


"Amit" <amitgolwala@gmail.com> wrote in message
news:d06efacebb0a1bcf702a1c3a0e00640e$1@www.eclipse.org...
> Nitin Dahyabhai wrote:
>
> > <extension point="org.eclipse.ui.editors.documentProviders">
> > <provider
> > inputTypes="PathEditorInput"
> > class="org.eclipse.ui.editors.text.TextFileDocumentProvider "
> > id="PathEditorInputTextFileDocumentProvider">
> > </provider>
> > </extension>
>
> I m sorry as I didnt posted my source code in last posting, but following
> is the code for my Viewer:
>
> public class SListView extends ViewPart {
> private ListViewer viewer;
> public SListView() {
> super();
> }
> public void init(IViewSite site) throws PartInitException {
> super.init(site);
> }
> public void createPartControl(Composite parent) {
> viewer = new ListViewer(parent);
> viewer.setLabelProvider(new ViewLabelProvider());
> viewer.setContentProvider(new ViewContentProvider());
> this.setDoubleClickListener();
> viewer.setInput(this.getViewSite());
> }
>
> private void setDoubleClickListener () {
> viewer.addDoubleClickListener(new IDoubleClickListener() {
> public void doubleClick (DoubleClickEvent event) {
> String token = new StringTokenizer(event.getSelection().toString(),
> "[]").nextToken();
> String fileName =
> (String)fileNames.elementAt(categoryNames.indexOf(token));
> openEditor (fileName.trim());
> }
> });
> }
> private void openEditor (String fileName) {
> try {
>
> IPath path = new Path (filePath.concat(fileName));
> PlatformUI.getWorkbench().getActiveWorkbenchWindow()
> .getActivePage().openEditor(
> new PathEditorInput(path),
> "org.eclipse.wst.javascript." +
> "ui.internal.editor.JSMultiPageEditorPart");
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
>
> I do have codes for displaying the filenames in the above view along with
> the ViewLabelProvider and ViewContentProvider. But showing them might
> result in growing of the size of this posting !!
>
> Follwing is the code of the class that implements IEditorInput:
>
> lic class PathEditorInput implements IEditorInput {
>
> private IPath path;
> public PathEditorInput(IPath path) {
> this.path = path;
> }
>
> public IPath getPath() {
> return this.path;
> }
>
> public boolean exists() {
> return this.path.toFile().exists();
> }
>
> public ImageDescriptor getImageDescriptor() {
> return
>
PlatformUI.getWorkbench().getEditorRegistry().getImageDescri ptor(this.path.t
oString());
> }
>
> public String getName() {
> return this.path.toFile().getName();
> }
>
> public IPersistableElement getPersistable() {
> return null;
> }
>
> public String getToolTipText() {
> return this.path.makeRelative().toString();
> }
>
> public Object getAdapter(Class adapter) {
> return null;
> }
>
> /* (non-Javadoc)
> * @see java.lang.Object#equals(java.lang.Object)
> */
> public boolean equals(Object obj) {
> if (this == obj)
> return true;
> if (!(obj instanceof PathEditorInput))
> return false;
> PathEditorInput other = (PathEditorInput) obj;
> return this.path.equals(other.path);
> }
>
> /* (non-Javadoc)
> * @see java.lang.Object#hashCode()
> */
> public int hashCode() {
> return this.path.hashCode();
> }
> }
>
> waiting for the reply !!
>
Re: NullPointer thrown by JSEditor.getLineStyleListener() [message #152384 is a reply to message #151512] Thu, 15 December 2005 01:25 Go to previous message
Eclipse UserFriend
Originally posted by: amitgolwala.gmail.com

Amy Wu wrote:

> Is there a reason why you are creating your own editor input?
> You could use one of the openEditor methods in org.eclipse.ui.ide.IDE and
> instead of an editor input, you would just need an IFile.
> For example:
> IWorkbenchPage page =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> IFile file = null;
> IFile[] files =
> ResourcesPlugin.getWorkspace().getRoot().findFilesForLocatio n(new
> Path(fileName));
> for (int i = 0; i < files.length && file == null; i++)
> if (files[i].exists())
> file = files[i];
> IDE.openEditor(page, file,
> " org.eclipse.wst.javascript.ui.internal.editor.JSMultiPageEdi torPart ");

> Of course, this can be cleaned up some more, but that's the main idea. You
> can probably search around for others using similar code.

Hi all,

Yeah I know that I can use IFile but the only reason of not using IFile is
because I dont want to import org.eclipse.core.resources in my project. I
was trying to find a work around so that I dont have to import that
package. ne ways, finally I got the solution. As replied by other guys I
have extended the "AbstractDocumentProvider" class and has override few of
its methods and got the JSEditor opened and working as it should be.
thanks a lot mates for ur help !! Cheeers !!

Amit
Previous Topic:WTP 1.0 RC4 bug when removing files
Next Topic:How to get the autocompletion feature working in JSEditor
Goto Forum:
  


Current Time: Sat Apr 20 03:47:31 GMT 2024

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

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

Back to the top