Where to action registry code from GEF redbook [message #234269] |
Sat, 19 May 2007 01:55 |
Eclipse User |
|
|
|
Originally posted by: mlevison.gmail.com
In the EMF/GEF redbook there is some sample code that demonstrates
installing zoom menu and tool bar items. Unfortunately I can't get to
work as advertised.
The first problem is where to put the code discussed in Example 4-6
which is similar to this code:
ZoomManager zoomManager = getZoomManager();
IAction zoomIn = new ZoomInAction(zoomManager);
IAction zoomOut = new ZoomOutAction(zoomManager);
ActionRegistry actionRegistry = getActionRegistry();
actionRegistry.registerAction(zoomIn);
actionRegistry.registerAction(zoomOut);
The redbook says put it inside the editor part - but gives not hint as
to which method. If I put it inside the init method - I get a null
pointer exception as I try to access as I attempt
ScalableFreeFormEdit.getZoomManager() - presumably because my
RootEditPart is ready yet. If do it inside the configureGraphicalViewer
I get in trouble with my contributeMenu code in the actionBarContribiutor:
public void contributeToMenu(IMenuManager menuManager) {
super.contributeToMenu(menuManager);
System.out.println("contributeToMenu");
// add a "View" menu after "Edit"
MenuManager viewMenu = new MenuManager("View");
viewMenu.add(getAction(GEFActionConstants.ZOOM_IN));
viewMenu.add(getAction(GEFActionConstants.ZOOM_OUT));
}
In this case the exception occurs because the action has been registered
and so getAction returns null.
So clearly there is a better place to register the actions within the
EditPart - I just can't figure it out.
One last detail - before I tried to add the menu items I just tried to
add the ZoomComboContributionItem to either the coolbar or toolbar as below:
public void contributeToCoolBar(ICoolBarManager coolBarManager) {
super.contributeToCoolBar(coolBarManager);
System.out.println("contributeToCoolBar");
coolBarManager.add(new Separator());
coolBarManager.add(new ZoomComboContributionItem(getPage()));
}
and nothing appeared in the application's toolbar.
Is there an up to date working set of example code that demos adding
zoom items to the menu and coolbar via an ActionBarContributor? If not
would someone be prepare to spend an hour or two on the phone on
Tuesday? If you did then I would delighted to write and publish an fresh
example. (Heck if you're in the Ottawa area - lets do this over coffee)
Tired and confused in Ottawa.
Mark Levison
|
|
|
|
Re: Where to action registry code from GEF redbook [message #234372 is a reply to message #234288] |
Tue, 22 May 2007 16:33 |
Eclipse User |
|
|
|
Originally posted by: mlevison.gmail.com
Thanks for the help Phillip - the code gives me some great ideas.
Phillip Beauvoir wrote:
>
> In my Graphical Editor I have a method thus:
>
> /**
> * Add some extra Actions - after the graphical viewer has been created
> */
> protected void createAdditionalActions() {
> ZoomManager zoomManager =
> (ZoomManager)getAdapter(ZoomManager.class);
>
> ...
> getActionRegistry().registerAction(zoomIn);
> getActionRegistry().registerAction(zoomOut);
>
...
> getActionRegistry().registerAction(showGrid);
> }
>
> This is called from configureGraphicalViewer() thus:
>
> protected void configureGraphicalViewer() {
> super.configureGraphicalViewer();
> ...
> ScalableFreeformRootEditPart rootPart = new
> ScalableFreeformRootEditPart();
> viewer.setRootEditPart(rootPart);
>
> ...
> createAdditionalActions();
> }
However I'm still stuck - when do you contribute your actions to the
menu and coolbar?
Using an ActionBarContributor (registered for my edit part in my plugin
xml) I see things get created in the following sequence:
ActionBarContributor.buildActions
ActionBarContributor.contributeToMenu
ActionBarContributor.contributeToCoolBar
EditPart.Init
EditPart.configureGraphicalViewer
EditPart.createAdditionalActions
So as you can see the ActionBarContributor gets called before anything
in the EditPart is created - so there is no ScaleableFreeFormEditPart or
a ZoomManager etc. before the contributor is called.
Clearly the authors of the redbook expected this to work some how - I
just not sure how that is.
Can I delay all the calls to the ActionBarContributor? Do ditch
ActionBarContributor and just make all my contributions directly from
the EditPart?
Still as confused as ever
Mark Levison
|
|
|
Re: Where to action registry code from GEF redbook [message #234379 is a reply to message #234288] |
Tue, 22 May 2007 16:44 |
Eclipse User |
|
|
|
Originally posted by: mlevison.gmail.com
Thanks for the help Phillip - the code gives me some great ideas.
Phillip Beauvoir wrote:
>
> In my Graphical Editor I have a method thus:
>
> /**
> * Add some extra Actions - after the graphical viewer has been
created
> */
> protected void createAdditionalActions() {
> ZoomManager zoomManager =
> (ZoomManager)getAdapter(ZoomManager.class);
>
> ...
> getActionRegistry().registerAction(zoomIn);
> getActionRegistry().registerAction(zoomOut);
>
...
> getActionRegistry().registerAction(showGrid);
> }
>
> This is called from configureGraphicalViewer() thus:
>
> protected void configureGraphicalViewer() {
> super.configureGraphicalViewer();
> ...
> ScalableFreeformRootEditPart rootPart = new
> ScalableFreeformRootEditPart();
> viewer.setRootEditPart(rootPart);
>
> ...
> createAdditionalActions();
> }
However I'm still stuck - when do you contribute your actions to the
menu and coolbar?
Using an ActionBarContributor (registered for my edit part in my plugin
xml) I see things get created in the following sequence:
ActionBarContributor.buildActions
ActionBarContributor.contributeToMenu
ActionBarContributor.contributeToCoolBar
EditPart.Init
EditPart.configureGraphicalViewer
EditPart.createAdditionalActions
So as you can see the ActionBarContributor gets called before anything
in the EditPart is created - so there is no ScaleableFreeFormEditPart or
a ZoomManager etc. before the contributor is called.
Clearly the authors of the redbook expected this to work some how - I
just not sure how that is.
Can I delay all the calls to the ActionBarContributor? Do ditch
ActionBarContributor and just make all my contributions directly from
the EditPart?
Still as confused as ever
Mark Levison
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03692 seconds