delete of gef figures in viewpart [message #163157] |
Mon, 03 January 2005 13:41  |
Eclipse User |
|
|
|
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 #163277 is a reply to message #163255] |
Fri, 07 January 2005 06:44   |
Eclipse User |
|
|
|
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 + CommandStack question [message #163292 is a reply to message #163277] |
Fri, 07 January 2005 08:08   |
Eclipse User |
|
|
|
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 #163321 is a reply to message #163314] |
Fri, 07 January 2005 10:56  |
Eclipse User |
|
|
|
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?
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.06254 seconds