Home » Eclipse Projects » GEF » Null action registry from copied gef flow example
Null action registry from copied gef flow example [message #141593] |
Tue, 06 July 2004 00:38  |
Eclipse User |
|
|
|
Originally posted by: RichardSpackmann.mafd.org
I am trying to set up a context menu for when I right click on an editpart
and am following the source code given in the flow example.
The problem is that I am getting a NullPointerException at the following
line:
menu.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
of the FlowContextMenuProvider class.
In debugging the plugin, the action registry is empty. Thus, "action" is
null (which is also confirmed in debug mode).
I copied over all the relevant (at least what I thought was relevant) - but
it doesn't work.
From what I understand from the GraphicalEditor JavaDocs, the method
"getActionRegistry" should create the action registry - and I would assume
that all the "standard" actions (all the GEFActionConstants) would be part
of it.
Does anyone know what could be the culprit?
Spack
|
|
| |
Re: Null action registry from copied gef flow example [message #141787 is a reply to message #141770] |
Tue, 06 July 2004 14:29   |
Eclipse User |
|
|
|
Originally posted by: webmaster.mafd.org
I'm obviously missing something - but at this point, I do not know what. I
believe that I copied over the necessary code which consists of the
FlowContextMenuProvider class and the configureGraphicalViewer protected
method in the editor class (which instantiates the FlowContentMenuProvider
class) - I attached the code below. Since the flow example really doesn't do
anything special in terms of actions for the context menu - this should be
all that I need to do right?
public class MyEditor extends GraphicalEditorWithPalette {
private KeyHandler sharedKeyHandler;
private PaletteRoot _paletteRoot = null;
public MyEditor() {
setEditDomain(new DefaultEditDomain(this));
}
public void init(IEditorSite iSite, IEditorInput iInput) throws
PartInitException {
setSite(iSite);
setInput(iInput);
}
protected void createActions() {
super.createActions();
ActionRegistry registry = getActionRegistry();
IAction action;
action = new DirectEditAction((IWorkbenchPart)this);
registry.registerAction(action);
getSelectionActions().add(action.getId());
}
protected KeyHandler getCommonKeyHandler() {
if (sharedKeyHandler == null) {
sharedKeyHandler = new KeyHandler();
sharedKeyHandler.put(
KeyStroke.getPressed(SWT.DEL, 127, 0),
getActionRegistry().getAction(GEFActionConstants.DELETE));
sharedKeyHandler.put(
KeyStroke.getPressed(SWT.F2, 0),
getActionRegistry().getAction(GEFActionConstants.DIRECT_EDIT ));
}
return sharedKeyHandler;
}
protected void initializeGraphicalViewer() {
getGraphicalViewer().setContents(new PlanDrawingModel());
}
protected void configureGraphicalViewer() {
super.configureGraphicalViewer();
getGraphicalViewer().setRootEditPart(new FreeformGraphicalRootEditPart());
getGraphicalViewer().setEditPartFactory(new GraphicalPartFactory());
getGraphicalViewer().setKeyHandler(new
GraphicalViewerKeyHandler(getGraphicalViewer())
.setParent(getCommonKeyHandler()));
((FigureCanvas)getGraphicalViewer().getControl()).setScrollB arVisibility(Fig
ureCanvas.ALWAYS);
ContextMenuProvider provider =
new FlowContextMenuProvider(getGraphicalViewer(), getActionRegistry());
getGraphicalViewer().setContextMenu(provider);
getSite().registerContextMenu(
"org.eclipse.gef.examples.flow.editor.contextmenu", //$NON-NLS-1$
provider,
getGraphicalViewer());
}
public void setActiveTool(Tool tool) {
getEditDomain().setActiveTool(tool);
}
protected PaletteRoot getPaletteRoot() {
if (_paletteRoot == null)
_paletteRoot = MerceePlanEditorPaletteFactory.createPalette();
return _paletteRoot;
}
}
//same except for extra println stmts in buildContextMenu
public class FlowContextMenuProvider extends ContextMenuProvider {
private ActionRegistry actionRegistry;
public FlowContextMenuProvider(EditPartViewer viewer, ActionRegistry
registry) {
super(viewer);
setActionRegistry(registry);
}
public void buildContextMenu(IMenuManager menu) {
if (menu == null) System.out.println("MENU IS @#$%& NULL!");
GEFActionConstants.addStandardActionGroups(menu);
IAction action;
action = getActionRegistry().getAction(GEFActionConstants.UNDO);
if (action == null) System.out.println("ACTION IS @#$%& NULL!");
menu.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
action = getActionRegistry().getAction(GEFActionConstants.REDO);
menu.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
action = getActionRegistry().getAction(IWorkbenchActionConstants.DELE TE);
if (action.isEnabled())
menu.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
}
}
"Pratik Shah" <ppshah@us.ibm.com> wrote in message
news:cceovr$10a$1@eclipse.org...
> When are you doing this? The only thing I can think of that would cause
> this is trying to access the action before the editor's site is set, i.e.
> before the editor's init(IEditorSite, IEditorInput) method has been
invoked.
> The actions are added to the action registry in
initializeActionRegistry(),
> which is invoked when the above-mentioned method is executed.
>
> "Richard Spackmann" <RichardSpackmann@mafd.org> wrote in message
> news:ccdaa1$b5v$1@eclipse.org...
> > I am trying to set up a context menu for when I right click on an
editpart
> > and am following the source code given in the flow example.
> >
> > The problem is that I am getting a NullPointerException at the following
> > line:
> > menu.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
> > of the FlowContextMenuProvider class.
> >
> > In debugging the plugin, the action registry is empty. Thus, "action" is
> > null (which is also confirmed in debug mode).
> >
> > I copied over all the relevant (at least what I thought was relevant) -
> but
> > it doesn't work.
> >
> > From what I understand from the GraphicalEditor JavaDocs, the method
> > "getActionRegistry" should create the action registry - and I would
assume
> > that all the "standard" actions (all the GEFActionConstants) would be
part
> > of it.
> >
> > Does anyone know what could be the culprit?
> >
> > Spack
> >
> >
>
>
|
|
|
Re: Null action registry from copied gef flow example [message #141805 is a reply to message #141787] |
Tue, 06 July 2004 18:42   |
Eclipse User |
|
|
|
You are over-riding GraphicalEditor's init(IEditorSite, IEditorInput)
method, which invokes initailizeActionRegistry().
"Richard Spackmann" <webmaster@mafd.org> wrote in message
news:ccer01$4om$1@eclipse.org...
> I'm obviously missing something - but at this point, I do not know what. I
> believe that I copied over the necessary code which consists of the
> FlowContextMenuProvider class and the configureGraphicalViewer protected
> method in the editor class (which instantiates the FlowContentMenuProvider
> class) - I attached the code below. Since the flow example really doesn't
do
> anything special in terms of actions for the context menu - this should be
> all that I need to do right?
>
> public class MyEditor extends GraphicalEditorWithPalette {
>
> private KeyHandler sharedKeyHandler;
> private PaletteRoot _paletteRoot = null;
>
> public MyEditor() {
> setEditDomain(new DefaultEditDomain(this));
> }
>
> public void init(IEditorSite iSite, IEditorInput iInput) throws
> PartInitException {
> setSite(iSite);
> setInput(iInput);
> }
>
> protected void createActions() {
> super.createActions();
> ActionRegistry registry = getActionRegistry();
> IAction action;
>
> action = new DirectEditAction((IWorkbenchPart)this);
> registry.registerAction(action);
> getSelectionActions().add(action.getId());
> }
>
> protected KeyHandler getCommonKeyHandler() {
> if (sharedKeyHandler == null) {
> sharedKeyHandler = new KeyHandler();
> sharedKeyHandler.put(
> KeyStroke.getPressed(SWT.DEL, 127, 0),
> getActionRegistry().getAction(GEFActionConstants.DELETE));
> sharedKeyHandler.put(
> KeyStroke.getPressed(SWT.F2, 0),
> getActionRegistry().getAction(GEFActionConstants.DIRECT_EDIT ));
> }
> return sharedKeyHandler;
> }
>
> protected void initializeGraphicalViewer() {
> getGraphicalViewer().setContents(new PlanDrawingModel());
> }
>
> protected void configureGraphicalViewer() {
> super.configureGraphicalViewer();
> getGraphicalViewer().setRootEditPart(new
FreeformGraphicalRootEditPart());
> getGraphicalViewer().setEditPartFactory(new GraphicalPartFactory());
> getGraphicalViewer().setKeyHandler(new
> GraphicalViewerKeyHandler(getGraphicalViewer())
> .setParent(getCommonKeyHandler()));
>
>
((FigureCanvas)getGraphicalViewer().getControl()).setScrollB arVisibility(Fig
> ureCanvas.ALWAYS);
>
> ContextMenuProvider provider =
> new FlowContextMenuProvider(getGraphicalViewer(),
getActionRegistry());
> getGraphicalViewer().setContextMenu(provider);
> getSite().registerContextMenu(
> "org.eclipse.gef.examples.flow.editor.contextmenu", //$NON-NLS-1$
> provider,
> getGraphicalViewer());
> }
>
> public void setActiveTool(Tool tool) {
> getEditDomain().setActiveTool(tool);
> }
>
> protected PaletteRoot getPaletteRoot() {
> if (_paletteRoot == null)
> _paletteRoot = MerceePlanEditorPaletteFactory.createPalette();
> return _paletteRoot;
> }
> }
>
> //same except for extra println stmts in buildContextMenu
> public class FlowContextMenuProvider extends ContextMenuProvider {
>
> private ActionRegistry actionRegistry;
>
> public FlowContextMenuProvider(EditPartViewer viewer, ActionRegistry
> registry) {
> super(viewer);
> setActionRegistry(registry);
> }
>
> public void buildContextMenu(IMenuManager menu) {
> if (menu == null) System.out.println("MENU IS @#$%& NULL!");
> GEFActionConstants.addStandardActionGroups(menu);
>
> IAction action;
> action = getActionRegistry().getAction(GEFActionConstants.UNDO);
> if (action == null) System.out.println("ACTION IS @#$%& NULL!");
> menu.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
>
> action = getActionRegistry().getAction(GEFActionConstants.REDO);
> menu.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
>
> action = getActionRegistry().getAction(IWorkbenchActionConstants.DELE TE);
> if (action.isEnabled())
> menu.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
> }
>
> }
>
> "Pratik Shah" <ppshah@us.ibm.com> wrote in message
> news:cceovr$10a$1@eclipse.org...
> > When are you doing this? The only thing I can think of that would cause
> > this is trying to access the action before the editor's site is set,
i.e.
> > before the editor's init(IEditorSite, IEditorInput) method has been
> invoked.
> > The actions are added to the action registry in
> initializeActionRegistry(),
> > which is invoked when the above-mentioned method is executed.
> >
> > "Richard Spackmann" <RichardSpackmann@mafd.org> wrote in message
> > news:ccdaa1$b5v$1@eclipse.org...
> > > I am trying to set up a context menu for when I right click on an
> editpart
> > > and am following the source code given in the flow example.
> > >
> > > The problem is that I am getting a NullPointerException at the
following
> > > line:
> > > menu.appendToGroup(GEFActionConstants.GROUP_UNDO,
action);
> > > of the FlowContextMenuProvider class.
> > >
> > > In debugging the plugin, the action registry is empty. Thus, "action"
is
> > > null (which is also confirmed in debug mode).
> > >
> > > I copied over all the relevant (at least what I thought was
relevant) -
> > but
> > > it doesn't work.
> > >
> > > From what I understand from the GraphicalEditor JavaDocs, the method
> > > "getActionRegistry" should create the action registry - and I would
> assume
> > > that all the "standard" actions (all the GEFActionConstants) would be
> part
> > > of it.
> > >
> > > Does anyone know what could be the culprit?
> > >
> > > Spack
> > >
> > >
> >
> >
>
>
|
|
|
Re: Null action registry from copied gef flow example [message #142042 is a reply to message #141805] |
Wed, 07 July 2004 10:41  |
Eclipse User |
|
|
|
Originally posted by: RichardSpackmann.mafd.org
Yup - that definately solved it - thanks again!
"Pratik Shah" <ppshah@us.ibm.com> wrote in message
news:ccf9qr$rbv$1@eclipse.org...
> You are over-riding GraphicalEditor's init(IEditorSite, IEditorInput)
> method, which invokes initailizeActionRegistry().
>
> "Richard Spackmann" <webmaster@mafd.org> wrote in message
> news:ccer01$4om$1@eclipse.org...
> > I'm obviously missing something - but at this point, I do not know what.
I
> > believe that I copied over the necessary code which consists of the
> > FlowContextMenuProvider class and the configureGraphicalViewer protected
> > method in the editor class (which instantiates the
FlowContentMenuProvider
> > class) - I attached the code below. Since the flow example really
doesn't
> do
> > anything special in terms of actions for the context menu - this should
be
> > all that I need to do right?
> >
> > public class MyEditor extends GraphicalEditorWithPalette {
> >
> > private KeyHandler sharedKeyHandler;
> > private PaletteRoot _paletteRoot = null;
> >
> > public MyEditor() {
> > setEditDomain(new DefaultEditDomain(this));
> > }
> >
> > public void init(IEditorSite iSite, IEditorInput iInput) throws
> > PartInitException {
> > setSite(iSite);
> > setInput(iInput);
> > }
> >
> > protected void createActions() {
> > super.createActions();
> > ActionRegistry registry = getActionRegistry();
> > IAction action;
> >
> > action = new DirectEditAction((IWorkbenchPart)this);
> > registry.registerAction(action);
> > getSelectionActions().add(action.getId());
> > }
> >
> > protected KeyHandler getCommonKeyHandler() {
> > if (sharedKeyHandler == null) {
> > sharedKeyHandler = new KeyHandler();
> > sharedKeyHandler.put(
> > KeyStroke.getPressed(SWT.DEL, 127, 0),
> > getActionRegistry().getAction(GEFActionConstants.DELETE));
> > sharedKeyHandler.put(
> > KeyStroke.getPressed(SWT.F2, 0),
> > getActionRegistry().getAction(GEFActionConstants.DIRECT_EDIT ));
> > }
> > return sharedKeyHandler;
> > }
> >
> > protected void initializeGraphicalViewer() {
> > getGraphicalViewer().setContents(new PlanDrawingModel());
> > }
> >
> > protected void configureGraphicalViewer() {
> > super.configureGraphicalViewer();
> > getGraphicalViewer().setRootEditPart(new
> FreeformGraphicalRootEditPart());
> > getGraphicalViewer().setEditPartFactory(new GraphicalPartFactory());
> > getGraphicalViewer().setKeyHandler(new
> > GraphicalViewerKeyHandler(getGraphicalViewer())
> > .setParent(getCommonKeyHandler()));
> >
> >
>
((FigureCanvas)getGraphicalViewer().getControl()).setScrollB arVisibility(Fig
> > ureCanvas.ALWAYS);
> >
> > ContextMenuProvider provider =
> > new FlowContextMenuProvider(getGraphicalViewer(),
> getActionRegistry());
> > getGraphicalViewer().setContextMenu(provider);
> > getSite().registerContextMenu(
> > "org.eclipse.gef.examples.flow.editor.contextmenu", //$NON-NLS-1$
> > provider,
> > getGraphicalViewer());
> > }
> >
> > public void setActiveTool(Tool tool) {
> > getEditDomain().setActiveTool(tool);
> > }
> >
> > protected PaletteRoot getPaletteRoot() {
> > if (_paletteRoot == null)
> > _paletteRoot = MerceePlanEditorPaletteFactory.createPalette();
> > return _paletteRoot;
> > }
> > }
> >
> > //same except for extra println stmts in buildContextMenu
> > public class FlowContextMenuProvider extends ContextMenuProvider {
> >
> > private ActionRegistry actionRegistry;
> >
> > public FlowContextMenuProvider(EditPartViewer viewer, ActionRegistry
> > registry) {
> > super(viewer);
> > setActionRegistry(registry);
> > }
> >
> > public void buildContextMenu(IMenuManager menu) {
> > if (menu == null) System.out.println("MENU IS @#$%& NULL!");
> > GEFActionConstants.addStandardActionGroups(menu);
> >
> > IAction action;
> > action = getActionRegistry().getAction(GEFActionConstants.UNDO);
> > if (action == null) System.out.println("ACTION IS @#$%& NULL!");
> > menu.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
> >
> > action = getActionRegistry().getAction(GEFActionConstants.REDO);
> > menu.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
> >
> > action =
getActionRegistry().getAction(IWorkbenchActionConstants.DELE TE);
> > if (action.isEnabled())
> > menu.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
> > }
> >
> > }
> >
> > "Pratik Shah" <ppshah@us.ibm.com> wrote in message
> > news:cceovr$10a$1@eclipse.org...
> > > When are you doing this? The only thing I can think of that would
cause
> > > this is trying to access the action before the editor's site is set,
> i.e.
> > > before the editor's init(IEditorSite, IEditorInput) method has been
> > invoked.
> > > The actions are added to the action registry in
> > initializeActionRegistry(),
> > > which is invoked when the above-mentioned method is executed.
> > >
> > > "Richard Spackmann" <RichardSpackmann@mafd.org> wrote in message
> > > news:ccdaa1$b5v$1@eclipse.org...
> > > > I am trying to set up a context menu for when I right click on an
> > editpart
> > > > and am following the source code given in the flow example.
> > > >
> > > > The problem is that I am getting a NullPointerException at the
> following
> > > > line:
> > > > menu.appendToGroup(GEFActionConstants.GROUP_UNDO,
> action);
> > > > of the FlowContextMenuProvider class.
> > > >
> > > > In debugging the plugin, the action registry is empty. Thus,
"action"
> is
> > > > null (which is also confirmed in debug mode).
> > > >
> > > > I copied over all the relevant (at least what I thought was
> relevant) -
> > > but
> > > > it doesn't work.
> > > >
> > > > From what I understand from the GraphicalEditor JavaDocs, the method
> > > > "getActionRegistry" should create the action registry - and I would
> > assume
> > > > that all the "standard" actions (all the GEFActionConstants) would
be
> > part
> > > > of it.
> > > >
> > > > Does anyone know what could be the culprit?
> > > >
> > > > Spack
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Goto Forum:
Current Time: Sun May 11 16:48:50 EDT 2025
Powered by FUDForum. Page generated in 0.06757 seconds
|