Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » SWT.DEL key and a Graphical viewer inside an eclipse ViewPart
SWT.DEL key and a Graphical viewer inside an eclipse ViewPart [message #632079] Mon, 11 October 2010 09:37 Go to next message
Eclipse User
Originally posted by: micha.on.the.road.web.de

Hi,

I noticed a strange issue with SWT.DEL key and the GEF keyhandler.

I do the following:

keyHandler.put(
KeyStroke.getPressed(SWT.DEL, 127, 0),
getActionRegistry().getAction(ActionFactory.DELETE.getId())) ;
keyHandler.put(
KeyStroke.getPressed('+', SWT.KEYPAD_ADD, 0),
getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
keyHandler.put(
KeyStroke.getPressed('-', SWT.KEYPAD_SUBTRACT, 0),
getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT));
viewer.setKeyHandler(keyHandler);

It works perfectly if the GraphicalViewer is inside a graphical editor.
However, my application is using it inside a ViewPart.
"+" and "-" works, but inside the GEF
KeyHandler.performStroke(KeyStroke) method,
IAction action = (IAction)actions.get(key);
returns null although keycodes of the events are matching (127). Not so
if embedded in the GraphicalEditor, as told.

I think it's a bug and I use this workaround (Note, I instantiate a
GraphicalEditor and embedd its viewer in my ViewPart):

keyHandler = new KeyHandler() {
public boolean keyPressed(KeyEvent event) {
if (event.keyCode==127) {
return performDelete();
}
return super.keyPressed(event);
}

private boolean performDelete() {
IAction action =
getActionRegistry().getAction(ActionFactory.DELETE.getId());
if (action == null)
return false;
if (action.isEnabled())
action.run();
return true;
}

};

However, maybe somebody has another idea about this; else I add a bug
report soon.

Regards
Michael
Re: SWT.DEL key and a Graphical viewer inside an eclipse ViewPart [message #632739 is a reply to message #632079] Thu, 14 October 2010 02:52 Go to previous messageGo to next message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
did u set the edit domain in you view for the viewer...

try doing that and see...

EditDomain domain = new EditDomain();
domain.addViewer(viewer);


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: SWT.DEL key and a Graphical viewer inside an eclipse ViewPart [message #643491 is a reply to message #632739] Tue, 07 December 2010 01:11 Go to previous message
Eclipse User
Originally posted by: micha.on.the.road.web.de

Hi,

its already long time ago but the problem remains. I tried a lot of
things but I did not get it working without the beyond mentioned work
around.

What do you mean exactly with setting the edit domain, is there some
trick? The GraphicalEditorWithPalette.setEditDomain() requires the
DefaultEditDomain that I set in the constructor. I tried other places,
went with the debugger through the key traversal and key up of the
EditDomain, but could not find the reason. That the DefaultEditDomain
maintains a IEditorPart reference cannot be the point because
getEditorPart() is never called.

Any more suggestions how to solve this?

Anyway thanks a lot for your reply!
Regards
Michael




On 14.10.2010 08:52, vijay wrote:
> did u set the edit domain in you view for the viewer...
>
> try doing that and see...
>
> EditDomain domain = new EditDomain();
> domain.addViewer(viewer);



On 11.10.2010 15:37, Arbor wrote:
> Hi,
>
> I noticed a strange issue with SWT.DEL key and the GEF keyhandler.
>
> I do the following:
>
> keyHandler.put(
> KeyStroke.getPressed(SWT.DEL, 127, 0),
> getActionRegistry().getAction(ActionFactory.DELETE.getId())) ;
> keyHandler.put(
> KeyStroke.getPressed('+', SWT.KEYPAD_ADD, 0),
> getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
> keyHandler.put(
> KeyStroke.getPressed('-', SWT.KEYPAD_SUBTRACT, 0),
> getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT));
> viewer.setKeyHandler(keyHandler);
>
> It works perfectly if the GraphicalViewer is inside a graphical editor.
> However, my application is using it inside a ViewPart.
> "+" and "-" works, but inside the GEF
> KeyHandler.performStroke(KeyStroke) method,
> IAction action = (IAction)actions.get(key);
> returns null for deletion although keycodes of the events are
matching (127).
> Not so if embedded in the GraphicalEditor, as told.
>
> I think it's a bug and I use this workaround (Note, I instantiate a
> GraphicalEditor and embedd its viewer in my ViewPart):
>
> keyHandler = new KeyHandler() {
> public boolean keyPressed(KeyEvent event) {
> if (event.keyCode==127) {
> return performDelete();
> }
> return super.keyPressed(event);
> }
>
> private boolean performDelete() {
> IAction action =
> getActionRegistry().getAction(ActionFactory.DELETE.getId());
> if (action == null)
> return false;
> if (action.isEnabled())
> action.run();
> return true;
> }
>
> };
>
> However, maybe somebody has another idea about this; else I add a bug
> report soon.
>
> Regards
> Michael
Previous Topic:[Zest] Custom drawn connections or anchor labels
Next Topic:Unable to run org.eclipse.gef.examples.ediagram
Goto Forum:
  


Current Time: Sun Aug 31 04:34:23 EDT 2014

Powered by FUDForum. Page generated in 0.11457 seconds