Enable and disable Command Menu item programmatically [message #646090] |
Wed, 22 December 2010 01:31 |
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02579 seconds