Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Prevent adding new Node
Prevent adding new Node [message #638507] Thu, 11 November 2010 14:29 Go to next message
Peacemoon  is currently offline Peacemoon Friend
Messages: 14
Registered: November 2010
Junior Member
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?

Thanks
Re: Prevent adding new Node [message #638538 is a reply to message #638507] Thu, 11 November 2010 15:16 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Asiri Rathnayake is currently offline Asiri RathnayakeFriend
Messages: 80
Registered: September 2010
Location: Colombo, Sri Lanka.
Member
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 Go to previous message
Asiri Rathnayake is currently offline Asiri RathnayakeFriend
Messages: 80
Registered: September 2010
Location: Colombo, Sri Lanka.
Member
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

Previous Topic:GMF rectangle disappears when connecting with Connection
Next Topic:Create a node programmatically when open new document
Goto Forum:
  


Current Time: Thu Apr 25 07:18:31 GMT 2024

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

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

Back to the top