Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Newbie] Default values, derived, changeable, transient, volatile
[Newbie] Default values, derived, changeable, transient, volatile [message #417585] Sat, 15 March 2008 19:05 Go to next message
Eclipse UserFriend
Originally posted by: manja.wolf.web.de

Hi,

my question is something that has been frequently discussed in this
newsgroup. However, I didn't find the answer to my problem so far.
Because I'm not sure whether it is a GMF or EMF-question I post it twice.

The task:
I develop a GMF-Editor for creation of special nets. Therefore I defined
an ecore-model with two different kinds of nets (e.g. net A is from one
kind, net B from the other). In these nets, there may be nodes (e.g.
node X, node Y). The nodes have attributes. I need to set some of these
attributes subject to the parent net (the net they are contained in). If
e.g. node X is moved (may be per drag&drop) from net A to net B, the
value of the attribute of node X should be set back to a default value
specific for net B. But otherwise the attribute should be changeable.
Do you have any suggestion to solve this problem?

What I have done until now:
I defined additional attributes newParentNet and oldParentNet which
should hold the information whether a node moved and in which eContainer
it is contained.

Desirably the attributes would be unchangeable, but not transient and
volatile. This way I can mark which was the old parentNet and which the
new. I 've read, that this concept isn't possible in EMF. Here a
code-snipped from NodeImpl.java:
************************************************************ ***********
public String getNewParentNet() {
if(this.eContainer instanceof MainProcess) {
if(newParentNet != ParentNet.MAIN_PROCESS.getLiteral()) {
//temp = Temp.COLD;
oldParentNet = newParentNet;
}
newParentNet = ParentNet.MAIN_PROCESS.getLiteral();
} else if(this.eContainer instanceof PreNet) {
if(newParentNet != ParentNet.PRE_NET.getLiteral()) oldParentNet =
newParentNet;
newParentNet = ParentNet.PRE_NET.getLiteral();
//temp = Temp.WITHOUT;
} else if(this.eContainer instanceof DoNet) {
if(newParentNet != ParentNet.DO_NET.getLiteral()) {
//if(!isAbstract()) temp = Temp.COLD;
oldParentNet = newParentNet;
}
newParentNet = ParentNet.DO_NET.getLiteral();
//if(isAbstract()) temp= Temp.WITHOUT;
} else {
System.out.println("something different. shoudn't occur.");
newParentNet = "";
}
return newParentNet;
}
************************************************************ ****
In this case newParentNet is unchangeable, but not transient nor
volatile. As you can easily see, it doesn't work. Upon saving, I get an
exception that newParentNet shouldn't be set to the new value. I
understood from other postings that this isn't a possible way to do it.
As you can see in the code snipped I would like to set the values of the
depending attributes in this method (or even in the getter of the
attribute e.g. temp in this case).

I tried as well to set the attributes newParentNet, oldParentNet to
changeable and not volatile ... (the default values) and defined the
EAnnotations suppressedSetVisibility, suppressedGetVisibility,
suppressedIsSetVisibility, suppressedUnsetVisibility as suggested. It
removed the setter and getter from the interface as described. But when
I run the application and build a net with a node, I can change the
attibute in the properties-view. I assumed that this wouldn't be
possible. Which behavior is suppressed?

Is there another way to solve it -- maybe an eAttribute like eContainer,
where I can see that a node moved to another parent net and from where
to where?

How can I solve the problem that I have attributes on nodes which should
have default values depending on the parent net (eContainer) but should
be changeable.

Sorry about this long explanation. I hope you can help me.

Thanks a lot, Manja
Re: [Newbie] Default values, derived, changeable, transient, volatile [message #417588 is a reply to message #417585] Sat, 15 March 2008 19:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Manja,

Don't post it twice, post it once and address both newsgroups at the
same time, as I've done with the reply. More comments below.

Manja wrote:
> Hi,
>
> my question is something that has been frequently discussed in this
> newsgroup. However, I didn't find the answer to my problem so far.
> Because I'm not sure whether it is a GMF or EMF-question I post it twice.
>
> The task:
> I develop a GMF-Editor for creation of special nets. Therefore I
> defined an ecore-model with two different kinds of nets (e.g. net A is
> from one kind, net B from the other). In these nets, there may be
> nodes (e.g. node X, node Y). The nodes have attributes. I need to set
> some of these attributes subject to the parent net (the net they are
> contained in). If e.g. node X is moved (may be per drag&drop) from net
> A to net B, the value of the attribute of node X should be set back
> to a default value specific for net B. But otherwise the attribute
> should be changeable.
> Do you have any suggestion to solve this problem?
Should the value just be derived via a computation?
>
> What I have done until now:
> I defined additional attributes newParentNet and oldParentNet which
> should hold the information whether a node moved and in which
> eContainer it is contained.
>
> Desirably the attributes would be unchangeable, but not transient and
> volatile.
That means you want to serialize it, which means you want it to change
when you read in the instance. It also implies you want to change it
when copying...
> This way I can mark which was the old parentNet and which the new. I
> 've read, that this concept isn't possible in EMF. Here a
> code-snipped from NodeImpl.java:
> ************************************************************ ***********
> public String getNewParentNet() {
> if(this.eContainer instanceof MainProcess) {
> if(newParentNet != ParentNet.MAIN_PROCESS.getLiteral()) {
> //temp = Temp.COLD;
> oldParentNet = newParentNet;
> }
> newParentNet = ParentNet.MAIN_PROCESS.getLiteral();
> } else if(this.eContainer instanceof PreNet) {
> if(newParentNet != ParentNet.PRE_NET.getLiteral())
> oldParentNet = newParentNet;
> newParentNet = ParentNet.PRE_NET.getLiteral();
> //temp = Temp.WITHOUT;
> } else if(this.eContainer instanceof DoNet) {
> if(newParentNet != ParentNet.DO_NET.getLiteral()) {
> //if(!isAbstract()) temp = Temp.COLD;
> oldParentNet = newParentNet;
> }
> newParentNet = ParentNet.DO_NET.getLiteral();
> //if(isAbstract()) temp= Temp.WITHOUT;
> } else {
> System.out.println("something different. shoudn't occur.");
> newParentNet = "";
> }
> return newParentNet;
> }
> ************************************************************ ****
> In this case newParentNet is unchangeable, but not transient nor
> volatile. As you can easily see, it doesn't work. Upon saving, I get
> an exception that newParentNet shouldn't be set to the new value. I
> understood from other postings that this isn't a possible way to do it.
> As you can see in the code snipped I would like to set the values of
> the depending attributes in this method (or even in the getter of the
> attribute e.g. temp in this case).
You could monitor changes to your parent by specializing
eBasicSetContainer. Or you could define a container feature, and
monitor when the basic method to set the container is called.
>
> I tried as well to set the attributes newParentNet, oldParentNet to
> changeable and not volatile ... (the default values) and defined the
> EAnnotations suppressedSetVisibility, suppressedGetVisibility,
> suppressedIsSetVisibility, suppressedUnsetVisibility as suggested. It
> removed the setter and getter from the interface as described. But
> when I run the application and build a net with a node, I can change
> the attibute in the properties-view. I assumed that this wouldn't be
> possible. Which behavior is suppressed?
>
> Is there another way to solve it -- maybe an eAttribute like
> eContainer, where I can see that a node moved to another parent net
> and from where to where?
>
> How can I solve the problem that I have attributes on nodes which
> should have default values depending on the parent net (eContainer)
> but should be changeable.
Here's an example from EClassifierImpl where we do a bit of processing
in if the container changes...

@Override
protected void eBasicSetContainer(InternalEObject newContainer, int
newContainerFeatureID)
{
// Ensure that cached ePackage is forgotten.
ePackage = null;
super.eBasicSetContainer(newContainer, newContainerFeatureID);
}

>
> Sorry about this long explanation. I hope you can help me.
>
> Thanks a lot, Manja


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Newbie] Default values, derived, changeable, transient, volatile [message #417595 is a reply to message #417588] Sun, 16 March 2008 19:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: manja.wolf.web.de

Ed,

thanks a lot for your recommendation to specialize eBasicSetContainer.
It works fine.

Could you please tell me something about EAnnotations
suppressedSetVisibility, suppressedGetVisibility,
suppressedIsSetVisibility, suppressedUnsetVisibility? Which behavior is
suppressed? The getter and setter are removed from interface. But if I
run the application then I can change these attributes in properties
view. Where is it suppressed? Only in the graphical canvas (when I
define labels on nodes)?

Manja
Re: [Newbie] Default values, derived, changeable, transient, volatile [message #417596 is a reply to message #417595] Mon, 17 March 2008 01:11 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Manja,

These annotations only affect the accessors generated in the generated
public interface. Suppression has not impact on whether you can
reflectively access or modify the feature.


Manja wrote:
> Ed,
>
> thanks a lot for your recommendation to specialize eBasicSetContainer.
> It works fine.
>
> Could you please tell me something about EAnnotations
> suppressedSetVisibility, suppressedGetVisibility,
> suppressedIsSetVisibility, suppressedUnsetVisibility? Which behavior
> is suppressed? The getter and setter are removed from interface. But
> if I run the application then I can change these attributes in
> properties view. Where is it suppressed? Only in the graphical canvas
> (when I define labels on nodes)?
>
> Manja


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Unsettable derived attributes
Next Topic:Exception is not handled by the provider classes of the generated Edit plugin
Goto Forum:
  


Current Time: Thu Apr 25 23:29:41 GMT 2024

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

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

Back to the top