adding a new option to the context menu [message #175999] |
Thu, 07 April 2005 10:24 |
Eclipse User |
|
|
|
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.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03225 seconds