Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Deleting a connection
Deleting a connection [message #188639] Thu, 21 July 2005 20:12 Go to next message
Eclipse UserFriend
Originally posted by: cleversons.gmail.com

Hi,

I'm trying to provide a connection removal functionality where the user
selects a connection and presses the delete key to delete it. I've
installed a ConnectionEditPolicy on my ConnectionEditPart which creates a
ConnectionDeleteCommand command. But how to link the delete key press
action to the creation of a ConnectionDeleteCommand?

Thank you
Cleverson Schmidt
Re: Deleting a connection [message #188661 is a reply to message #188639] Fri, 22 July 2005 03:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Delete is a workbench global action. You need to register a global action
handler with the partsite.

> Hi,
>
> I'm trying to provide a connection removal functionality where the user
> selects a connection and presses the delete key to delete it. I've
> installed a ConnectionEditPolicy on my ConnectionEditPart which creates a
> ConnectionDeleteCommand command. But how to link the delete key press
> action to the creation of a ConnectionDeleteCommand?
> Thank you
> Cleverson Schmidt
>
Re: Deleting a connection [message #188685 is a reply to message #188661] Fri, 22 July 2005 13:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cleversons.gmail.com

Hi Randy,

Thanks for the answer.
But could you please be a little more specific? How do I do that?

Thank you
Best Regards
Cleverson Schmidt
Re: Deleting a connection [message #188738 is a reply to message #188685] Fri, 22 July 2005 15:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cleversons.gmail.com

Please correct me if I'm in the wrong path.

I'm trying to figure out how to handle the delete key press so that I can
remove a connection which has been previously selected. I think I can set
a GraphicalViewerKeyHandler with its parent set to my specific key handler:

viewer.setKeyHandler(new
GraphicalViewerKeyHandler(viewer).setParent(getDeleteKeyHand ler()));

Where getDeleteKeyHandler creates a new KeyHandler mapping delete key
actions to my specific IAction implementation, something like
MyDeleteAction.

Is that ok? If so, then the I still have one doubt. How can I now which is
the current selected connection?

Once more thank you very much guys.

Best Regards
Cleverson Schmidt
Re: Deleting a connection [message #188754 is a reply to message #188738] Fri, 22 July 2005 15:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cleversons.gmail.com

Could someone here please point out in the Logic example where exactly it
links a delete press with a delete command? I'm trying to understand how
those examples enable the removal of element by responding to delete key
presses.

Thank you
Re: Deleting a connection [message #188762 is a reply to message #188754] Fri, 22 July 2005 15:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.unknown.com

LogicActionBarContributor#declareGlobalActionKeys()

"Cleverson Schmidt" <cleversons@gmail.com> wrote in message
news:62d5866f0f6c1e5810b790366f28562e$1@www.eclipse.org...
> Could someone here please point out in the Logic example where exactly it
> links a delete press with a delete command? I'm trying to understand how
> those examples enable the removal of element by responding to delete key
> presses.
>
> Thank you
>
Re: Deleting a connection [message #188785 is a reply to message #188754] Fri, 22 July 2005 16:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Pratik pointed you to the relevant code, but you could also try putting a
breakpoint in DeleteAction#run() to find out what really happens.

"Cleverson Schmidt" <cleversons@gmail.com> wrote in message
news:62d5866f0f6c1e5810b790366f28562e$1@www.eclipse.org...
> Could someone here please point out in the Logic example where exactly it
> links a delete press with a delete command? I'm trying to understand how
> those examples enable the removal of element by responding to delete key
> presses.
>
> Thank you
>
Re: Deleting a connection [message #188805 is a reply to message #188785] Fri, 22 July 2005 18:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cleversons.gmail.com

Thank you guys. Unfortunately it is not working yet. I understood how it
is done on the Logic Example and I've tried to do the same on my
application but it is not working.
Following Pratik's suggestion I've included the snipet bellow on my
ActionBarContributor class:

protected void declareGlobalActionKeys() {
addGlobalActionKey(ActionFactory.DELETE.getId());
}

After debugging my application I could realize that when a connection is
selected by the user, my ConnectionEditPolicy creates a
ConnectionDeleteCommand (my specialization of a Command to delete
connections). But when the user presses the delete key, nothing happens.
Do you guys have any tip on what can be wrong?

I have a ConnectionEditPart which installs a ConnectionEditPolicy which in
turns creates a ConnectionDeleteCommand. Is there anything missing?

The strange thing is that I have also a ContextMenuProvider subclass
supplying a popup menu to the user. On this popup, there is a delete
option:

menu.appendToGroup(GEFActionConstants.GROUP_EDIT,getAction(A ctionFactory.DELETE.getId()));

If the user right clicks a connection and chooses the delete option,
everything works flawlessly. Why the same does not work when he presses
the delete key?

Thank you very much...again :)

Best Regards
Cleverson Schmidt
Re: Deleting a connection [message #188828 is a reply to message #188805] Fri, 22 July 2005 18:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.unknown.com

Your ActionBarContributor is registered as the contributor class in the
plugin.xml? If you're overriding createActions() or getAdapter() in your
editor, make sure you're invoking the super methods. When you select the
connection, see if the delete action is enabled in the edit menu. If not,
your editor your editor might not be notifying the workbench of selection
changes properly. Ensure that GraphicalEditor#hookGraphicalViewer is being
invoked.

"Cleverson Schmidt" <cleversons@gmail.com> wrote in message
news:5848261c755be9f537d0e63d55adefce$1@www.eclipse.org...
> Thank you guys. Unfortunately it is not working yet. I understood how it
> is done on the Logic Example and I've tried to do the same on my
> application but it is not working.
> Following Pratik's suggestion I've included the snipet bellow on my
> ActionBarContributor class:
>
> protected void declareGlobalActionKeys() {
> addGlobalActionKey(ActionFactory.DELETE.getId());
> }
>
> After debugging my application I could realize that when a connection is
> selected by the user, my ConnectionEditPolicy creates a
> ConnectionDeleteCommand (my specialization of a Command to delete
> connections). But when the user presses the delete key, nothing happens.
> Do you guys have any tip on what can be wrong?
>
> I have a ConnectionEditPart which installs a ConnectionEditPolicy which in
> turns creates a ConnectionDeleteCommand. Is there anything missing?
>
> The strange thing is that I have also a ContextMenuProvider subclass
> supplying a popup menu to the user. On this popup, there is a delete
> option:
>
>
menu.appendToGroup(GEFActionConstants.GROUP_EDIT,getAction(A ctionFactory.DEL
ETE.getId()));
>
> If the user right clicks a connection and chooses the delete option,
> everything works flawlessly. Why the same does not work when he presses
> the delete key?
>
> Thank you very much...again :)
>
> Best Regards
> Cleverson Schmidt
>
Re: Deleting a connection [message #188852 is a reply to message #188828] Fri, 22 July 2005 19:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cleversons.gmail.com

Thank you again Pratik

> Your ActionBarContributor is registered as the contributor class in the
> plugin.xml?

Yes it is.

> If you're overriding createActions() or getAdapter() in your
> editor, make sure you're invoking the super methods.

I'm sure I am invoking the super methods.

> When you select the
> connection, see if the delete action is enabled in the edit menu. If not,
> your editor your editor might not be notifying the workbench of selection
> changes properly.

When I select the connection, the delete action is enabled on the
application menu.

> Ensure that GraphicalEditor#hookGraphicalViewer is being
> invoked.

I could not find any reference to a hookGraphicalViewer in my source code.
So, I put a call to hookGraphicalViewer in the end of
configureGraphicalViewer() but it didn't work. I can even delete my
connection using the delete menu, but not by pressing the delete key.

Realy intrigant :(
Any other clue?

Thanks once again
Re: Deleting a connection [message #188875 is a reply to message #188852] Fri, 22 July 2005 19:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.unknown.com

Okay, last guess (running out of ideas now). You must be doing something
that's preventing the workbench from handling the delete key. Maybe you're
handling the delete key in your keyhandler? Set a breakpoint in
DomainEventDispatcher#handleKeyPressed(). When that method enters,
event.doit will be true. When that method exits, event.doit should still be
true. If it is false, then that's the problem. Somebody handled the delete
key and workbench will perform no action. Just step into the code to see
where it's being handled.

"Cleverson Schmidt" <cleversons@gmail.com> wrote in message
news:48d40ec9ee8d4b850d23db38be7347ea$1@www.eclipse.org...
> Thank you again Pratik
>
> > Your ActionBarContributor is registered as the contributor class in the
> > plugin.xml?
>
> Yes it is.
>
> > If you're overriding createActions() or getAdapter() in your
> > editor, make sure you're invoking the super methods.
>
> I'm sure I am invoking the super methods.
>
> > When you select the
> > connection, see if the delete action is enabled in the edit menu. If
not,
> > your editor your editor might not be notifying the workbench of
selection
> > changes properly.
>
> When I select the connection, the delete action is enabled on the
> application menu.
>
> > Ensure that GraphicalEditor#hookGraphicalViewer is being
> > invoked.
>
> I could not find any reference to a hookGraphicalViewer in my source code.
> So, I put a call to hookGraphicalViewer in the end of
> configureGraphicalViewer() but it didn't work. I can even delete my
> connection using the delete menu, but not by pressing the delete key.
>
> Realy intrigant :(
> Any other clue?
>
> Thanks once again
>
Re: Deleting a connection [message #188890 is a reply to message #188852] Fri, 22 July 2005 20:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Does you DeleteAction ever get registered as the global action handler? Are
you using the dreaded MultiPageEditorPart??

"Cleverson Schmidt" <cleversons@gmail.com> wrote in message
news:48d40ec9ee8d4b850d23db38be7347ea$1@www.eclipse.org...
> Thank you again Pratik
>
>> Your ActionBarContributor is registered as the contributor class in the
>> plugin.xml?
>
> Yes it is.
>
>> If you're overriding createActions() or getAdapter() in your
>> editor, make sure you're invoking the super methods.
>
> I'm sure I am invoking the super methods.
>
>> When you select the
>> connection, see if the delete action is enabled in the edit menu. If
>> not,
>> your editor your editor might not be notifying the workbench of selection
>> changes properly.
>
> When I select the connection, the delete action is enabled on the
> application menu.
>
>> Ensure that GraphicalEditor#hookGraphicalViewer is being
>> invoked.
>
> I could not find any reference to a hookGraphicalViewer in my source code.
> So, I put a call to hookGraphicalViewer in the end of
> configureGraphicalViewer() but it didn't work. I can even delete my
> connection using the delete menu, but not by pressing the delete key.
>
> Realy intrigant :(
> Any other clue?
>
> Thanks once again
>
Re: Deleting a connection [message #188987 is a reply to message #188890] Mon, 25 July 2005 13:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cleversons.gmail.com

> Does you DeleteAction ever get registered as the global action handler? Are
> you using the dreaded MultiPageEditorPart??

I'm not sure if I know the answer to your first question. In my
ActionBarContributor extension class I'm putting the following line on the
declareGlobalActionKeys:
addGlobalActionKey(ActionFactory.DELETE.getId());

Is it enough to register the delete action as a global action handler? By
the way, I'm not redefining my own KeyHandler. I'm using a
GraphicalViewerKeyHandler:
viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer));

Regarding your second question, I'm not using MultiPageEditorPart.

Thank you.

Cleverson Schmidt
Re: Deleting a connection [message #189016 is a reply to message #188987] Mon, 25 July 2005 15:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cleversons.gmail.com

Aleluia!! It works now!!
After scanning the source code of all examples (Flow, Logic and Shapes)
looking for differences in how the delete key press is handled I've
finnaly found a solution.
In my application I was setting the KeyHandler as shown below:

viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer));

The Flow example does it slightly different:

viewer.setKeyHandler(new
GraphicalViewerKeyHandler(viewer).setParent(getCommonKeyHand ler()));

I've just adapted the getCommonKeyHandler implementation as follows:

protected KeyHandler getCommonKeyHandler() {
if (sharedKeyHandler == null) {
sharedKeyHandler = new KeyHandler();
sharedKeyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0),
getActionRegistry().getAction(
ActionFactory.DELETE.getId()));
}
return sharedKeyHandler;
}

Works like magic. I've got to confess I still don't know why exactly we
have to do that. But it is ok.

Thank you very much Pratik and Randy. Your help on this forum is simply
great!

Best Regards
Cleverson Schmidt
Re: Deleting a connection [message #189049 is a reply to message #189016] Mon, 25 July 2005 15:41 Go to previous message
Eclipse UserFriend
Originally posted by: none.unknown.com

"Cleverson Schmidt" <cleversons@gmail.com> wrote in message
news:06856d9e9496e3819cd4c88457865920$1@www.eclipse.org...
> Aleluia!! It works now!!
> After scanning the source code of all examples (Flow, Logic and Shapes)
> looking for differences in how the delete key press is handled I've
> finnaly found a solution.
> In my application I was setting the KeyHandler as shown below:
>
> viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer));
>
> The Flow example does it slightly different:
>
> viewer.setKeyHandler(new
> GraphicalViewerKeyHandler(viewer).setParent(getCommonKeyHand ler()));
>
> I've just adapted the getCommonKeyHandler implementation as follows:
>
> protected KeyHandler getCommonKeyHandler() {
> if (sharedKeyHandler == null) {
> sharedKeyHandler = new KeyHandler();
> sharedKeyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0),
> getActionRegistry().getAction(
> ActionFactory.DELETE.getId()));
> }
> return sharedKeyHandler;
> }
>
> Works like magic. I've got to confess I still don't know why exactly we
> have to do that. But it is ok.

You don't have to do that. The flow example's just old and a little out of
date when it comes to such things. If you want to find out why your example
was not working the way the logic example does, try what I suggested in my
last post.

>
> Thank you very much Pratik and Randy. Your help on this forum is simply
> great!
>
> Best Regards
> Cleverson Schmidt
>
Previous Topic:FlowLayout doesn't calculate its size automatically?
Next Topic:MVC Question
Goto Forum:
  


Current Time: Thu Dec 26 11:24:30 GMT 2024

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

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

Back to the top