Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Guarding all commands in a custom editor
Guarding all commands in a custom editor [message #418597] Mon, 21 April 2008 20:48 Go to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
I need to guard all commands that are created/executed from a custom
editor. The guard needs to inspect the state of the model object and
possibly warn the user and prevent the command from executing. In other
words, our model contains some information that is intended to flag that
model object as being semi-read-only; the user will have to explicitly
choose to modify the object before changes to certain attributes are
applied to the model.
At first I thought I could do this with a custom CommandStack, but it
turns out that the Command interface (nor any of the base Command
implementations) doesn't give me the feature being modified by the
Command, so I can't determine if that command is allowed or not (it
depends on what feature is being modified). For the same reason, I can't
use the resourceToReadOnlyMap of AdapterFactoryEditingDomain (if a model
is semi-read-only, some commands must still allowed to execute).

Then I thought a custom EditingDomain was the answer, where I would
override the createCommand() method. But it seems that some "bogus"
commands are being created during editor initialization and those
commands are not relevant because they aren't actually touching the
model. These "bogus" commands are coming from the
EditingDomainActionBarContributor during initialization.

So, am I even on the right track here? I am loathe to put special-case
code in my createCommand() to look for certain kinds of commands and
ignore others. Is there another mechanism altogether that I could hook into?

TIA,
Eric
Re: Guarding all commands in a custom editor [message #418601 is a reply to message #418597] Mon, 21 April 2008 20:56 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Eric,

Perhaps you want to allow the command to be created, test if it's
executable, and only in that case do the additional check to see if it
should be disabled; doing that in the AdapterFactoryEditingDomain seems
like a good funnel point at which to cover everything. Or maybe all
your model objects inherit from a common root and you could put the
specialized command creation code in the item providers themselves...


Eric Rizzo wrote:
> I need to guard all commands that are created/executed from a custom
> editor. The guard needs to inspect the state of the model object and
> possibly warn the user and prevent the command from executing. In
> other words, our model contains some information that is intended to
> flag that model object as being semi-read-only; the user will have to
> explicitly choose to modify the object before changes to certain
> attributes are applied to the model.
> At first I thought I could do this with a custom CommandStack, but it
> turns out that the Command interface (nor any of the base Command
> implementations) doesn't give me the feature being modified by the
> Command, so I can't determine if that command is allowed or not (it
> depends on what feature is being modified). For the same reason, I
> can't use the resourceToReadOnlyMap of AdapterFactoryEditingDomain (if
> a model is semi-read-only, some commands must still allowed to execute).
>
> Then I thought a custom EditingDomain was the answer, where I would
> override the createCommand() method. But it seems that some "bogus"
> commands are being created during editor initialization and those
> commands are not relevant because they aren't actually touching the
> model. These "bogus" commands are coming from the
> EditingDomainActionBarContributor during initialization.
>
> So, am I even on the right track here? I am loathe to put special-case
> code in my createCommand() to look for certain kinds of commands and
> ignore others. Is there another mechanism altogether that I could hook
> into?
>
> TIA,
> Eric


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF Resources Data Migration
Next Topic:EMF Validation Framework
Goto Forum:
  


Current Time: Thu Apr 25 16:53:49 GMT 2024

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

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

Back to the top