Home » Modeling » GMF (Graphical Modeling Framework) » How Can I Get the Value of An Attribute by Code
| | |
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 |
Ed Merks 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 |
vincent988923 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 |
Ed Merks 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/
|
|
|
Goto Forum:
Current Time: Wed Apr 24 23:37:20 GMT 2024
Powered by FUDForum. Page generated in 0.02427 seconds
|