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