Skip to main content

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 ThomasFriend
Messages: 11
Registered: March 2010
Junior Member
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:

the command:
          name="Open Navigator">

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

    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 ThomasFriend
Messages: 11
Registered: March 2010
Junior Member
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: Wed Sep 28 23:29:43 GMT 2022

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

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

Back to the top