Skip to main content


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 13:37 Go to next message
Eclipse UserFriend
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 06:52 Go to previous messageGo to next message
Vijay RajFriend
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 06:11 Go to previous message
Eclipse UserFriend
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: Fri Apr 19 19:34:21 GMT 2024

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

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

Back to the top