Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » recursive notification to parent question
recursive notification to parent question [message #499360] Sat, 21 November 2009 11:32 Go to next message
Matt South is currently offline Matt SouthFriend
Messages: 5
Registered: November 2009
Junior Member
I have a fairly simple EMF class, Rebutter, whose java annotations consist of the following:
/**
 * @model
 */
public interface Rebutter {
	/**
	 * @model containment="true" max=1 opposite="rebutted"
	 */
	Rebutter getRebutter();
	
	/**
	 * @model changeable="false" transient="true" derived="true" volatile="true"
	 */
	boolean isAccepted();
	
	/**
	 * @model changeable="false" opposite="rebutter"
	 */
	Rebutter getRebutted();
}

If I generate all (using the latest releases of eclipse and EMF) and implement the derived isAccepted() attribute in RebutterImpl with the following:
public boolean isAccepted() {
	return rebutter!=null ? !rebutter.isAccepted() : true;
}

Then I allow a chain of rebutter objects whose accepted flag depends on it's child chain.

I have a problem in the editor, though. I can't get updates to visibly bubble up the chain. Here's what I do:
I change the generated RebutterItemProvider to
1. show the accepted status of the rebutter by appending an "X"
2. update notifyChanged to signal a labelUpdate if the Rebutter changes
So, in the editor, if I add a rebutter to an existing rebutter, then it's label changes, but not it's parent (rebutted) rebutter.

I think the best crack I had at this was to change the generated RebutterImpl setRebutter method to pass a notification up the chain...
public void setRebutter(Rebutter newRebutter) {
	if (newRebutter != rebutter) {
		boolean oldAccepted = this.isAccepted();
...
		// notify rebutted that this object's accepted flag may have changed
		this.getRebutted().eNotify(new ENotificationImpl(this, Notification.SET, DecisionPackage.REBUTTER__ACCEPTED, oldAccepted, this.isAccepted()));
	}
...
}

but this didnt work and maybe doesnt quite smell right. Any pointers in the right direction would be most appreciated.

Matt
Re: recursive notification to parent question [message #499361 is a reply to message #499360] Sat, 21 November 2009 12:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Matt,

Comments below.

Matt South wrote:
> I have a fairly simple EMF class, Rebutter, whose java annotations
> consist of the following:
> /**
> * @model
> */
> public interface Rebutter {
> /**
> * @model containment="true" max=1 opposite="rebutted"
> */
> Rebutter getRebutter();
>
> /**
> * @model changeable="false" transient="true" derived="true"
> volatile="true"
> */
> boolean isAccepted();
>
> /**
> * @model changeable="false" opposite="rebutter"
> */
> Rebutter getRebutted();
> }
> If I generate all (using the latest releases of eclipse and EMF) and
> implement the derived isAccepted() attribute in RebutterImpl with the
> following:
> public boolean isAccepted() {
> return rebutter!=null ? !rebutter.isAccepted() : true;
It's the same as return rebutter == null || !rebutter.isAccepted()
> }
> Then I allow a chain of rebutter objects whose accepted flag depends
> on it's child chain.
> I have a problem in the editor, though. I can't get updates to
> visibly bubble up the chain. Here's what I do:
> I change the generated RebutterItemProvider to 1. show the accepted
> status of the rebutter by appending an "X"
> 2. update notifyChanged to signal a labelUpdate if the Rebutter changes
> So, in the editor, if I add a rebutter to an existing rebutter, then
> it's label changes, but not it's parent (rebutted) rebutter.
>
> I think the best crack I had at this was to change the generated
> RebutterImpl setRebutter method to pass a notification up the chain...
You might solve it at the item provider level as well by synthesizing
firing viewer notifications up the container chain.
>
> public void setRebutter(Rebutter newRebutter) {
> if (newRebutter != rebutter) {
> boolean oldAccepted = this.isAccepted();
> ..
> // notify rebutted that this object's accepted flag may have
> changed
> this.getRebutted().eNotify(new ENotificationImpl(this,
> Notification.SET, DecisionPackage.REBUTTER__ACCEPTED, oldAccepted,
> this.isAccepted()));
You've already established there is a rebutter so calling the getter
here seems not necessary. And isn't it the newRebutter's accepted state
that you should be taking into account? Do you want "touch"
notifications if the accepted state doesn't really change?
> }
> ..
> }
> but this didnt work and maybe doesnt quite smell right.
You might want to use the setRebutterGen "pattern" to avoid changing the
base method... Maybe it didn't work because it's always a touch
notification and I don't see a recursive traversal walking up the
container chain. Isn't that needed?
> Any pointers in the right direction would be most appreciated.
>
> Matt
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: recursive notification to parent question [message #499426 is a reply to message #499361] Sun, 22 November 2009 13:10 Go to previous messageGo to next message
Matt South is currently offline Matt SouthFriend
Messages: 5
Registered: November 2009
Junior Member
Thanks Ed, your suggestion for the isAccepted implementation is cleaner, cheers.

One issue with my example model is the similarity in names between the attributes rebutter and rebutted - did you spot that? In my example I try and use rebutted to pass the message up the chain.

Quote:
You might solve it at the item provider level as well by synthesizing
firing viewer notifications up the container chain.


Can you sketch a way to do this? I guess I should be sending an additional notification (in RebutterItemProvider.notifyChanges()?) but my understanding of EMF isnt mature enough to grasp this.

thanks again,

Matt
Re: recursive notification to parent question [message #499449 is a reply to message #499426] Sun, 22 November 2009 17:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Matt,

Comments below.

Matt South wrote:
> Thanks Ed, your suggestion for the isAccepted implementation is
> cleaner, cheers.
>
> One issue with my example model is the similarity in names between the
> attributes rebutter and rebutted - did you spot that?
Easy to make a typo. :-P
> In my example I try and use rebutted to pass the message up the chain.
>
> Quote:
>> You might solve it at the item provider level as well by synthesizing
>> firing viewer notifications up the container chain.
>
>
> Can you sketch a way to do this?
EGenericTypeItemProvider in org.eclipse.emf.ecore.edit does something
similar. It seems in your case better to do it in the model though as
you were trying...
> I guess I should be sending an additional notification (in
> RebutterItemProvider.notifyChanges()?) but my understanding of EMF
> isnt mature enough to grasp this.
>
> thanks again,
>
> Matt


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: recursive notification to parent question [message #499455 is a reply to message #499426] Sun, 22 November 2009 18:15 Go to previous message
Matt South is currently offline Matt SouthFriend
Messages: 5
Registered: November 2009
Junior Member
Hi Ed,

I've added a method to the RebutterImpl class:
private void notifyAcceptedUpdate(boolean oldValue, boolean newValue) {
	if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, DecisionPackage.REBUTTER__ACCEPTED, oldValue, newValue));
	if (getRebutted()!=null) ((RebutterImpl) getRebutted()).notifyAcceptedUpdate(!oldValue, !newValue);
}

And altered my update of the generated setRebutter to use this new method:
public void setRebutter(Rebutter newRebutter) {
	if (newRebutter != rebutter) {
		boolean oldAccepted = this.isAccepted();
...
		// check for change of accepted flag
		if (oldAccepted != isAccepted()) notifyAcceptedUpdate(oldAccepted, isAccepted());
	}
...
}

Now the updates do get bubbled up in the editor and I'm unstuck. Thanks for your continued help!

Matt

Previous Topic:[net4j] ClassNotFoundException when transferring instances of custom serializable class
Next Topic:[Validation] Questions regarding MultiStatus and MarkerUtil
Goto Forum:
  


Current Time: Fri Apr 26 11:40:18 GMT 2024

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

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

Back to the top