Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How Can I Get the Value of An Attribute by Code
How Can I Get the Value of An Attribute by Code [message #689905] Tue, 28 June 2011 15:12 Go to next message
vincent988923 is currently offline vincent988923Friend
Messages: 29
Registered: June 2011
Junior Member
Hi, Everyone. I have a problem about getting the value of an attribute of a Node. Right now I have added a new attribute in my model after generating the code. I want to detect the change of the new value so that something will be changed accordingly. In my opinion, I should override the protected void handleNotificationEvent(Notification event) function. But how can I tell whether or not it has been changed in the XXXEditPart.java file. In another word, how can I get the old value and the new value of my new attribute in the function?

Big Thanks! Razz
Re: How Can I Get the Value of An Attribute by Code [message #689966 is a reply to message #689905] Tue, 28 June 2011 16:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Given that Notification has getOldValue and getNewValue, this question
seems to answer itself...


On 28/06/2011 8:12 AM, forums-noreply@eclipse.org wrote:
> Hi, Everyone. I have a problem about getting the value of an attribute
> of a Node. Right now I have added a new attribute in my model after
> generating the code. I want to detect the change of the new value so
> that something will be changed accordingly. In my opinion, I should
> override the protected void handleNotificationEvent(Notification
> event) function. But how can I tell whether or not it has been changed
> in the XXXEditPart.java file. In another word, how can I get the old
> value and the new value of my new attribute in the function?
>
> Big Thanks! :p


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How Can I Get the Value of An Attribute by Code [message #689998 is a reply to message #689966] Tue, 28 June 2011 18:03 Go to previous messageGo to next message
vincent988923 is currently offline vincent988923Friend
Messages: 29
Registered: June 2011
Junior Member
Thanks. But in my model, the node TRANSITION has more than one attribute(Name, Priority, Tirer...). No matter what kind of attributes change, it will trigger handleNotificationEvent function.But I really need that the function will be executed only when Tirer is changed.

Therefore,

1.I should point out where the "change" source is from.
2.Then, I should get its old value and new value to continue.


So do you have any ideas?? Thank you!

Regards,

Vincent
Re: How Can I Get the Value of An Attribute by Code [message #690014 is a reply to message #689998] Tue, 28 June 2011 18:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Vincent,

Did you notice the getFeature method?


On 28/06/2011 11:03 AM, forums-noreply@eclipse.org wrote:
> Thanks. But in my model, the node TRANSITION has more than one
> attribute(Name, Priority, Tirer...). No matter what kind of attributes
> change, it will trigger handleNotificationEvent function.But I really
> need that the function will be executed only when Tirer is changed.
>
> Therefore,
> 1.I should point out where the "change" source is from.
Check the feature to see if it's the one you're interested in...
> 2.Then, I should get its old value and new value to continue.
Look at the values in the notification in that case.
> So do you have any ideas?? Thank you!
If you've set a breakpoint and looked at the notification details in the
values view, I'll bet you would have noticed all this information being
present...
>
> Regards,
>
> Vincent


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How Can I Get the Value of An Attribute by Code [message #690022 is a reply to message #690014] Tue, 28 June 2011 19:36 Go to previous messageGo to next message
vincent988923 is currently offline vincent988923Friend
Messages: 29
Registered: June 2011
Junior Member
Hi, thanks again. I figure out that notification can have the following attribute.
notification.getNotifier(),   
notification.getEventType(),   
notification.getFeature(),   
notification.getOldValue(),   
notification.getNewValue(),   
notification.getPosition());  

but I still don't know how to solve it. Actually, I added attribute Tirer by myself in the XXX.src.rdp.impl.TransitionImp.java
protected static int tirer = 0;
	
	public int getTirer() {
		return this.tirer;
	}

public void setTirer(int newTirer) {
		int oldTirer = this.tirer;
		if(this.tirer == newTirer)
		{
			return;
		}
		this.tirer = newTirer;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, RdpPackage.TRANSITION__TIRER, oldTirer, newTirer));
	}

Actually, I have tried some solutions as follows, but i can't make it.
protected void handleNotificationEvent(Notification event)
	{
		super.handleNotificationEvent(event);
		//Object feature = event.getFeature();
		//if(NotationPackage.eINSTANCE.getPropertyValue().)
		//if(event.getNotifier() instanceof TransitionEditPart))
		//if((View)TransitionEditPart.getModel)
		//getPrimaryShape().
		//event.getFeatureID(getClass());
		//EventPackage.
		//event.getNotifier().equals(obj)
		System.out.println("Change the Color when it's TIRER"+event);
		
		if(event.getNotifier() instanceof TransitionEditPart)
		{
			System.out.println("Transition");
			if(event.getFeature() instanceof EAttribute)
			{
				System.out.println("Ettribute");
				String Tirer = ((EAttribute)event.getFeature()).getName();
				System.out.println("****"+Tirer);
			}
		}
		int oldTirer = this.tirer;
		int newTirer = 1;
		if(oldTirer != newTirer)
		{
			this.tirer = newTirer;
			this.ChangeColor();
		}
		
		}

I hope that every time when the value of Tirer is changed, it will trigger the handleNotificationEvent. Can you tell me exactly how I can write in the function? Thank you very much.

best regards,
Vincent

[Updated on: Tue, 28 June 2011 19:37]

Report message to a moderator

Re: How Can I Get the Value of An Attribute by Code [message #690089 is a reply to message #690022] Wed, 29 June 2011 00:34 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Vincent,

Comments below.

On 28/06/2011 12:36 PM, forums-noreply@eclipse.org wrote:
> Hi, thanks again. I figure out that notification can have the
> following attribute.
> notification.getNotifier(), notification.getEventType(),
> notification.getFeature(), notification.getOldValue(),
> notification.getNewValue(), notification.getPosition()); but I
> still don't know how to solve it. Actually, I added attribute Tirer by
> myself in the XXX.src.rdp.impl.TransitionImp.java
By adding it yourself you mean it wasn't generated for you? That
doesn't make much sense to me. Setters with notification are normally
generated for you...
> public void setTirer(int newTirer) {
> int oldTirer = this.tirer;
> if(this.tirer == newTirer)
> {
> return;
> }
> this.tirer = newTirer;
> if (eNotificationRequired())
> eNotify(new ENotificationImpl(this, Notification.SET,
> RdpPackage.TRANSITION__TIRER, oldTirer, newTirer));
> }
>
> Actually, I have tried some solutions as follows, but i can't make it.
>
> protected void handleNotificationEvent(Notification event)
> {
> super.handleNotificationEvent(event);
So you've set breakpoints and you're really getter here?
> //Object feature = event.getFeature();
> //if(NotationPackage.eINSTANCE.getPropertyValue().)
> //if(event.getNotifier() instanceof TransitionEditPart))
The name TRANSITION__TIRER makes me think your interface would be called
Transition.
> //if((View)TransitionEditPart.getModel)
> //getPrimaryShape().
> //event.getFeatureID(getClass());
You'd pass in the class of the instance, not the class containing this
handleNotification method.
> //EventPackage.
> //event.getNotifier().equals(obj)
> System.out.println("Change the Color when it's TIRER"+event);
>
> if(event.getNotifier() instanceof TransitionEditPart)
As I said, I'd expect it to be a Transition not an edit part.
> {
> System.out.println("Transition");
I don't think you're consulting with the debugger. Unless you confirm
and given some indication you've figured out how to use the debugger, I
won't help you anymore.
> if(event.getFeature() instanceof EAttribute)
> {
> System.out.println("Ettribute");
> String Tirer =
> ((EAttribute)event.getFeature()).getName();
> System.out.println("****"+Tirer);
> }
> }
> int oldTirer = this.tirer;
> int newTirer = 1;
> if(oldTirer != newTirer)
> {
> this.tirer = newTirer;
> this.ChangeColor();
> }
>
> }
>
> I hope that every time when the value of Tirer is changed, it will
> trigger the handleNotificationEvent. Can you tell me exactly how I can
> write in the function?
No. That's not how life works. We help you help yourself but I'm not
convinced you've started up the debugger yet so I'm not interested in
helping you unless you learn to effectively use the tools you have at
your disposal.
> Thank you very much.
>
> best regards,
> Vincent


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Creating a view
Next Topic:Shorcuts disappear when close diagram
Goto Forum:
  


Current Time: Wed Apr 24 23:37:20 GMT 2024

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

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

Back to the top