Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » How to detect Ctrl-Z in eclipse for the EcoreDiagramEditor
How to detect Ctrl-Z in eclipse for the EcoreDiagramEditor [message #1413498] Thu, 28 August 2014 17:27 Go to next message
ping cin is currently offline ping cinFriend
Messages: 13
Registered: February 2014
Junior Member
Hello everyone,

I would like to be able to detect a Ctrl-Z event in the EcoreDiagramEditor while modeling with ecore tool (.ecorediag).

While the user is modeling an ecore metamodel in eclipse, I have a plugin, in which I am constructing in parallel another representation of the (on going) metamodel. Thus, I need to detect Ctrl-Z, to also apply it on my other parallel representation.

For example, if I delete an attribute, and then I cancel its effect with a Ctrl-Z, I would also like to cancel it in my other parallel representation.

I tried to add a filter to my plugin container (like below), but it does not work well (at least not for Ctrl-Z).

container.getDisplay().addFilter(SWT.KeyDown, new Listener(){
public void handleEvent(Event e){
System.out.println("3333");
System.out.println("Filter-ctrl: " + SWT.CTRL);
System.out.println("Filter-mask: " + e.stateMask);
System.out.println("Filter-char: " + e.character);
System.out.println("Filter-char: " + e.keyCode);
}
});

For example, I can detect Ctrl-f, but not Ctrl-Z. Could anyone help me out here?

Thank you in advance for your time and answer.

Best Regads.
Re: How to detect Ctrl-Z in eclipse for the EcoreDiagramEditor [message #1413531 is a reply to message #1413498] Thu, 28 August 2014 19:38 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi,

If your plug-in is listening to changes in the Ecore diagram editor
using Adapters of some kind, responding to Notifications by updating
your parallel representation, then it doesn't matter whether changes
are occurring because the user undid some action via Ctrl+Z. Your
plug-in will simply see Notifications indicating the inverse changes
and can update the parallel representation accordingly.

In any, you really don't want to intercept Ctrl+Z literally in this way
because the user's Eclipse instance may map some other keystroke to the
Undo command. Besides that on Mac platform the default binding is
different anyways, being Cmd+Z, not Ctrl+Z.

So, I think the real question is how is your plug-in observing changes
in the Ecore model and why should it make any difference whether they
occur because of some command executing versus being undone?

Cheers,

Christian

On 2014-08-28 17:27:06 +0000, ping cin said:

> Hello everyone,
>
> I would like to be able to detect a Ctrl-Z event in the
> EcoreDiagramEditor while modeling with ecore tool (.ecorediag).
>
> While the user is modeling an ecore metamodel in eclipse, I have a
> plugin, in which I am constructing in parallel another representation
> of the (on going) metamodel. Thus, I need to detect Ctrl-Z, to also
> apply it on my other parallel representation.
>
> For example, if I delete an attribute, and then I cancel its effect
> with a Ctrl-Z, I would also like to cancel it in my other parallel
> representation.
>
> I tried to add a filter to my plugin container (like below), but it
> does not work well (at least not for Ctrl-Z).
>
> container.getDisplay().addFilter(SWT.KeyDown, new Listener(){
> public void handleEvent(Event e){
> System.out.println("3333");
> System.out.println("Filter-ctrl: " + SWT.CTRL);
> System.out.println("Filter-mask: " + e.stateMask);
> System.out.println("Filter-char: " + e.character);
> System.out.println("Filter-char: " + e.keyCode);
> }
> });
>
> For example, I can detect Ctrl-f, but not Ctrl-Z. Could anyone help me
> out here?
>
> Thank you in advance for your time and answer.
>
> Best Regads.
Re: How to detect Ctrl-Z in eclipse for the EcoreDiagramEditor [message #1597921 is a reply to message #1413531] Mon, 02 February 2015 17:04 Go to previous message
ping cin is currently offline ping cinFriend
Messages: 13
Registered: February 2014
Junior Member
Hello,

Sorry for the late response.

I use the Adapters to get all notifications of the updates of an ecore model. So you are absolutely right if the user applies a ctrl-z, I have a notification (that is theoretically the inverse of the previous one). In this case, I have to make an analysis of the notifications to detect that two notifications are canceling each other (effect of ctrl-z), whereas detecting ctrl-z would be easier, at first glance. But in case the user applies a manual ctrl-z (example: adding an element and then deleting it manually without using ctrl-z buttons), the above method is the only solution to actually detect it.

Thank you very much for you answer.
Best Regards.
Previous Topic:[Texo] Building a CRUD client
Next Topic:Call for Submissions: Modeling Symposium @ EclipseCon North America 2015
Goto Forum:
  


Current Time: Fri Apr 19 05:14:17 GMT 2024

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

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

Back to the top