Home » Language IDEs » Java Development Tools (JDT) » Correct instantiation and configuring of JavaSourceViewer
Correct instantiation and configuring of JavaSourceViewer [message #260656] |
Tue, 16 June 2009 19:24 |
Alexander Kiselyov Messages: 3 Registered: July 2009 |
Junior Member |
|
|
Hi, I've got a little problem. I'm trying to create view in my plug-in,
which will contain Java editor with syntax highlighting and other stuff.
For this task I decided to use
org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.
Here is fragment of code from the
createPartControl(org.eclipse.swt.widgets.Composite) method of my view:
IPreferenceStore store = new ScopedPreferenceStore(new InstanceScope(),
Activator.getDefault().getBundle().getSymbolicName());
int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER |
SWT.FULL_SELECTION;
JavaSourceViewer viewer = new JavaSourceViewer(parent, null, null, false,
styles, store);
Activator is a main class of my plug-in (extends from AbstractUIPlugin).
This fragment works fine, except 2 things. First, I can't see text I set
such way:
viewer.getTextWidget().setText("sdlfknjhsadkjlfhn,skdf");
I've explored code of method and decided to change it to:
viewer.getTextWidget().getContents().setText("sdlfknjhsadkjlfhn,skdf ");
(text widget's setText() method have a lot of intermediate code, event
handling, etc and I think its incorrect to do it my way, in contravention
of widget's setText())
And second. As I understood, syntax highliting and other such behavior are
provided by JavaSourceViewerConfiguration class.
JavaSourceViewerConfiguration configuration =
new JavaSourceViewerConfiguration(new JavaColorManager(), store,
this, IJavaPartitions.JAVA_PARTITIONING);
viewer.configure(configuration);
But when I'm tryed to instantiate it and configure viewer with it, I've
got an NPE:
java.lang.NullPointerException
at
org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration.getSet tings(JavaSourceViewerConfiguration.java:813)
at
org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration.getCon tentAssistant(JavaSourceViewerConfiguration.java:392)
at
org.eclipse.jface.text.source.SourceViewer.configure(SourceV iewer.java:370)
at
org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.conf igure(JavaSourceViewer.java:223)
at
com.codesrc.thinktankrcp.projects.FileContentsView.createPar tControl(FileContentsView.java:161)
...
So, I've investigated it and saw that
org.eclipse.jdt.internal.ui.JavaPlugin.getDefault() in
JavaSourceViewerConfiguration.java:813:
IDialogSettings settings=
JavaPlugin.getDefault().getDialogSettings().getSection(secti onName);
returned null. Also I tryed to experiment with
org.eclipse.jdt.internal.ui.javaeditor.JavaEditor and got a lot of similar
NPE in same situations from such classes:
org.eclipse.jdt.internal.ui.JavaPlugin,
org.eclipse.ui.internal.editors.text.EditorsPlugin,
org.eclipse.jdt.core.JavaCore. I've tried to fill it's values by
reflection :), it works, but at first it's a terrible ugly hack, and in
second - I've started to receive many other exceptions in many places, so
it is not correct way. As I understood, something in the Eclipse Platform
should correctly initialize, prepare and tune such classes. Can you help
me with it? Maybe I should differently set up my plug-in project, include
some dependencies to it or something else?
|
|
|
Re: Correct instantiation and configuring of JavaSourceViewer [message #260671 is a reply to message #260656] |
Wed, 17 June 2009 07:56 |
Dani Megert Messages: 3802 Registered: July 2009 |
Senior Member |
|
|
Alexander Kiselyov wrote:
> Hi, I've got a little problem. I'm trying to create view in my
> plug-in, which will contain Java editor with syntax highlighting and
> other stuff. For this task I decided to use
> org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.
Note that this is an internal class which you should not use (try
SourceViewer instead). Having said that, it looks like for some reason
the org.eclipse.jdt.ui plug-in is not loaded and hence you get the NPE.
Make sure that plug-in is listed as required plug-in in your plug-in.
Dani
> Here is fragment of code from the
> createPartControl(org.eclipse.swt.widgets.Composite) method of my view:
>
> IPreferenceStore store = new ScopedPreferenceStore(new InstanceScope(),
> Activator.getDefault().getBundle().getSymbolicName());
> int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER |
> SWT.FULL_SELECTION;
> JavaSourceViewer viewer = new JavaSourceViewer(parent, null, null,
> false, styles, store);
>
> Activator is a main class of my plug-in (extends from
> AbstractUIPlugin). This fragment works fine, except 2 things. First, I
> can't see text I set such way:
> viewer.getTextWidget().setText("sdlfknjhsadkjlfhn,skdf");
>
> I've explored code of method and decided to change it to:
>
> viewer.getTextWidget().getContents().setText("sdlfknjhsadkjlfhn,skdf ");
>
> (text widget's setText() method have a lot of intermediate code, event
> handling, etc and I think its incorrect to do it my way, in
> contravention of widget's setText())
>
> And second. As I understood, syntax highliting and other such behavior
> are provided by JavaSourceViewerConfiguration class.
> JavaSourceViewerConfiguration configuration = new
> JavaSourceViewerConfiguration(new JavaColorManager(), store, this,
> IJavaPartitions.JAVA_PARTITIONING);
> viewer.configure(configuration);
>
> But when I'm tryed to instantiate it and configure viewer with it,
> I've got an NPE:
>
> java.lang.NullPointerException
> at
> org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration.getSet tings(JavaSourceViewerConfiguration.java:813)
>
> at
> org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration.getCon tentAssistant(JavaSourceViewerConfiguration.java:392)
>
> at
> org.eclipse.jface.text.source.SourceViewer.configure(SourceV iewer.java:370)
>
> at
> org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.conf igure(JavaSourceViewer.java:223)
>
> at
> com.codesrc.thinktankrcp.projects.FileContentsView.createPar tControl(FileContentsView.java:161)
>
> ..
>
> So, I've investigated it and saw that
> org.eclipse.jdt.internal.ui.JavaPlugin.getDefault() in
> JavaSourceViewerConfiguration.java:813:
>
> IDialogSettings settings=
> JavaPlugin.getDefault().getDialogSettings().getSection(secti onName);
>
> returned null. Also I tryed to experiment with
> org.eclipse.jdt.internal.ui.javaeditor.JavaEditor and got a lot of
> similar NPE in same situations from such classes:
> org.eclipse.jdt.internal.ui.JavaPlugin,
> org.eclipse.ui.internal.editors.text.EditorsPlugin,
> org.eclipse.jdt.core.JavaCore. I've tried to fill it's values by
> reflection :), it works, but at first it's a terrible ugly hack, and
> in second - I've started to receive many other exceptions in many
> places, so it is not correct way. As I understood, something in the
> Eclipse Platform should correctly initialize, prepare and tune such
> classes. Can you help me with it? Maybe I should differently set up my
> plug-in project, include some dependencies to it or something else?
>
>
|
|
| | | |
Goto Forum:
Current Time: Tue Nov 12 19:52:08 GMT 2024
Powered by FUDForum. Page generated in 0.24209 seconds
|