Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Customize the xtext editor itself(Entry point of xtext editor ?)
Customize the xtext editor itself [message #1117493] Thu, 26 September 2013 14:03 Go to next message
Aurélien Lebeau is currently offline Aurélien LebeauFriend
Messages: 16
Registered: September 2013
Junior Member
Hello,


In my RCP, I am currently migrating from a simple "hand-made" editor to and Xtext one. Until here, it was successful.

The problem is that I have some functionalities as "Watchpoints" (kind of breakpoints) in my old editor that I would like to reimplement in the Xtext editor. What is the entry point of this editor ? In what class is it defined ? How to customize it ?


Thanks ! Smile
Re: Customize the xtext editor itself [message #1117531 is a reply to message #1117493] Thu, 26 September 2013 14:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi

the Class is called XtextEditor. you can bind a subclass in the uimodule.

public Class<? extends org.eclipse.xtext.ui.editor.XtextEditor> bindXtextEditor() {
return YourEditor.class;
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Customize the xtext editor itself [message #1118364 is a reply to message #1117531] Fri, 27 September 2013 10:29 Go to previous messageGo to next message
Aurélien Lebeau is currently offline Aurélien LebeauFriend
Messages: 16
Registered: September 2013
Junior Member
Thanks for the pointer ! I got SLEditor that extends XtextEditor.

But I got some exceptions :

1    [main] ERROR org.eclipse.xtext.ui.editor.CompoundXtextEditorCallback  - Was configured with another client or not configured at all.
java.lang.IllegalStateException: Was configured with another client or not configured at all.
	at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport.removeDirtyStateSupport(DirtyStateEditorSupport.java:342)
	at org.eclipse.xtext.ui.editor.AbstractDirtyStateAwareEditorCallback.beforeDispose(AbstractDirtyStateAwareEditorCallback.java:38)
	at org.eclipse.xtext.ui.editor.CompoundXtextEditorCallback.beforeDispose(CompoundXtextEditorCallback.java:69)
	at org.eclipse.xtext.ui.editor.XtextEditor.dispose(XtextEditor.java:522)
	at myBrandNewEditor.dispose(SLEditor.java:155)
...


And
!MESSAGE Unable to create editor ID DSLEditor.Sl: org.eclipse.jface.text.source.projection.ProjectionViewer cannot be cast to org.eclipse.xtext.ui.editor.XtextSourceViewer
!STACK 0
java.lang.ClassCastException: org.eclipse.jface.text.source.projection.ProjectionViewer cannot be cast to org.eclipse.xtext.ui.editor.XtextSourceViewer
	at org.eclipse.xtext.ui.editor.XtextEditor.installHighlightingHelper(XtextEditor.java:512)
	at org.eclipse.xtext.ui.editor.XtextEditor.createPartControl(XtextEditor.java:474)
	at myBrandNewEditor.createPartControl(SLEditor.java:242)



I noticed that the corresponding lines in SLEditor are calls to super.
SLEditor.java:155 is super.dispose();
SLEditor.java:242 is super.createPartControl(parent);

What can give these exceptions ?
Need to give and ID to the editor ?

Re: Customize the xtext editor itself [message #1118453 is a reply to message #1118364] Fri, 27 September 2013 12:30 Go to previous messageGo to next message
Aurélien Lebeau is currently offline Aurélien LebeauFriend
Messages: 16
Registered: September 2013
Junior Member
I tried to move the editor in the same package as DSLEditorUI (old DSLEditor.ui) but I get this stack
!MESSAGE org.eclipse.xtext.service.CompoundModule  - java.lang.reflect.InvocationTargetException

!STACK 0
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at org.eclipse.xtext.service.MethodBasedModule.invokeMethod(MethodBasedModule.java:136)
	at org.eclipse.xtext.service.MethodBasedModule.configure(MethodBasedModule.java:49)
	at org.eclipse.xtext.service.CompoundModule.configure(CompoundModule.java:34)
	at org.eclipse.xtext.service.AbstractGenericModule.configure(AbstractGenericModule.java:32)
	at org.eclipse.xtext.ui.DefaultUiModule.configure(DefaultUiModule.java:123)
	at eu.macqel.myosotisDSLEditor.ui.SlUiModule.configure(SlUiModule.java:38)
	at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
	at com.google.inject.spi.Elements.getElements(Elements.java:101)
	at com.google.inject.spi.Elements.getElements(Elements.java:92)
	at com.google.inject.util.Modules$RealOverriddenModuleBuilder$1.configure(Modules.java:172)
	at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
	at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
	at com.google.inject.spi.Elements.getElements(Elements.java:101)
	at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133)
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
	at com.google.inject.Guice.createInjector(Guice.java:95)
	at com.google.inject.Guice.createInjector(Guice.java:72)
	at com.google.inject.Guice.createInjector(Guice.java:62)
	at eu.macqel.myosotisDSLEditor.ui.internal.SlActivator.createInjector(SlActivator.java:67)
	at eu.macqel.myosotisDSLEditor.ui.internal.SlActivator.getInjector(SlActivator.java:55)
	at eu.macqel.myosotisDSLEditor.ui.SlExecutableExtensionFactory.getInjector(SlExecutableExtensionFactory.java:26)
	at org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory.create(AbstractGuiceAwareExecutableExtensionFactory.java:49)
	at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:262)
	at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
	at org.eclipse.ui.internal.WorkbenchPlugin.createExtension(WorkbenchPlugin.java:260)
	at org.eclipse.ui.internal.registry.EditorDescriptor.createEditor(EditorDescriptor.java:235)
	at org.eclipse.ui.internal.EditorManager.createPart(EditorManager.java:875)
	at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:609)
	at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:465)
	at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
	at org.eclipse.ui.internal.EditorAreaHelper.setVisibleEditor(EditorAreaHelper.java:271)
	at org.eclipse.ui.internal.EditorManager.setVisibleEditor(EditorManager.java:1459)
	at org.eclipse.ui.internal.EditorManager$5.runWithException(EditorManager.java:972)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3537)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3189)
	at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
	at org.eclipse.ui.internal.Workbench$33.runWithException(Workbench.java:1600)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3537)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3189)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2609)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at eu.macqel.myosotis.workshop.Application.start(Application.java:149)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.eclipse.xtext.service.MethodBasedModule.invokeMethod(MethodBasedModule.java:134)
	... 64 more
Caused by: java.lang.NoClassDefFoundError: eu/macqel/myosotisDSLEditor/SLEditor
	at eu.macqel.myosotisDSLEditor.ui.SlUiModule.bindXtextEditor(SlUiModule.java:52)
	... 69 more
Caused by: java.lang.ClassNotFoundException: eu.macqel.myosotisDSLEditor.SLEditor
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:455)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 70 more


I don't understand why I get a ClassNotFoundException as my class does exists and is in the same package.
Re: Customize the xtext editor itself [message #1118471 is a reply to message #1118453] Fri, 27 September 2013 12:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Sry no idea

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Customize the xtext editor itself [message #1118503 is a reply to message #1118471] Fri, 27 September 2013 13:25 Go to previous messageGo to next message
Aurélien Lebeau is currently offline Aurélien LebeauFriend
Messages: 16
Registered: September 2013
Junior Member
To sum up, in order to override the xtextEditor, I have to

- Create the editor file like
public class myNewEditor extends XtextEditor...

- Add this to my DSLUiModule
public Class<? extends XtextEditor> bindXtextEditor() {
return myNewEditor.class;
}


And that's it ?

[Updated on: Fri, 27 September 2013 13:25]

Report message to a moderator

Re: Customize the xtext editor itself [message #1118543 is a reply to message #1118503] Fri, 27 September 2013 14:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
yes

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Customize the xtext editor itself [message #1118572 is a reply to message #1118543] Fri, 27 September 2013 14:47 Go to previous messageGo to next message
Aurélien Lebeau is currently offline Aurélien LebeauFriend
Messages: 16
Registered: September 2013
Junior Member
That's exactly what I did... I'm really lost, I don't understand what I got such troubles doing this...

Thanks to this topic http://www.eclipse.org/forums/index.php/t/207698/, i do not have exception about IDs anymore. plugin.xml and plugin_gen.xml were out of sync. But I still have a weird stack...

!MESSAGE An unexpected exception was thrown.
!STACK 0
java.lang.NullPointerException
	at org.eclipse.xtext.ui.editor.XtextEditor.dispose(XtextEditor.java:522)
	at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:705)
	at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:465)
	at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
	at org.eclipse.ui.internal.EditorAreaHelper.setVisibleEditor(EditorAreaHelper.java:271)
	at org.eclipse.ui.internal.EditorManager.setVisibleEditor(EditorManager.java:1459)
	at org.eclipse.ui.internal.EditorManager$5.runWithException(EditorManager.java:972)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3537)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3189)
	at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
	at org.eclipse.ui.internal.Workbench$33.runWithException(Workbench.java:1600)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3537)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3189)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2609)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at eu.macqel.myosotis.workshop.Application.start(Application.java:149)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)


Here's my UiModule :
public class SlUiModule extends eu.macqel.myosotisDSLEditor.ui.AbstractSlUiModule {
	public SlUiModule(AbstractUIPlugin plugin) {
		super(plugin);
	}
	
	...
	
	public Class<? extends XtextEditor> bindXtextEditor() {
		return SLEditor.class;
	}
}


And here's my SLEditor :
package eu.macqel.myosotisDSLEditor.ui;

import org.eclipse.xtext.ui.editor.XtextEditor;

public class SLEditor extends XtextEditor  {


	public SLEditor() {
	}


}


Re: Customize the xtext editor itself [message #1118592 is a reply to message #1118572] Fri, 27 September 2013 15:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

there must be some other problem. are you sure this is the only thing you do? please try this with a brand new hello world project.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Customize the xtext editor itself [message #1122080 is a reply to message #1118592] Tue, 01 October 2013 08:02 Go to previous messageGo to next message
Aurélien Lebeau is currently offline Aurélien LebeauFriend
Messages: 16
Registered: September 2013
Junior Member
Thanks for your help !
Finally, the problem came of my old editor that was still in the extensions points and create conflicts...

By the way, do you know how I can deactivate Outline and Refactoring of my editor ? I do not want to have the option "Rename element" when I right-clic on the editor and I do not want the outline tab to the right of my RCP.

I tried commenting the inject lines of Generate.mwe2 but it gives me Exception.
Re: Customize the xtext editor itself [message #1122154 is a reply to message #1122080] Tue, 01 October 2013 09:24 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

am not sure if these are "Editor" aspects.

Removing
fragment = refactoring.RefactorElementNameFragment auto-inject {}
does what i want.

Outline is a general Eclipse Concept

fragment = outline.OutlineTreeProviderFragment auto-inject {}
fragment = outline.QuickOutlineFragment auto-inject {}
does not disable the outline but the quick outline only and the hook for customization.
http://wiki.eclipse.org/FAQ_How_do_I_create_an_Outline_view_for_my_own_language_editor%3F will help to to find out what todo.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Preserve Line Breaks
Next Topic:Update Error for Xtext 4.2.3
Goto Forum:
  


Current Time: Thu Mar 28 22:31:18 GMT 2024

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

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

Back to the top