Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Enabling/disabling dynamically Tool Item
Enabling/disabling dynamically Tool Item [message #1784029] Wed, 21 March 2018 18:13
Philippe Hordonneau is currently offline Philippe HordonneauFriend
Messages: 3
Registered: July 2009
Junior Member
My saveCommand is hold by a HandledMenuItem and a HandledToolItem.
The command must be disabled when no change occurs in the data model.

I'd like to disable the ToolItem dynamically. So the SaveHandler is an observer of my model. The data model notifies its dependants when the dirty property of the datamodel changes.

Here is the code:

public class SaveHandler implements Observer{
	MApplication application;
	private EModelService modelService;
	public boolean canExecute() {
		return ((MyProject.getFilename() != null) && MyProject.isModelDirty());

	public Boolean execute() {

		if (canExecute() == true) // test en principe inutile
			// ici le processus de sauvegarde du fichier

		return Boolean.TRUE;
	public void register() 

	public void update(Observable o, Object arg) {
             // here i would like to change the enable state of my command
		MUIElement item = modelService.find("", application);
    	ToolItem toolItem= (ToolItem)(item.getWidget());

	public void unregister(MApplication application, EModelService service) 

I am not satisfied with this solution. In fact as it is the the command that becomes enabled/disabled it would be logic to ask the command to notify the gui elements to refresh. I'am not satisfied to have to search the swt component in order to refresh the tool item.

I'm new with Eclipse E4. Any suggestion to a proper solution? Thanks a lot.
Previous Topic:MPart in Handler assigned to the part is not injected? (SOLVED)
Next Topic:E4 with compatibility layer - menus
Goto Forum:

Current Time: Thu Apr 22 17:43:36 GMT 2021

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

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

Back to the top