Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » My ImageProvider is registered too late for my toolbar action
My ImageProvider is registered too late for my toolbar action [message #1710300] Mon, 05 October 2015 20:36 Go to next message
erwin de ley is currently offline erwin de leyFriend
Messages: 49
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
Re: My ImageProvider is registered too late for my toolbar action [message #1710709 is a reply to message #1710300] Thu, 08 October 2015 15:04 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1883
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Erwin,

maybe an alternative approach would be better. In the Sketch test tool we add buttons with icons to the toolbar using plain Eclipse commands and menu entries. Check out the example at
http://git.eclipse.org/c/graphiti/org.eclipse.graphiti.git/tree/tests/org.eclipse.graphiti.testtool.sketch

In the plugin.xml we register e.g. a shrink command and menu entry.

HTH,
Michael
Re: My ImageProvider is registered too late for my toolbar action [message #1711349 is a reply to message #1710709] Thu, 15 October 2015 08:37 Go to previous message
erwin de ley is currently offline erwin de leyFriend
Messages: 49
Registered: August 2013
Member
Hi Michael,

I've done as you proposed and it works fine now, thanks!

regards
erwin
Previous Topic:[SOLVED] Unable to resize or move figures in the diagram
Next Topic:Diagram canvas on top of diagram canvas?
Goto Forum:
  


Current Time: Wed Jan 17 07:41:50 GMT 2018

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

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