Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Enable and disable Command Menu item programmatically
Enable and disable Command Menu item programmatically [message #646090] Wed, 22 December 2010 01:31
ash is currently offline ash
Messages: 142
Registered: July 2010
Senior Member
Hi,

Can any how change the enable and disable the commmand button of the viewtoolbar/viewmenu programatically


package com.jobsleaf.propertytester;
import org.eclipse.core.commands.AbstractHandler;


public class DeleteHandler extends AbstractHandler
{
boolean mEnabled = false;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException
{
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l();
MessageDialog.open(MessageDialog.INFORMATION, shell, "PropertyTester", "Hi All", SWT.OK);
return null;
}

public boolean isEnabled()
{
return mEnabled;
}
@Override
protected void setBaseEnabled(boolean state)
{

super.setBaseEnabled(state);
}
@Override
public boolean isHandled()
{

return mEnabled ;

}
@Override
public void setEnabled(Object evaluationContext)
{


System.out.println( "I am into set enabled methos ");
if(evaluationContext instanceof Boolean)
{
System.out.println( "I am into set enabled methos 11111111");
mEnabled = ((Boolean)evaluationContext).booleanValue();
fireHandlerChanged(new HandlerEvent(this, mEnabled, false));
}
else
{
super.setEnabled(evaluationContext);
}

In the view on some event i want to change the enable of the biutton

if(count > 0)
{
commandService = (ICommandService)PlatformUI.getWorkbench().getService(IComma ndService.class);
IHandlerService handlerservice = (IHandlerService)PlatformUI.getWorkbench().getService(IHandl erService.class);

command = commandService.getCommand("com.jobsleaf.propertytester.delete ");
s = (AbstractHandler) command.getHandler();
s.setEnabled(true);

Map filter = new HashMap();
filter.put(IServiceScopes.WINDOW_SCOPE, getSite().getPage()
.getWorkbenchWindow());

commandService.refreshElements("com.jobsleaf.propertytester.delete ", filter);

}
else
{
Map filter = new HashMap();
filter.put(IServiceScopes.WINDOW_SCOPE, getSite().getPage()
.getWorkbenchWindow());

command.setEnabled(false);
commandService.refreshElements("com.jobsleaf.propertytester.delete ", filter);
}

}catch (Exception e) {
// TODO: handle exception
}




}


}

I tried to to this but its not working. can any provide me the solution

Thanks
ashok

[Updated on: Wed, 22 December 2010 01:33]

Report message to a moderator

Previous Topic:how bind commands to buttons with enabled state
Next Topic:Clear the workspace folder
Goto Forum:
  


Current Time: Sat Oct 25 04:18:30 GMT 2014

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

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