Custom Editor with standard Java features [message #199230] |
Tue, 13 March 2007 15:53 |
Eclipse User |
|
|
|
Originally posted by: sgannon200.hotmail.com
Hi all,
I know this may be a basic question to ask here but I'm fairly desperate.
I've created a custom Eclipse editor and I now want to add the standard
Java features, such as error detection and syntax highlighting, provided
by the Eclipse IDE.
In my mind this should be easy enough to achieve, but I've come to a stand
still.
My editor extends TextEditor and as far as I know all I need is to set the
SourceViewerConfiguration. This has proven difficult.
My code is as follows:
public class PPIMEditor extends TextEditor
{
private UIAccessor uiAccessor; // My own class which accesses the UI.
.
.
public PPIMEditor()
{
super();
}
.
.
public void createPartControl(final Composite parent)
{
super.createPartControl(parent);
uiAccessor = new UIAccessor(parent, this);
}
.
.
protected void initializeEditor()
{
super.initializeEditor();
IPreferenceStore myStore = new PreferenceStore();
JavaTextTools myTools = new JavaTextTools( myStore );
SourceViewerConfiguration myCfg = new
JavaSourceViewerConfiguration(myTools.getColorManager(), myStore, this,
null);
setSourceViewerConfiguration( myCfg );
}
.
.
// Handles a control-z issue, but is not a part of the problem - I think?
protected IOperationApprover getUndoRedoOperationApprover(IUndoContext
undoContext)
{
approver = new
PPIMOperationApprover(super.getUndoRedoOperationApprover(und oContext));
return approver;
}
.
.
}
From what I have read I think this should create the editor (but it may
not have the colour highlighting and syntax correction features because of
IPreferenceStore myStore = new PreferenceStore()).
However when I run this application from the testing feature of plugin.xml
I get the following error message:
Unable to create this part due to an internal error. Reason for the
failure: An unexpected exception was thrown.
And after choosing "<<Details":
java.lang.NullPointerException
at
org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrateg y. <init>(JavaReconcilingStrategy.java:63)
at
org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStr ategy. <init>(JavaCompositeReconcilingStrategy.java:45)
at
org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration.getRec onciler(JavaSourceViewerConfiguration.java:442)
at
org.eclipse.jface.text.source.SourceViewer.configure(SourceV iewer.java:353)
at
org.eclipse.ui.texteditor.AbstractTextEditor.createPartContr ol(AbstractTextEditor.java:2553)
at
org.eclipse.ui.texteditor.StatusTextEditor.createPartControl (StatusTextEditor.java:53)
at
org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.create PartControl(AbstractDecoratedTextEditor.java:367)
at editor.PPIMEditor.createPartControl(PPIMEditor.java:84)
.
.
.
In the PPIMEditor the problem is traced to
public void createPartControl(final Composite parent)
{
super.createPartControl(parent);// Source of error
uiAccessor = new UIAccessor(parent, this);
}
This error is really causing me problems. I don't know why an Eclipse
method such as super.createPartControl should cause this failure.
I also tried to use:
JavaTextTools jTools = JavaPlugin.getDefault().getJavaTextTools();
setSourceViewerConfiguration(new
JavaSourceViewerConfiguration(jTools.getColorManager(),
JavaPlugin.getDefault().getPreferenceStore(), this,
IJavaPartitions.JAVA_PARTITIONING));
but everytime I used JavaPlugin.getDefault().* it gave an error. Is there
some way to initialize JavaPlugin so it will work? Could this be the cause
of the problem?
I'm currently using Eclipse 3.2 and Java 1.5.
Any help would be greatly appreciated as I need this feature to work.
|
|
|
Re: Custom Editor with standard Java features [message #199247 is a reply to message #199230] |
Tue, 13 March 2007 16:14 |
Dani Megert Messages: 3802 Registered: July 2009 |
Senior Member |
|
|
Shane Gannon wrote:
> Hi all,
>
> I know this may be a basic question to ask here but I'm fairly desperate.
>
> I've created a custom Eclipse editor and I now want to add the
> standard Java features, such as error detection and syntax
> highlighting, provided by the Eclipse IDE.
>
> In my mind this should be easy enough to achieve, but I've come to a
> stand still.
>
> My editor extends TextEditor and as far as I know all I need is to set
> the SourceViewerConfiguration. This has proven difficult.
>
> My code is as follows:
>
> public class PPIMEditor extends TextEditor
> {
> private UIAccessor uiAccessor; // My own class which accesses the UI.
> .
> .
>
> public PPIMEditor()
> {
> super();
> }
>
> .
> .
>
> public void createPartControl(final Composite parent)
> {
> super.createPartControl(parent);
> uiAccessor = new UIAccessor(parent, this);
> }
>
> .
> .
>
> protected void initializeEditor()
> {
> super.initializeEditor();
> IPreferenceStore myStore = new PreferenceStore();
> JavaTextTools myTools = new JavaTextTools( myStore );
> SourceViewerConfiguration myCfg = new
> JavaSourceViewerConfiguration(myTools.getColorManager(), myStore,
> this, null);
> setSourceViewerConfiguration( myCfg );
> }
>
> .
> .
>
> // Handles a control-z issue, but is not a part of the problem - I
> think?
> protected IOperationApprover
> getUndoRedoOperationApprover(IUndoContext undoContext)
> {
> approver = new
> PPIMOperationApprover(super.getUndoRedoOperationApprover(und oContext));
> return approver;
> }
>
> .
> .
> }
>
> From what I have read I think this should create the editor (but it
> may not have the colour highlighting and syntax correction features
> because of IPreferenceStore myStore = new PreferenceStore()).
>
> However when I run this application from the testing feature of
> plugin.xml I get the following error message:
>
> Unable to create this part due to an internal error. Reason for the
> failure: An unexpected exception was thrown.
>
> And after choosing "<<Details":
>
> java.lang.NullPointerException
> at
> org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrateg y. <init>(JavaReconcilingStrategy.java:63)
>
> at
> org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStr ategy. <init>(JavaCompositeReconcilingStrategy.java:45)
>
> at
> org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration.getRec onciler(JavaSourceViewerConfiguration.java:442)
>
> at
> org.eclipse.jface.text.source.SourceViewer.configure(SourceV iewer.java:353)
>
> at
> org.eclipse.ui.texteditor.AbstractTextEditor.createPartContr ol(AbstractTextEditor.java:2553)
>
> at
> org.eclipse.ui.texteditor.StatusTextEditor.createPartControl (StatusTextEditor.java:53)
>
> at
> org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.create PartControl(AbstractDecoratedTextEditor.java:367)
>
> at editor.PPIMEditor.createPartControl(PPIMEditor.java:84)
> .
> .
This NPE happens because the JDT UI plug-in wasn't loaded. There are
various reasons for that:
- you missed to declare it as required
- you are not launching as Eclipse Application but a normal Java Application
- some other issue
Dani
> .
>
>
> In the PPIMEditor the problem is traced to
> public void createPartControl(final Composite parent)
> {
> super.createPartControl(parent);// Source of error
> uiAccessor = new UIAccessor(parent, this);
> }
>
> This error is really causing me problems. I don't know why an Eclipse
> method such as super.createPartControl should cause this failure.
>
> I also tried to use:
>
> JavaTextTools jTools = JavaPlugin.getDefault().getJavaTextTools();
> setSourceViewerConfiguration(new
> JavaSourceViewerConfiguration(jTools.getColorManager(),
> JavaPlugin.getDefault().getPreferenceStore(), this,
> IJavaPartitions.JAVA_PARTITIONING));
>
> but everytime I used JavaPlugin.getDefault().* it gave an error. Is
> there some way to initialize JavaPlugin so it will work? Could this be
> the cause of the problem?
>
> I'm currently using Eclipse 3.2 and Java 1.5.
>
> Any help would be greatly appreciated as I need this feature to work.
>
|
|
|
Re: Custom Editor with standard Java features [message #199385 is a reply to message #199247] |
Wed, 14 March 2007 11:19 |
Eclipse User |
|
|
|
Originally posted by: sgannon200.hotmail.com
This NPE happens because the JDT UI plug-in wasn't loaded. There are
various reasons for that:
- you missed to declare it as required
- you are not launching as Eclipse Application but a normal Java
Application
- some other issue
Dani
Hi Daniel
You were right. I had "org.eclipse.jdt.ui" declared in plugin.xml on the
Runtime - Classpath section, when it should really have been declared in
Dependencies - Required Plug-ins.
Thank you, this problem has bugged me for weeks.
For anybody else interested in getting their editor to use the standard
Java features you can use:
JavaTextTools jTools = JavaPlugin.getDefault().getJavaTextTools();
setSourceViewerConfiguration(new
JavaSourceViewerConfiguration(jTools.getColorManager(),
JavaPlugin.getDefault().getPreferenceStore(), this,
IJavaPartitions.JAVA_PARTITIONING));
as the previous code will not provide error correction and syntax
highlighting.
|
|
|
|
Powered by
FUDForum. Page generated in 0.08550 seconds