Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Add dropdown menu to diagram tabbar
Add dropdown menu to diagram tabbar [message #1768678] Fri, 21 July 2017 11:32 Go to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 392
Registered: December 2015
Senior Member
Hi,

I am trying to add a dropdown menu to the diagram tabbar/toolbar, just like the Layers dropdown. My basic approach is to use the menus extension point, providing a contribution factory class that inherits the (internal) sirius class SiriusTabbarExtensionContributionFactory, using the (also internal) AbstractMenuContributionItem to provide contributions. The problem I have is that I am running into IllegalArgumentExceptions during calculateOffset(). It looks like the contribution keeps a wrong index of its position in the toolbar. I have also seen comments that could be related to this in TabbarFillerWithContributions:

// The visibility of static contributions are done before calling
// addTabbarContributions() to have a correct index when
//org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.AbstractMenuContributionItem.TabbarContributionItem.fill(ToolBar,
// int) is called

So it looks like something is done for the sirius-standard menus to avoid this issue, but I have no clue how to fix it for my additional dropdown menu. Has anyone added a menu/dropdown to the diagram bar without being hit by this?
Re: Add dropdown menu to diagram tabbar [message #1768682 is a reply to message #1768678] Fri, 21 July 2017 12:56 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
Hi,
You have a better way to provide a dropdown by following documentation at https://www.eclipse.org/sirius/doc/developer/extensions-provide_tabbar_extensions.html

And using the pulldown command kind:
index.php/fa/30067/0/

In the previous example you will have a drop down menu with two commands default and second. You also have the default command that is triggered when clicking on the icon without browsing the menu.

Hope this answers your question.

Regards,

Pierre


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Add dropdown menu to diagram tabbar [message #1770150 is a reply to message #1768678] Tue, 08 August 2017 15:45 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 392
Registered: December 2015
Senior Member
Hi Pierre, thank you. I didn't know about command's pulldown style. Now on to the next problem: I would like to show the menu only when a given diagram layer is active. So in the beginning, layer is disabled, and the dropdown should be hidden. Now I activate the layer, and the dropdown should be visible. Do you have any ideas on how to do that?
Re: Add dropdown menu to diagram tabbar [message #1770230 is a reply to message #1770150] Wed, 09 August 2017 09:17 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
Hi Felix,

I don't see an easy solution but the following should work (not tested so maybe I am missing something):

You can use a resource set listener on session's resource set to listen to filter activation deactivation and react accordingly:

When your plugin is activated you first have to register a listener in the SessionManager
SessionManager.INSTANCE.addSessionsListener(new SessionListener());

This allow to react each time a session is opened.

In this listener you will add the resource set listener each time a session is opened:


public class SessionListener extends SessionManagerListener.Stub {
    @Override
    public void notify(Session notifiedSession, int notification) {
        if ((SessionListener.OPENED== notification){
ResourceSetListenerChangeListener resourceSetListenerChangeListener = new ResourceSetListenerChangeListener();
        session.getTransactionalEditingDomain().addResourceSetListener(resourceSetListererChangeListener);


    }
}


Then in your listener ResourceSetListenerChangeListener you will react to notifications about activating/deactivating a layer and set a boolean variable myTargetLayerActivated to true or false regarding the notification accessible from anywhere like in your plugin singleton activator if you have one. This variable must be associated to the session like in a map:

 private final class ResourceSetListenerChangeListener extends ResourceSetListenerImpl {

        @Override
        public void resourceSetChanged(ResourceSetChangeEvent event) {
                boolean myTargetLayerActivated = isActivated(event);
MyPluginActivator.getSessionToListenerMap().put(session,myTargetLayerActivated );
        
/**You also need to trigger the refresh of the tabbar to update the visibility manually by using org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor.getTabBarManager().update(true)
from the current opened diagram editor**/ 

((DDiagramEditor)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()).getTabBarManager().update(true);

}
        @Override
        public boolean isPostcommitOnly() {
            return true;
        }

        @Override
        public NotificationFilter getFilter() {
            return NotificationFilter.NOT_TOUCH;
        }
    }




Next in your manifest where you declare your drop down menu, you need to set the visibility computing with visibleWhen expression in a property tester:

<visibleWhen checkEnabled="false">
      <with variable="activeEditor">
             <test property="testLayerActivatedForEditorSession"/>
         </with>
   </visibleWhen>

and in your tester class you use the map with layer information:


public class TestLayerActivatedForEditorSessionextends PropertyTester {
    public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
        if (receiver instanceof DDiagramEditor) {
return MyPluginActivator.getSessionToListenerMap().get(((DDiagramEditor)receiver).getSession());
     }
return false;
}

This should do the trick.

Regards,


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Add dropdown menu to diagram tabbar [message #1776531 is a reply to message #1770230] Fri, 17 November 2017 11:36 Go to previous message
Felix Dorner is currently offline Felix DornerFriend
Messages: 392
Registered: December 2015
Senior Member
Hi Pierre, can't get it working yet. It's not a too urgent issue, but I created https://bugs.eclipse.org/bugs/show_bug.cgi?id=527395 for further discussion.
Previous Topic:Create Edge in Sirius like the Reference Relation in ecore editor
Next Topic:Button in Tool Section only to trigger external java action
Goto Forum:
  


Current Time: Thu Apr 25 20:07:24 GMT 2024

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

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

Back to the top