Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Hook to prevent command execution
Hook to prevent command execution [message #1815009] Tue, 24 September 2019 07:27 Go to next message
Marcus Höpfner is currently offline Marcus HöpfnerFriend
Messages: 56
Registered: February 2014
Member
Hi,

we are working on server resources, they are downloaded/uploaded to/from Eclipse. These resource are EMF based.

During first editing of a resource the server is asked whether the resource can be locked (no one else is editing the resource).
If it fails, editing must be stopped.

Everything is EMF command-based via databinding or actions in context menus of table and tree viewers.

The question is whether there is a single spot in EMF which is passed directly before command execution to plug the lock logic in? If lock fails, I must be able to abort the command execution.
One spot I have found is, to override the execute(Command command) method in the used WorkspaceCommandStack and only call super.execute(command) if lock succeeds. Is there a better spot? Maybe even with a notify mechanism. Because the databinding has to be updated to the UI.
Imagine a user enters a value in a text box and the lock fails. Actually the ui needs to be updated from the model to revert the entered value.

Thanks
Re: Hook to prevent command execution [message #1815013 is a reply to message #1815009] Tue, 24 September 2019 08:29 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Generally org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.isReadOnly(Resource) is consulted to determine if the resource is modifiable or not:
  public boolean isReadOnly(Resource resource)
  {
    if (resourceToReadOnlyMap == null)
    {
      return false;
    }
    else
    {
      Boolean result = resourceToReadOnlyMap.get(resource);
      if (result == null && resource != null)
      {
        Map<?, ?> options = Collections.singletonMap(URIConverter.OPTION_REQUESTED_ATTRIBUTES, Collections.singleton(URIConverter.ATTRIBUTE_READ_ONLY));
		Map<String, ?> attributes = (resource.getResourceSet() == null ? resourceSet : resource.getResourceSet()).getURIConverter().getAttributes(resource.getURI(), options);
        result = Boolean.TRUE.equals(attributes.get(URIConverter.ATTRIBUTE_READ_ONLY));
        resourceToReadOnlyMap.put(resource, result);
      }
      return Boolean.TRUE.equals(result);
    }
  }
But that process is generally a "eager" about determining whether the resource is modifiable or not. If you want to determine it "lazily" upon the actual attempt to edit something, then the command stack would seem like the place to do that. And then indeed providing feedback to the user about the "failed/blocked" edit (command execution) becomes a problem. I'm not sure how best to handle that given I don't know in detail how the UI is hooked up...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Hook to prevent command execution [message #1815027 is a reply to message #1815013] Tue, 24 September 2019 11:41 Go to previous message
Marcus Höpfner is currently offline Marcus HöpfnerFriend
Messages: 56
Registered: February 2014
Member
Ok. isReadOnly is the wrong place for my purpose.
I'll go for two approaches:
- in databinding I'll use a validator. when it validates to false the ui is updated
- an action wrapper which checks for lock before it runs the actual action (which calls a command)

Previous Topic:Genmodel warnings with 2019-06
Next Topic:Hide specific elements in tree editor
Goto Forum:
  


Current Time: Tue Apr 16 16:57:08 GMT 2024

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

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

Back to the top