Skip to main content


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 Go to next message
ash is currently offline ashFriend
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

Re: Enable and disable Command Menu item programmatically [message #1711193 is a reply to message #646090] Wed, 14 October 2015 05:16 Go to previous message
ilke Muhtar is currently offline ilke MuhtarFriend
Messages: 47
Registered: September 2015
Member
I am stuck here as well :

I say buildCommand.setEnabled(true); but it doesnt work. It espects Object EvaluationContext, have you solved this problem ?

ilke
Previous Topic:Multi-word org.eclipse.ui.keywords for preference page filter
Next Topic:Non-Closeable Views are closeable via Menu
Goto Forum:
  


Current Time: Tue Apr 23 12:05:36 GMT 2024

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

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

Back to the top