[Newbie] Default values, derived, changeable, transient, volatile [message #177475] |
Sat, 15 March 2008 19:05 |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.01866 seconds