My ImageProvider is registered too late for my toolbar action [message #1710300] |
Mon, 05 October 2015 20:36 |
Erwin De Ley Messages: 52 Registered: August 2013 |
Member |
|
|
Dear all,
I'm developing on Eclipse Mars and Graphiti 0.12.0.v20150603-0807.
I try to add an action to the toolbar, for a graphiti-based editor. The tutorial mentions that a tool behavior provider could be used to add features to the toolbar (in the intro on tool behavior provider), but I couldn't find any further info on how to get that done. All further info seems to be about the context menu.
So I'm trying to get it done by extending the Graphiti DiagramEditorActionBarContributor. This seems to function, except for one thing : the action's image is never shown correctly, it always shows the MissingImageDescriptor. And this seems to be because the toolbar gets rendered before my image provider is registered. And once the MissingImageDescriptor is assigned to my image key, in org.eclipse.graphiti.ui.internal.services.impl.ImageService.createImageDescriptorForId(String, String), it's never replaced by the real image anymore.
I try to get this done as follows :
public class MyActionBarContributor extends DiagramEditorActionBarContributor {
@Override
public void contributeToToolBar(IToolBarManager toolbarManager) {
toolbarManager.add(new RunAction());
toolbarManager.add(new Separator());
super.contributeToToolBar(toolbarManager);
}
}
and registering it as follows :
<extension point="org.eclipse.ui.editors">
<editor
class="my.workflow.editor.MyDiagramEditor"
contributorClass="my.workflow.editor.MyActionBarContributor"
default="true"
extensions="tdml"
icon="icons/model.gif"
id="my.workflow.editor.MyDiagramEditor"
matchingStrategy="org.eclipse.graphiti.ui.editor.DiagramEditorMatchingStrategy"
name="My model editor">
<contentTypeBinding
contentTypeId="org.eclipse.graphiti.content.diagram">
</contentTypeBinding>
</editor>
</extension>
The RunAction tries to set its image in its constructor :
public RunAction() {
setId(getClass().getName());
setText("Run my workflow");
ImageDescriptor runImg = GraphitiUi.getImageService().getImageDescriptorForId(MyDiagramTypeProvider.ID, ImageConstants.IMG_RUN_WORKFLOW);
setImageDescriptor(runImg);
}
My image provider is configured following the info in the tutorial :
<extension point="org.eclipse.graphiti.ui.diagramTypeProviders">
<diagramTypeProvider
class="my.workflow.editor.MyDiagramTypeProvider"
context="org.eclipse.graphiti.ui.diagramEditor"
id="my.workflow.editor.MyDiagramTypeProvider"
name="My Workflow Editor">
<diagramType id="my.workflow.editor.workflowDiagramType" />
<imageProvider id="my.workflow.editor.ImageProvider" />
</diagramTypeProvider>
</extension>
<extension point="org.eclipse.graphiti.ui.imageProviders">
<imageProvider
class="my.workflow.editor.ImageProvider"
id="my.workflow.editor.ImageProvider">
</imageProvider>
</extension>
During debugging the opening of a model in my editor, it seems the toolbar is created first, incl my RunAction and when its constructor retrieves the image descriptor it always gets the missing image one.
Only after that do I see MyImageProvider.addAvailableImages being invoked, during the invocation of DiagramBehavior.initDiagramTypeProvider and its call to ExtensionManager.createDiagramTypeProvider() and its loadImageProvider() etc.
Is there a way to resolve this? Should I use another approach to add toolbar actions?
many thanks for the very nice graphiti framework,
erwin
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02718 seconds