Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [XText] Attaching a behavioral extension
[XText] Attaching a behavioral extension [message #46734] Sun, 31 May 2009 16:53 Go to next message
Cédric Vidal is currently offline Cédric VidalFriend
Messages: 101
Registered: July 2009
Senior Member
Hi guys,

I'm currently trying to add a behavioral extension implemented using a
content adapter to a model managed by XText.

I already managed to achieve it in an EMF.Edit generated editor and I'm
looking around the TMF XText generated editor to find a place where to
attach my adaptor.

I would be most greatfull if you could point me to the right place in
the generated code.

Kind Regards,

Cédric Vidal

PS: I'm using TMF Xtext 0.7RC2 bundle from Itemis
http://oaw.itemis.com/openarchitectureware/language=en/2837/ downloads
Re: [XText] Attaching a behavioral extension [message #46769 is a reply to message #46734] Sun, 31 May 2009 21:08 Go to previous messageGo to next message
Cédric Vidal is currently offline Cédric VidalFriend
Messages: 101
Registered: July 2009
Senior Member
Ok,

I found out the following solution. I subclassed XtextEditor:

public class MyXtextEditor extends XtextEditor {

@Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);
IXtextDocument document = getDocument();

document.modify(new IUnitOfWork<Object, XtextResource>() {
@Override
public Object exec(XtextResource resource) throws Exception {
attachBehavior(resource);
return null;
}
});

document.addModelListener(new IXtextModelListener() {
@Override
public void modelChanged(XtextResource resource) {
attachBehavior(resource);
}
});
}

private void attachBehavior(XtextResource resource) {
// attach adaptor
}

}

and changed plugin.xml editor configuration to use mine instead of
default XtextEditor.

So far it works for me.

Kind regards,

Cédric

Cédric Vidal a écrit :
> Hi guys,
>
> I'm currently trying to add a behavioral extension implemented using a
> content adapter to a model managed by XText.
>
> I already managed to achieve it in an EMF.Edit generated editor and I'm
> looking around the TMF XText generated editor to find a place where to
> attach my adaptor.
>
> I would be most greatfull if you could point me to the right place in
> the generated code.
>
> Kind Regards,
>
> Cédric Vidal
>
> PS: I'm using TMF Xtext 0.7RC2 bundle from Itemis
> http://oaw.itemis.com/openarchitectureware/language=en/2837/ downloads
Re: [XText] Attaching a behavioral extension [message #46857 is a reply to message #46769] Mon, 01 June 2009 19:35 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
As the editor usually is created by guice, there might be some component
declaring a dependency on XtextEditor. You should change the
configuration in the ui module instead of changing the contents of
plugin.xml. We might inject the editor somewhere else.

To do so add a binding like this:

public class MyLanguageUiModule extends AbstractMyLanguageUiModule {

public Class<? extends XtextEditor> bindEditor() {
return MySpecialEditor.class;
}

.....

Cheers,
Sven

Cédric Vidal schrieb:
> Ok,
>
> I found out the following solution. I subclassed XtextEditor:
>
> public class MyXtextEditor extends XtextEditor {
>
> @Override
> public void createPartControl(Composite parent) {
> super.createPartControl(parent);
> IXtextDocument document = getDocument();
>
> document.modify(new IUnitOfWork<Object, XtextResource>() {
> @Override
> public Object exec(XtextResource resource) throws Exception {
> attachBehavior(resource);
> return null;
> }
> });
>
> document.addModelListener(new IXtextModelListener() {
> @Override
> public void modelChanged(XtextResource resource) {
> attachBehavior(resource);
> }
> });
> }
>
> private void attachBehavior(XtextResource resource) {
> // attach adaptor
> }
>
> }
>
> and changed plugin.xml editor configuration to use mine instead of
> default XtextEditor.
>
> So far it works for me.
>
> Kind regards,
>
> Cédric
>
> Cédric Vidal a écrit :
>> Hi guys,
>>
>> I'm currently trying to add a behavioral extension implemented using a
>> content adapter to a model managed by XText.
>>
>> I already managed to achieve it in an EMF.Edit generated editor and
>> I'm looking around the TMF XText generated editor to find a place
>> where to attach my adaptor.
>>
>> I would be most greatfull if you could point me to the right place in
>> the generated code.
>>
>> Kind Regards,
>>
>> Cédric Vidal
>>
>> PS: I'm using TMF Xtext 0.7RC2 bundle from Itemis
>> http://oaw.itemis.com/openarchitectureware/language=en/2837/ downloads
Re: [XText] Attaching a behavioral extension [message #49016 is a reply to message #46857] Sun, 07 June 2009 15:33 Go to previous message
Cédric Vidal is currently offline Cédric VidalFriend
Messages: 101
Registered: July 2009
Senior Member
Hi Sven,

Thanx for the correction. I'll try that as soon as I get the chance.

Regards,

Cédric

Sven Efftinge a écrit :
> As the editor usually is created by guice, there might be some component
> declaring a dependency on XtextEditor. You should change the
> configuration in the ui module instead of changing the contents of
> plugin.xml. We might inject the editor somewhere else.
>
> To do so add a binding like this:
>
> public class MyLanguageUiModule extends AbstractMyLanguageUiModule {
>
> public Class<? extends XtextEditor> bindEditor() {
> return MySpecialEditor.class;
> }
>
> ....
>
> Cheers,
> Sven
>
> Cédric Vidal schrieb:
>> Ok,
>>
>> I found out the following solution. I subclassed XtextEditor:
>>
>> public class MyXtextEditor extends XtextEditor {
>>
>> @Override
>> public void createPartControl(Composite parent) {
>> super.createPartControl(parent);
>> IXtextDocument document = getDocument();
>>
>> document.modify(new IUnitOfWork<Object, XtextResource>() {
>> @Override
>> public Object exec(XtextResource resource) throws Exception {
>> attachBehavior(resource);
>> return null;
>> }
>> });
>>
>> document.addModelListener(new IXtextModelListener() {
>> @Override
>> public void modelChanged(XtextResource resource) {
>> attachBehavior(resource);
>> }
>> });
>> }
>>
>> private void attachBehavior(XtextResource resource) {
>> // attach adaptor
>> }
>>
>> }
>>
>> and changed plugin.xml editor configuration to use mine instead of
>> default XtextEditor.
>>
>> So far it works for me.
>>
>> Kind regards,
>>
>> Cédric
>>
>> Cédric Vidal a écrit :
>>> Hi guys,
>>>
>>> I'm currently trying to add a behavioral extension implemented using
>>> a content adapter to a model managed by XText.
>>>
>>> I already managed to achieve it in an EMF.Edit generated editor and
>>> I'm looking around the TMF XText generated editor to find a place
>>> where to attach my adaptor.
>>>
>>> I would be most greatfull if you could point me to the right place in
>>> the generated code.
>>>
>>> Kind Regards,
>>>
>>> Cédric Vidal
>>>
>>> PS: I'm using TMF Xtext 0.7RC2 bundle from Itemis
>>> http://oaw.itemis.com/openarchitectureware/language=en/2837/ downloads
Previous Topic:Using the EMF classes and from a new plugin
Next Topic:[XText] Attaching a behavioral extension in a non intrusive way
Goto Forum:
  


Current Time: Thu Dec 26 20:19:57 GMT 2024

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

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

Back to the top