Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Menu Contribution Toggle Button issue
Menu Contribution Toggle Button issue [message #543349] Tue, 29 June 2010 07:59 Go to next message
Thomas is currently offline Thomas
Messages: 11
Registered: March 2010
Junior Member
Hi,
I have an RCP application which has a view and a menu contribution with a toggle button command.
If I'm opening my view via the toggle button command it should be checked and if I uncheck it my view should be closed.
My solution looks like this:
<menuContribution
            locationURI="menu:org.eclipse.ui.main.menu?after=tools">
         <menu
               id="window"
               label="Window">
            <command
                  commandId="Rcp.openDefaultPerspective"
                  label="Default"
                  style="push">
            </command>
            <separator
                  name="separator1"
                  visible="true">
            </separator>
            <command
                  commandId="Rcp.openNavigator"
                  icon="icons/menu/8.01a_Configuration_16x16.png"
                  label="Navigator"
                  style="toggle">
            </command>
</menuContribution>


the command:
<command
          defaultHandler="rcp.handler.OpenNavigatorHandler"
          id="Rcp.openNavigator"
          name="Open Navigator">
       <state
             class="org.eclipse.ui.handlers.RegistryToggleState:true"
             id="org.eclipse.ui.commands.toggleState">
       </state>
</command>


my handler:
public class OpenNavigatorHandler extends AbstractHandler {
    @SuppressWarnings("unused")
    private static Logger log = Logger.getLogger( OpenNavigatorHandler.class );

    @Override
    public Object execute(final ExecutionEvent event) throws ExecutionException {
        final Command command = event.getCommand();
        final boolean wasChecked = HandlerUtil.toggleCommandState( command );

        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if( !wasChecked ) {
            if( window != null ) {
                try {
                    window.getActivePage().showView( "Rcp.openNavigator" );

                } catch( final PartInitException e ) {
                    MessageDialog.openError( window.getShell(), "Error", "Error opening view:" + e.getMessage() );
                }
            }
        } else {
            final IViewPart view = window.getActivePage().findView( "Rcp.openNavigator" );
            if( view != null ) {
                window.getActivePage().hideView( view );
            }
        }

        return null;
    }
}


The Problem now is what if I'm closing my view via the [x] how should the toggle button be notified?and I also have an "Reset perspective" command, by default the view is open. The problem there is also that how should the toggle button be notified.
I read something about the handler should implement IElementUpdater and the view should call HandlerUtil.refreshElements(*) but couldn't find a useful snippet.
I'm working with Eclipse 3.5.

Thanks in advance

[Updated on: Tue, 29 June 2010 08:24]

Report message to a moderator

Re: Menu Contribution Toggle Button issue [message #544244 is a reply to message #543349] Fri, 02 July 2010 06:59 Go to previous message
Thomas is currently offline Thomas
Messages: 11
Registered: March 2010
Junior Member
Hi,
I managed to implement it.
My handler implements IElementUpdater and I'm calling in the init and dispose method of my view:
final ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService( ICommandService.class );
service.refreshElements( commandID, null );
Previous Topic:How can i Create?!
Next Topic:RCP application no longer able to update after migrating to Helios
Goto Forum:
  


Current Time: Fri Sep 19 10:06:52 GMT 2014

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

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