|
Re: Prevent adding new Node [message #638538 is a reply to message #638507] |
Thu, 11 November 2010 15:16 |
Eclipse User |
|
|
|
Originally posted by: marius.groeger.googlemail.com
On 11.11.2010 15:29, Peacemoon wrote:
> Hello, i'm trying to catch the node adding event and check the new node
> against some conditions. When the test failed, the node shouldn't be
> added in both domain model and diagram.
>
> I have used OCL in gmfmap. But in this case, a new node will be created.
> Then i tried to change the the XXItemProvider class in edit package,
> commented all notifyChanged() out, but somehow a node is still created.
>
> I also tried to hook the notification in XXCanocialEditPolicy in diagram
> package by overriding the handleNotificationEvent methode and didn't
> call super.handleNotificationEvent. And, as you already know, the node
> still appears.
> I try to track down where i can insert my checking code for the node but
> i had no luck.
>
> Does anyone of you know where i should write my checking code and how
> can i prevent that a new node will be created both in domain model and
> in diagram?
AFAIR the command stack will traverse all edit policies and combine all
non-null commands. If any sub-command is unexecutable, the request is
not fulfilled and all(!) commands are dropped.
So, you might try registering a custom editpolicy (deriving
AbstractEditPolicy). In the getCommand() method filter for the correct
request you want to block and your special condition; if you want to
reject creation return UnexecutableCommand.INSTANCE.
Be warned, this is off the top of my head and might not work (fully or
in parts); experts: please correct me if I'm spreading myths here!
Regards
Marius
|
|
|
Re: Prevent adding new Node [message #639060 is a reply to message #638507] |
Mon, 15 November 2010 07:21 |
|
Hi,
I think the approach marius has mentioned will work (but I'm not an expert either). However I would like to know what exactly you are trying to achieve, I mean most of the time such constraints (like object A should not go inside object B) can be enforced in the EMF model itself, so you might be trying to achieve something the hard way that can be fixed in the model easily. If you can illustrate your problem using a sample model, we might be able to help you with an alternative approach.
- Asiri
|
|
|
Re: Prevent adding new Node [message #639061 is a reply to message #638507] |
Mon, 15 November 2010 07:30 |
|
Hi Again,
One more thing you can try:
In your diagram plugin, there should be a package like blah.blah.blah.diagram.edit.commands here you will find a command like XXXCreateCommand where XXX is the name of the node you want to control. In this command class simply update the canExecute() method to return false if your conditions are not met, I believe this solution (if it works for you) is bit clear than implementing your own edit policy as suggested by marius.
- Asiri
[Updated on: Mon, 15 November 2010 07:32] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02890 seconds