Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » adding a new option to the context menu
adding a new option to the context menu [message #175999] Thu, 07 April 2005 10:24 Go to next message
Eclipse UserFriend
Originally posted by: jdelgad.correo.ugr.es

Hi !!

I want to add a new option to the context menu. So, the code I have
written inside the buildContext method is the following:



action = getActionRegistry().getAction( MyAction.MY_SHAPE );
if ( action.isEnabled() ) {
manager.appendToGroup( GEFActionConstants.GROUP_EDIT, action );
}




but when I right click on a figure I get a "NullPointerException"
because "action = null". The code for the class MyAction is the following:



public class MyAction extends SelectionAction {

public static final String MY_SHAPE = "MyShape";

/**
* @param editor
*/
public MyAction( IEditorPart editor ) {
super(editor);
setId( MY_SHAPE );
setText( "New Action" );
}

/**
* @see org.eclipse.gef.ui.actions.EditorPartAction#calculateEnabled ()
*/
protected boolean calculateEnabled() {
if (getSelectedObjects().isEmpty() ) {
return false;
}
EditPart part = (EditPart) getSelectedObjects().get( 0 );
if ( part instanceof JclecEditPart ) {
return true;
} else {
return false;
}
}

public void run() {
EditPart part = (EditPart) getSelectedObjects().get( 0 );
((Model)((JclecEditPart) part).getModel()).setMyAction( true );
}
}



Do you know why I get the exception? Please help.

Thank you

--Jose.
Re: adding a new option to the context menu [message #176005 is a reply to message #175999] Thu, 07 April 2005 12:48 Go to previous messageGo to next message
Brian Fernandes is currently offline Brian FernandesFriend
Messages: 68
Registered: July 2009
Member
Jose,

You're probably forgetten to *register* your action with your editors
ActionRegsitry, which is why you're getting a null action from
ActionRegistry#getAction.

You would probably want to override GraphicalEditor#createActions in your
editor and create and register your action at that time.

Please have a look at how the example GEF editors do this,
Best,
Brian.
"Jose" <jdelgad@correo.ugr.es> wrote in message
news:5fc09fde54c038f2ff4f2246ad6fdc6a$1@www.eclipse.org...
> Hi !!
>
> I want to add a new option to the context menu. So, the code I have
> written inside the buildContext method is the following:
>
>
>
> action = getActionRegistry().getAction( MyAction.MY_SHAPE );
> if ( action.isEnabled() ) {
> manager.appendToGroup( GEFActionConstants.GROUP_EDIT, action );
> }
>
>
>
>
> but when I right click on a figure I get a "NullPointerException"
> because "action = null". The code for the class MyAction is the following:
>
>
>
> public class MyAction extends SelectionAction {
>
> public static final String MY_SHAPE = "MyShape";
>
> /**
> * @param editor
> */
> public MyAction( IEditorPart editor ) {
> super(editor);
> setId( MY_SHAPE );
> setText( "New Action" );
> }
>
> /**
> * @see org.eclipse.gef.ui.actions.EditorPartAction#calculateEnabled ()
> */
> protected boolean calculateEnabled() {
> if (getSelectedObjects().isEmpty() ) {
> return false;
> }
> EditPart part = (EditPart) getSelectedObjects().get( 0 );
> if ( part instanceof JclecEditPart ) {
> return true;
> } else {
> return false;
> }
> }
>
> public void run() {
> EditPart part = (EditPart) getSelectedObjects().get( 0 );
> ((Model)((JclecEditPart) part).getModel()).setMyAction( true ); }
> }
>
>
>
> Do you know why I get the exception? Please help.
>
> Thank you
>
> --Jose.
>
Re: adding a new option to the context menu (PROBLEM SOLVED) [message #176062 is a reply to message #176005] Thu, 07 April 2005 18:00 Go to previous message
Eclipse UserFriend
Originally posted by: jdelgad.correo.ugr.es

Hi Brian,

the problem was what you say, i.e. the action wasn't registered.


Thank you very much.

--Jose.
Previous Topic:build I20050331 GTK2 problem
Next Topic:problems with ManhattanConnectionRouter
Goto Forum:
  


Current Time: Sun Jan 29 18:49:19 GMT 2023

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

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

Back to the top