Skip to main content



      Home
Home » Eclipse Projects » GEF » Selecting an editPart
Selecting an editPart [message #102226] Mon, 27 October 2003 12:44 Go to next message
Eclipse UserFriend
I am trying to implement a right click menu action which extends
SelectionAction (similar to the increment/decrement action in the logic
example). This works okay if I return "true" when asked whether the
action is enabled. However, I want to be able to contextualise the action
so that it only appears when an EditPart is selected, I do this using the
following code:

protected boolean calculateEnabled() {
return canPerformAction();
}

private boolean canPerformAction() {
if (getSelectedObjects().isEmpty())
return false;
return true;
}

The problem is that canPerformAction() invariably returns false (even
though I can see selected EditPart on the screen) and hence the action is
always disabled. This problem seems to be symptomatic of a more
fundamental problem in my application which is that an EditPart's
getSelected() method always returns the value EditPart.SELECTED_NONE (even
though I can see that the figure produced by the EditPart is selected -
that is - shows the handles to resize).

Does anyone have any suggestions why this might be the case?

Many thanks.

James
Re: Selecting an editPart [message #102242 is a reply to message #102226] Mon, 27 October 2003 13:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.Rigidsoftware.com

On Mon, 27 Oct 2003 17:44:41 +0000, James Willans wrote:

> I am trying to implement a right click menu action which extends
> SelectionAction (similar to the increment/decrement action in the logic
> example). This works okay if I return "true" when asked whether the
> action is enabled. However, I want to be able to contextualise the
> action so that it only appears when an EditPart is selected, I do this
> using the following code:
>
> protected boolean calculateEnabled() {
> return canPerformAction();
> }
> }
> private boolean canPerformAction() {
> if (getSelectedObjects().isEmpty())
> return false;
> return true;
> }
> }
> The problem is that canPerformAction() invariably returns false (even
> though I can see selected EditPart on the screen) and hence the action
> is always disabled. This problem seems to be symptomatic of a more
> fundamental problem in my application which is that an EditPart's
> getSelected() method always returns the value EditPart.SELECTED_NONE
> (even though I can see that the figure produced by the EditPart is
> selected - that is - shows the handles to resize).
>
> Does anyone have any suggestions why this might be the case?
>
> Many thanks.
>
> James

Have you tried setting a breakpoint to see if canPerformAction() is
actually being called? Your login within this class is sound, but you
need to be sure the action is properly attached to the workspace.


CL
Re: Selecting an editPart [message #102273 is a reply to message #102242] Mon, 27 October 2003 14:27 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for your reply. Yes - canPerformAction is certainly getting
called. In fact it is doing its job okay, but the selected editParts are
failing to report true when they're (seemingly) selected.

James

CL [dnoyeB] Gilbert wrote:

> On Mon, 27 Oct 2003 17:44:41 +0000, James Willans wrote:

> > I am trying to implement a right click menu action which extends
> > SelectionAction (similar to the increment/decrement action in the logic
> > example). This works okay if I return "true" when asked whether the
> > action is enabled. However, I want to be able to contextualise the
> > action so that it only appears when an EditPart is selected, I do this
> > using the following code:
> >
> > protected boolean calculateEnabled() {
> > return canPerformAction();
> > }
> > }
> > private boolean canPerformAction() {
> > if (getSelectedObjects().isEmpty())
> > return false;
> > return true;
> > }
> > }
> > The problem is that canPerformAction() invariably returns false (even
> > though I can see selected EditPart on the screen) and hence the action
> > is always disabled. This problem seems to be symptomatic of a more
> > fundamental problem in my application which is that an EditPart's
> > getSelected() method always returns the value EditPart.SELECTED_NONE
> > (even though I can see that the figure produced by the EditPart is
> > selected - that is - shows the handles to resize).
> >
> > Does anyone have any suggestions why this might be the case?
> >
> > Many thanks.
> >
> > James

> Have you tried setting a breakpoint to see if canPerformAction() is
> actually being called? Your login within this class is sound, but you
> need to be sure the action is properly attached to the workspace.


> CL
Re: Selecting an editPart [message #102306 is a reply to message #102273] Mon, 27 October 2003 15:34 Go to previous messageGo to next message
Eclipse UserFriend
Having said this, even when I force editParts to return true from their
getSelected() method, canPerformAction still returns false. Not sure
what's happening here. Under what circumstances might an Action of type
SelectionAction not receive selection events?

James

James Willans wrote:

> Thanks for your reply. Yes - canPerformAction is certainly getting
> called. In fact it is doing its job okay, but the selected editParts are
> failing to report true when they're (seemingly) selected.

> James

> CL [dnoyeB] Gilbert wrote:

> > On Mon, 27 Oct 2003 17:44:41 +0000, James Willans wrote:

> > > I am trying to implement a right click menu action which extends
> > > SelectionAction (similar to the increment/decrement action in the logic
> > > example). This works okay if I return "true" when asked whether the
> > > action is enabled. However, I want to be able to contextualise the
> > > action so that it only appears when an EditPart is selected, I do this
> > > using the following code:
> > >
> > > protected boolean calculateEnabled() {
> > > return canPerformAction();
> > > }
> > > }
> > > private boolean canPerformAction() {
> > > if (getSelectedObjects().isEmpty())
> > > return false;
> > > return true;
> > > }
> > > }
> > > The problem is that canPerformAction() invariably returns false (even
> > > though I can see selected EditPart on the screen) and hence the action
> > > is always disabled. This problem seems to be symptomatic of a more
> > > fundamental problem in my application which is that an EditPart's
> > > getSelected() method always returns the value EditPart.SELECTED_NONE
> > > (even though I can see that the figure produced by the EditPart is
> > > selected - that is - shows the handles to resize).
> > >
> > > Does anyone have any suggestions why this might be the case?
> > >
> > > Many thanks.
> > >
> > > James

> > Have you tried setting a breakpoint to see if canPerformAction() is
> > actually being called? Your login within this class is sound, but you
> > need to be sure the action is properly attached to the workspace.


> > CL
Re: Selecting an editPart [message #102332 is a reply to message #102306] Mon, 27 October 2003 16:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jpl.remotejava.com

James Willans wrote:
> Having said this, even when I force editParts to return true from their
> getSelected() method, canPerformAction still returns false. Not sure
> what's happening here. Under what circumstances might an Action of type
> SelectionAction not receive selection events?

The list returned by getSelectedObjects() depends on the current value
of the 'selection' field in class SelectionAction. This field is set by
the following chain of method calls:

GraphicalEditor.selectionChanged
GraphicalEditor.updateActions
SelectionAction.update
SelectionAction.setSelection

I would try setting breakpoints in all this methods to see where the
chain becomes broken in your case.

The above information is easy to find with the excellent Call Hierarchy
plugin (which is integrated into Eclipse 3.x, but you can obtain it
separately for 2.1.x).

-JPL
Re: Selecting an editPart [message #102345 is a reply to message #102332] Mon, 27 October 2003 17:14 Go to previous messageGo to next message
Eclipse UserFriend
Jan,

Thanks for the advice. The problem stemmed from failing to call
super.init from the init method of a sub class of GraphicalEditor.

James

Jan Ploski wrote:

> James Willans wrote:
> > Having said this, even when I force editParts to return true from their
> > getSelected() method, canPerformAction still returns false. Not sure
> > what's happening here. Under what circumstances might an Action of type
> > SelectionAction not receive selection events?

> The list returned by getSelectedObjects() depends on the current value
> of the 'selection' field in class SelectionAction. This field is set by
> the following chain of method calls:

> GraphicalEditor.selectionChanged
> GraphicalEditor.updateActions
> SelectionAction.update
> SelectionAction.setSelection

> I would try setting breakpoints in all this methods to see where the
> chain becomes broken in your case.

> The above information is easy to find with the excellent Call Hierarchy
> plugin (which is integrated into Eclipse 3.x, but you can obtain it
> separately for 2.1.x).

> -JPL
Re: Selecting an editPart [message #102401 is a reply to message #102345] Mon, 27 October 2003 22:09 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

This problem has been encountered several times on the newsgroup. Please
read the JavaDoc, especially when subclassing.

"James Willans" <jwillans@cs.york.ac.uk> wrote in message
news:bnk5cs$arr$1@eclipse.org...
> Jan,
>
> Thanks for the advice. The problem stemmed from failing to call
> super.init from the init method of a sub class of GraphicalEditor.
>
> James
>
> Jan Ploski wrote:
>
> > James Willans wrote:
> > > Having said this, even when I force editParts to return true from
their
> > > getSelected() method, canPerformAction still returns false. Not sure
> > > what's happening here. Under what circumstances might an Action of
type
> > > SelectionAction not receive selection events?
>
> > The list returned by getSelectedObjects() depends on the current value
> > of the 'selection' field in class SelectionAction. This field is set by
> > the following chain of method calls:
>
> > GraphicalEditor.selectionChanged
> > GraphicalEditor.updateActions
> > SelectionAction.update
> > SelectionAction.setSelection
>
> > I would try setting breakpoints in all this methods to see where the
> > chain becomes broken in your case.
>
> > The above information is easy to find with the excellent Call Hierarchy
> > plugin (which is integrated into Eclipse 3.x, but you can obtain it
> > separately for 2.1.x).
>
> > -JPL
>
>
Previous Topic:GEF action handling migrated to JFace?
Next Topic:Paste several elements
Goto Forum:
  


Current Time: Wed May 07 23:45:00 EDT 2025

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

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

Back to the top