Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Set field value problem
Set field value problem [message #1701688] Wed, 15 July 2015 04:04 Go to next message
Shin-Yi Lin is currently offline Shin-Yi LinFriend
Messages: 34
Registered: June 2015
Member
Hi All,

I want to set a field value of a class. I do this in the way of modifying codes in getText() method in XXXItemProvider.java as the red frame in the following picture.
index.php/fa/22506/0/

It generates the following problem
index.php/fa/22505/0/

But, if I remove the codes, "(NFRSoftgoal)object.setLabel......", it becomes normal.

Can anyone help me solve the problem?

Thanks & Regards,




[Updated on: Wed, 15 July 2015 04:06]

Report message to a moderator

Re: Set field value problem [message #1701770 is a reply to message #1701688] Wed, 15 July 2015 13:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30541
Registered: July 2009
Senior Member
Comments below.

On 15/07/2015 6:04 AM, Shin-Yi Lin wrote:
> Hi All,
>
> I want to set a field value of a class. I do this in the way of modifying codes in getText() method in XXXItemProvider.java as the red frame in the following picture.
Modifying an instance's state in an item provider's getText method is
not appropriate. Such methods should be side-effect free. State
changes to the model should happen only in commands.
>
>
> It generates the following problem
>
>
>
> However, the representation diagram is normal.
> Can anyone help me solve the problem?
>
> Thanks & Regards,
>
>
>
>
>
Re: Set field value problem [message #1701783 is a reply to message #1701770] Wed, 15 July 2015 14:49 Go to previous messageGo to next message
Shin-Yi Lin is currently offline Shin-Yi LinFriend
Messages: 34
Registered: June 2015
Member
So, where can I change the an instance's state without going through commands?
I want to change its state automatically when field values of its children change.
Could you give me some suggestions? Thank you.
Re: Set field value problem [message #1701788 is a reply to message #1701783] Wed, 15 July 2015 15:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30541
Registered: July 2009
Senior Member
It must be done with commands. But I know nothing about your model
structure and what exactly you're trying to achieve. It sounds like you
want a derived feature that's always computed based on the values of
other things in the model. Most likely such a feature should be
transient as well.

On 15/07/2015 4:49 PM, Shin-Yi Lin wrote:
> So, where can I change the an instance's state without going through
> commands? I want to change its state automatically when field values
> of its children change. Could you give me some suggestions? Thank you.
>
Re: Set field value problem [message #1701944 is a reply to message #1701788] Fri, 17 July 2015 02:40 Go to previous messageGo to next message
Shin-Yi Lin is currently offline Shin-Yi LinFriend
Messages: 34
Registered: June 2015
Member
(1) My model structure (I want to change label attribute.):
index.php/fa/22547/0/

(2.1) Before (Child and parent clouds are undecided. Cloud represents NFRSoftgoal class.):
index.php/fa/22548/0/

(2.2) After (After child cloud changes to satisfy through command, parent cloud changes to satisfy automatically.)
index.php/fa/22549/0/
  • Attachment: q1.jpg
    (Size: 27.83KB, Downloaded 167 times)
  • Attachment: q2.jpg
    (Size: 4.19KB, Downloaded 199 times)
  • Attachment: q3.jpg
    (Size: 4.59KB, Downloaded 165 times)
Re: Set field value problem [message #1702009 is a reply to message #1701944] Fri, 17 July 2015 12:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30541
Registered: July 2009
Senior Member
Comments below.

On 17/07/2015 4:40 AM, Shin-Yi Lin wrote:
> (1) My model structure (I want to change label attribute.):
So the label feature is on a class that's the root of a several other
classes...
>
>
> (2.1) Before (Child and parent clouds are undecided. Cloud represents NFRSoftgoal class.):
This undecided thing is the default state...
>
>
> (2.2) After (After child cloud changes to satisfy through command, parent cloud changes to satisfy automatically.)
Is this via a command that directly modifies the label feature of the
"child"? If so, that's the place to modify the state of the parents,
e.g., using a compound command that modifies the child as normal, and
walks up the parents to modify the parent label also using commands.
What, if anything, prevents the "parent" label from being directly
changed back to undecided (which is perhaps an inconsistent state for
the model)?
>
Re: Set field value problem [message #1702033 is a reply to message #1702009] Fri, 17 July 2015 17:19 Go to previous messageGo to next message
Shin-Yi Lin is currently offline Shin-Yi LinFriend
Messages: 34
Registered: June 2015
Member
Ed Merks wrote on Fri, 17 July 2015 12:28
Comments below.

On 17/07/2015 4:40 AM, Shin-Yi Lin wrote:
> (1) My model structure (I want to change label attribute.):
So the label feature is on a class that's the root of a several other
classes...
----> Yes.
>
>
> (2.1) Before (Child and parent clouds are undecided. Cloud represents NFRSoftgoal class.):
This undecided thing is the default state...
-----> That's right.
>
>
> (2.2) After (After child cloud changes to satisfy through command, parent cloud changes to satisfy automatically.)
Is this via a command that directly modifies the label feature of the
"child"? If so, that's the place to modify the state of the parents,
e.g., using a compound command that modifies the child as normal, and
walks up the parents to modify the parent label also using commands.
What, if anything, prevents the "parent" label from being directly
changed back to undecided (which is perhaps an inconsistent state for
the model)?
-----> I change the label feature of "child" through the red frame in the following pictures (This is under run-time application and Sirius environment.):
index.php/fa/22556/0/

-----> But I don't want to change the label feature of "parent" through the same way, because it should be automatically changed, not manually.
That's why I modified the code of getText( Object object) function in NFRSoftgoalItemProvide.java under bpmn.edit.
index.php/fa/22557/0/


-----> What do you mean "via a command" ? I don't know how to change via a command. Could you explain or give any reference for it?

Thanks & Regards,

>
  • Attachment: t1.jpg
    (Size: 63.19KB, Downloaded 150 times)
  • Attachment: t2.jpg
    (Size: 75.19KB, Downloaded 145 times)
Re: Set field value problem [message #1702051 is a reply to message #1702033] Fri, 17 July 2015 23:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30541
Registered: July 2009
Senior Member
Comments below.

On 17/07/2015 7:19 PM, Shin-Yi Lin wrote:
> Ed Merks wrote on Fri, 17 July 2015 12:28
>> Comments below.
>>
>> On 17/07/2015 4:40 AM, Shin-Yi Lin wrote:
>>> (1) My model structure (I want to change label attribute.):
>> So the label feature is on a class that's the root of a several other
>> classes...
>> ----> Yes.
>>>
>>> (2.1) Before (Child and parent clouds are undecided. Cloud represents NFRSoftgoal class.):
>> This undecided thing is the default state...
>> -----> That's right.
>>>
>>> (2.2) After (After child cloud changes to satisfy through command, parent cloud changes to satisfy automatically.)
>> Is this via a command that directly modifies the label feature of the
>> "child"? If so, that's the place to modify the state of the parents,
>> e.g., using a compound command that modifies the child as normal, and
>> walks up the parents to modify the parent label also using commands.
>> What, if anything, prevents the "parent" label from being directly
>> changed back to undecided (which is perhaps an inconsistent state for
>> the model)?
>> -----> I change the label feature of "child" through the red frame in the following pictures (This is under run-time application and Sirius environment.):
>>
>>
>> -----> But I don't want to change the label feature of "parent" through the same way, because it should be automatically changed, not manually.
I'm asking what's preventing that from happening? I suppose it doesn't
matter if you've done something so that only a leaf/child can be
directly modified.
>> That's why I modified the code of getText( Object object) function in NFRSoftgoalItemProvide.java under bpmn.edit.
That's not a good idea.
>>
>>
>>
>> -----> What do you mean "via a command" ? I don't know how to change via a command. Could you explain or give any reference for it?
On the child, the set command is created by
org.eclipse.emf.edit.provider.ItemProviderAdapter.createSetCommand(EditingDomain,
EObject, EStructuralFeature, Object) so you can specialize this method
of the child's item provider so that it modifies not only the child's
label feature, but modifies also the parents. All that could be done
with a CompoundCommand that composes all the SetCommands.
>>
>> Thanks & Regards,
>>
Re: Set field value problem [message #1702235 is a reply to message #1702051] Mon, 20 July 2015 22:09 Go to previous messageGo to next message
Shin-Yi Lin is currently offline Shin-Yi LinFriend
Messages: 34
Registered: June 2015
Member
I do want to prevent modifying parent's attribute value after child label going up.


I saw the example of using createSetCommand in EMF book.
createSetCommand is added in the **ItemProvider.java
index.php/fa/22582/0/

But which package should SetPriceCommand and SetQuantityCommand been added into? Is it **.provider package in **.edit?
index.php/fa/22583/0/

Thank you.
  • Attachment: q8.jpg
    (Size: 123.49KB, Downloaded 126 times)
  • Attachment: q9.jpg
    (Size: 152.91KB, Downloaded 128 times)
Re: Set field value problem [message #1702242 is a reply to message #1702235] Tue, 21 July 2015 00:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30541
Registered: July 2009
Senior Member
You should learn some debugging techniques to answer questions like this
yourself. For example, set a breakpoint in the setLabel method. See
when it gets called when you change the child's label. You'll discover
it's in the SetCommand. Then set a breakpoint in the constructor and
you'll see when that command is created. You'll see which
XyzItemProvider is doing that; well it will be in the base
ItemProviderAdapter, but in the debugger you'll see which derived class
is involved. That's where you can specialize the method.

In other words, use the debugger to find your answers. I often work
with frameworks where no one will answer my questions and I still need
to figure out how they work and how I can specialize how the work...

On 21/07/2015 12:09 AM, Shin-Yi Lin wrote:
> I do want to prevent modifying parent's attribute value after child label going up.
>
>
> I saw the example of using createSetCommand in EMF book.
> createSetCommand is added in the **ItemProvider.java
>
>
> But which package should SetPriceCommand and SetQuantityCommand been added into? Is it **.provider package in **.edit?
>
>
> Thank you.
Re: Set field value problem [message #1702343 is a reply to message #1702242] Tue, 21 July 2015 16:00 Go to previous messageGo to next message
Shin-Yi Lin is currently offline Shin-Yi LinFriend
Messages: 34
Registered: June 2015
Member
Thanks for your suggestion.

I've set the breakpoint at setLabel method before you mentioned. It's not in the SetCommand; rather, it is in the PhenomenonTypeImp.java. In addition, SetCommand is actually in org.eclipse.emf.edit.command.SetCommand. From the EMF book, setPrice and setQuantity which extend SetCommand are classes, which means I should create a class java file for them. This really confused me.
------> From your suggestion. I guess I should specialize the setLabel method and extends from SetCommand in PhenomenonTypeImp.java.

By the way, during debugging, it showed some errors of "the source attachment does not contain the source for the file SessionLabelProvider and SiriusCommonLabelProvider". They're under org.eclipse.sirius.ui.tools.internal.views.common and compiler can't not find the lines of code it needs.

Re: Set field value problem [message #1702360 is a reply to message #1702343] Tue, 21 July 2015 18:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30541
Registered: July 2009
Senior Member
Comments below.

On 21/07/2015 6:00 PM, Shin-Yi Lin wrote:
> Thanks for your suggestion.
>
> I've set the breakpoint at setLabel method before you mentioned. It's
> not in the SetCommand; rather, it is in the PhenomenonTypeImp.java.
Yes, the set methods are in the implementation classes. The point is to
set a breakpoint and look at the call stack to see who is calling it.
> In addition, SetCommand is actually in
> org.eclipse.emf.edit.command.SetCommand.
Indeed. Do you know that Ctrl-Shift-T will let you find any class easily.
> From the EMF book, setPrice and setQuantity which extend SetCommand
> are classes, which means I should create a class java file for them.
> This really confused me. ------> From your suggestion. I guess I
> should specialize the setLabel method and extends from SetCommand in
> PhenomenonTypeImp.java.
No, I was quite specific about specializing your generated item provider.
>
> By the way, during debugging, it showed some errors of "the source
> attachment does not contain the source for the file
> SessionLabelProvider and SiriusCommonLabelProvider". They're under
> org.eclipse.sirius.ui.tools.internal.views.common and compiler can't
> not find the lines of code it needs.
That's a Sirius question; perhaps their build is not configured properly.

In the end, you need to learn to help yourself, because I won't be
answering every question of yours down to the last minute detail. This
thread will just continue forever.
>
>
Previous Topic:Copy EObject between resources with saving id
Next Topic:CDO - What happened to the Couchbase IStore implementation?
Goto Forum:
  


Current Time: Mon Oct 14 16:39:19 GMT 2019

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

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

Back to the top