Skip to main content



      Home
Home » Eclipse Projects » GEF » delete of gef figures in viewpart
delete of gef figures in viewpart [message #163157] Mon, 03 January 2005 13:41 Go to next message
Eclipse UserFriend
Hi,

There seem to be a lot of Threads regarding the delete issue but I have
found none that deals with using GEF delete in a ViewPart (instead of a
GraphicalEditor).

I'm using GEF in a ViewPart thus I can't get the DeleteAction via
getActionRegistry().getAction(...

I simply created a new DeleteAction:


ActionRegistry registry = new ActionRegistry();
KeyHandler keyHandler = new GraphicalViewerKeyHandler(viewer);
DeleteAction delAction = new DeleteAction(this);
registry.registerAction(delAction);
keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0), delAction);
viewer.setKeyHandler(keyHandler);

but that was - apparantly - too simple, it doesn't work.
I did install a subclass of ComponentEditPolicy with my EditPart with
the COMPONENT_ROLE but that EditPolicy's createDeleteCommand() method is
never called.

Can anyone help me how to enable a DeleteAction when NOT using a
subclass of GraphicalEditor please?

Any help greatly appreciated!

Uli
Re: delete of gef figures in viewpart [message #163182 is a reply to message #163157] Mon, 03 January 2005 15:36 Go to previous messageGo to next message
Eclipse UserFriend
You don't need a keyhandler for enabling delete. Try something like this in
your view's init(IViewSite) method instead.

site.getActionBars().setGlobalActionHandler(ActionFactory.DE LETE.getId(),
new DeleteAction(this));

"Ulrich K
Re: delete of gef figures in viewpart [message #163188 is a reply to message #163182] Tue, 04 January 2005 09:23 Go to previous messageGo to next message
Eclipse UserFriend
Hi!

I tried that but id didn't work. Acutally there seems to be something
more fundamental to be wrong.
I also tried:

viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer) {
public boolean keyPressed(KeyEvent event) {
System.out.println("Heyho!");
if (event.keycode == SWT.DEL) {
// do delete
}
return true;
}
});

But that method also did never get called. There must be some sort of
key handling since I can jump around my GEF figures using the arrow keys
and I suspect that handling is consuming the key events?! :-(
Any ideas someone?

Thank you very much anyway for your tip!

Uli


> You don't need a keyhandler for enabling delete. Try something like this in
> your view's init(IViewSite) method instead.
>
> site.getActionBars().setGlobalActionHandler(ActionFactory.DE LETE.getId(),
> new DeleteAction(this));
>
> "Ulrich Küster" <Ulrich.Kuester@uni-jena.de> wrote in message
> news:crc3ju$2jv$1@www.eclipse.org...
>
>>Hi,
>>
>>There seem to be a lot of Threads regarding the delete issue but I have
>>found none that deals with using GEF delete in a ViewPart (instead of a
>>GraphicalEditor).
>>
>>I'm using GEF in a ViewPart thus I can't get the DeleteAction via
>>getActionRegistry().getAction(...
>>
>>I simply created a new DeleteAction:
>>
>>
>>ActionRegistry registry = new ActionRegistry();
>>KeyHandler keyHandler = new GraphicalViewerKeyHandler(viewer);
>>DeleteAction delAction = new DeleteAction(this);
>>registry.registerAction(delAction);
>>keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0), delAction);
>>viewer.setKeyHandler(keyHandler);
>>
>>but that was - apparantly - too simple, it doesn't work.
>>I did install a subclass of ComponentEditPolicy with my EditPart with
>>the COMPONENT_ROLE but that EditPolicy's createDeleteCommand() method is
>>never called.
>>
>>Can anyone help me how to enable a DeleteAction when NOT using a
>>subclass of GraphicalEditor please?
>>
>>Any help greatly appreciated!
>>
>>Uli
>
>
>
Re: delete of gef figures in viewpart [message #163247 is a reply to message #163188] Thu, 06 January 2005 12:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

DEL is a registered keybinding by the eclipse workbench. However, the Canvas
should always get the first opportunity to process a keystroke. if
keyPressed is not getting called when you press DEL, it might be a bug in
the workbench. Especially if the workbench's global delete menuitem is
disabled at that time.

BTW, DEL should work in the outline view in the logic example. If it
doesn't, open a bugzilla.

"Ulrich K
Re: delete of gef figures in viewpart [message #163255 is a reply to message #163247] Thu, 06 January 2005 13:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

I just tried this in the Logic example. The KeyHandler processes delete
key, and maps it to the DeleteAction.

The KeyHandler works even when the global action is enabled.

"Randy Hudson" <none@us.ibm.com> wrote in message
news:crjsv9$ski$1@www.eclipse.org...
> DEL is a registered keybinding by the eclipse workbench. However, the
Canvas
> should always get the first opportunity to process a keystroke. if
> keyPressed is not getting called when you press DEL, it might be a bug in
> the workbench. Especially if the workbench's global delete menuitem is
> disabled at that time.
>
> BTW, DEL should work in the outline view in the logic example. If it
> doesn't, open a bugzilla.
>
Re: delete of gef figures in viewpart [message #163277 is a reply to message #163255] Fri, 07 January 2005 06:44 Go to previous messageGo to next message
Eclipse UserFriend
Hi Randy,

thank you very much for your help and efforts again!

I found out, why my code didn't work and apologize for my stupidity. :-(

viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer) {
> public boolean keyPressed(KeyEvent event) {
> System.out.println("Heyho!");
> if (event.keycode == SWT.DEL) {
> // do delete
> }
> return true;
> }
> });

I used the draw2d package KeyEvent instead of the proper SWT KeyEvent,
so I didn't really override the method :-(
The difference can be seen in the difference between event.keycode
(draw2d) and event.keyCode (SWT), too.

I suppose I will get delete working using this approach.

However I tried to do it this way, too:

ActionRegistry registry = new ActionRegistry();
KeyHandler keyHandler = new GraphicalViewerKeyHandler(viewer);
DeleteAction delAction = new DeleteAction(this);
// this = my ViewPart
delAction.setLazyEnablementCalculation(true);
registry.registerAction(delAction);
keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0), delAction);

viewer.setKeyHandler(keyHandler);

That does not work, since the DeleteAction never receives a selection,
although I've set my GEF-viewer as the selection provider of my
ViewPart's site:
this.getSite().setSelectionProvider(viewer);

Any idea what I'm still missing?

Again, thank you very much,

Uli
Re: delete of gef figures in viewpart [message #163284 is a reply to message #163182] Fri, 07 January 2005 06:46 Go to previous messageGo to next message
Eclipse UserFriend
Pratik Shah wrote:

> You don't need a keyhandler for enabling delete. Try something like this in
> your view's init(IViewSite) method instead.
>
> site.getActionBars().setGlobalActionHandler(ActionFactory.DE LETE.getId(),
> new DeleteAction(this));

Thank you for your answer! I tried that, but unfortunaltely it does not
seem to work. I'v put a breakpoint in the DeleteAction's
createDeleteCommand(List objects) method but that is never called. :-/

Again, thanks for your help anyway!

Uli
Re: delete of gef figures in viewpart + CommandStack question [message #163292 is a reply to message #163277] Fri, 07 January 2005 08:08 Go to previous messageGo to next message
Eclipse UserFriend
Ulrich Küster wrote:

viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
delAction.update();
}
});

does the job, but is this really the right way to do it?
Furthermore this way I ran into a NPE:

java.lang.NullPointerException at
org.eclipse.gef.ui.actions.WorkbenchPartAction.execute(Workb enchPartAction.java:76)
at org.eclipse.gef.ui.actions.DeleteAction.run(DeleteAction.jav a:129)

That could be prevented by extending the getAdapter() method of my
ViewPart as follows:

public Object getAdapter(Class adapter) {
if (adapter.equals(CommandStack.class)) {
return viewer.getEditDomain().getCommandStack();
}
return super.getAdapter(adapter);
}

But how could I have known right away from the API that I have to do that?

Kind regards,

Uli


> ActionRegistry registry = new ActionRegistry();
> KeyHandler keyHandler = new GraphicalViewerKeyHandler(viewer);
> DeleteAction delAction = new DeleteAction(this);
> // this = my ViewPart
> delAction.setLazyEnablementCalculation(true);
> registry.registerAction(delAction);
> keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0), delAction);
>
> viewer.setKeyHandler(keyHandler);
>
> That does not work, since the DeleteAction never receives a selection,
> although I've set my GEF-viewer as the selection provider of my
> ViewPart's site:
> this.getSite().setSelectionProvider(viewer);
>
> Any idea what I'm still missing?
>
> Again, thank you very much,
>
> Uli
Re: delete of gef figures in viewpart + CommandStack question [message #163314 is a reply to message #163292] Fri, 07 January 2005 10:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

It should be documented in StackAction if it isn't.

> public Object getAdapter(Class adapter) {
> if (adapter.equals(CommandStack.class)) {
> return viewer.getEditDomain().getCommandStack();
> }
> return super.getAdapter(adapter);
> }
>
> But how could I have known right away from the API that I have to do that?
Re: delete of gef figures in viewpart + CommandStack question [message #163321 is a reply to message #163314] Fri, 07 January 2005 10:56 Go to previous message
Eclipse UserFriend
Randy Hudson wrote:

Thank you for your answer.
It is not documented in StackAction and furthermore my DeleteAction is
not an instance of StackAction but of SelectionAction (?!).

There is some documentation in WorkbenchPartAction but not in the
constructor where the WorkBenchPart is provided. So maybe it should be
added there?

Anyway, thank you for your help again,

Uli

> It should be documented in StackAction if it isn't.
>
>
>>public Object getAdapter(Class adapter) {
>>if (adapter.equals(CommandStack.class)) {
>>return viewer.getEditDomain().getCommandStack();
>>}
>>return super.getAdapter(adapter);
>>}
>>
>>But how could I have known right away from the API that I have to do that?
>
>
>
Previous Topic:adding SWT/Jface tree component to draw2d figure
Next Topic:Setting tool from a tool bar
Goto Forum:
  


Current Time: Wed Jul 23 11:17:44 EDT 2025

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

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

Back to the top