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{
	@Inject 
	MApplication application;
	
	@Inject
	private EModelService modelService;
	
	@CanExecute
	public boolean canExecute() {
		return ((MyProject.getFilename() != null) && MyProject.isModelDirty());
	}
	

	@Execute
	public Boolean execute() {


		if (canExecute() == true) // test en principe inutile
		{
			// ici le processus de sauvegarde du fichier
			MyProject.setDirty(false);
		}

		return Boolean.TRUE;
	}
	
	@PostConstruct
	public void register() 
	{
		ModelProvider.INSTANCE.addObserver(this);
	}


	@Override
	public void update(Observable o, Object arg) {
             // here i would like to change the enable state of my command
		MUIElement item = modelService.find("MyProject.handleditem.trimbar.top.save", application);
    	ToolItem toolItem= (ToolItem)(item.getWidget());
		toolItem.setEnabled(((ModelProvider)o).isModified());;
	}

	@PreDestroy
	public void unregister(MApplication application, EModelService service) 
	{
		ModelProvider.INSTANCE.deleteObserver(this);
	}
}


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: Sun Sep 23 08:03:09 GMT 2018

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

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

Back to the top