How to get node ot non contaiment feauture [message #56767] |
Thu, 28 September 2006 08:36 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: ayalandzhiev.sbnd.net
Hello, I have a problem to get Node of non containment feature for
example : I have a EObject A which reference to EObject B and NodeImpl
for A and I need a NodeImpl for B.
Regards, Atanas.
|
|
|
Re: How to get node ot non contaiment feauture [message #57135 is a reply to message #56767] |
Thu, 28 September 2006 13:26 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: john.watson.yahoo.com
Hi,
I think you cannot or cannot easily.
You have
AImpl <-----------------------------------> BImpl
/\ /\
| |
| |
| |
Node Node
From Node you can get AImpl and BImpl, but from BImpl you cannot get Node
(the link is from Node to BImpl).
You can do something like that:
Hashtable allWidgets = new Hashtable;
TreeIterator treeIt = (DiagramImpl).eAllContents();
while (treeIt.hasNext()) {
Object obj = treeIt.next();
if (!(obj instanceof NodeImpl))
continue;
NodeImpl node = (NodeImpl) obj;
EObject parent = node.eContainer();
if (node.getElement() == null)
continue;
if (parent instanceof DiagramImpl) {
allWidgets.put(node.getElement(), node);
continue;
}
if (!(parent instanceof NodeImpl))
continue;
NodeImpl parentNode = (NodeImpl) parent;
if (parentNode.getElement() != node.getElement())
allWidgets.put(node.getElement(), node);
}
and after that when you get BImpl you can get corresponding Node from the
Hashtable.
NOTE: My figures are main rectangle and label inside it. There are tho
nodes one for main rectangle and one for label. And both of nodes point to
the same EObject. To solve that problem I check if the EObject of parent
Node is the same as the EObject of current Node. But I'm not sure if the
it will work with complex figures as the figure from GMF Tutorial 3
HTH,
|
|
|
Re: How to get node ot non contaiment feauture [message #57162 is a reply to message #57135] |
Thu, 28 September 2006 13:35 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: merks.ca.ibm.com
John,
There should typically never be a need to refer to XyzImpl classes in
client code except as a base class for something that extends XyzImpl.
Everywhere else you should always use the API, i.e., the Xyz interface
itself. This is particularly important for models that have multiple
inheritance because classes only support single inheritance so not all
implementers of Xyz will necessarily extend XyzImpl. Sometimes an
EcoreUtil.UsageCrossReferencer can be very helpful for looking up
inverses of unidirectional references. Similarly,
ECrossReferenceAdapter can be attached to a ResourceSet, Resource, or
EObject and will dynamically keep track of inverses for all
unidirectional references. I'm not sure if either of these would be
useful for this scenario...
John Watson wrote:
> Hi,
>
> I think you cannot or cannot easily.
> You have
>
> AImpl <-----------------------------------> BImpl
> /\ /\
> | |
> | |
> | |
> Node Node
>
> From Node you can get AImpl and BImpl, but from BImpl you cannot get
> Node (the link is from Node to BImpl).
>
> You can do something like that:
>
> Hashtable allWidgets = new Hashtable;
> TreeIterator treeIt = (DiagramImpl).eAllContents();
> while (treeIt.hasNext()) {
> Object obj = treeIt.next();
> if (!(obj instanceof NodeImpl))
> continue;
> NodeImpl node = (NodeImpl) obj;
> EObject parent = node.eContainer();
> if (node.getElement() == null)
> continue;
> if (parent instanceof DiagramImpl) {
> allWidgets.put(node.getElement(), node);
> continue;
> }
> if (!(parent instanceof NodeImpl))
> continue;
> NodeImpl parentNode = (NodeImpl) parent;
> if (parentNode.getElement() != node.getElement())
> allWidgets.put(node.getElement(), node);
> }
>
> and after that when you get BImpl you can get corresponding Node from
> the Hashtable.
>
> NOTE: My figures are main rectangle and label inside it. There are tho
> nodes one for main rectangle and one for label. And both of nodes
> point to the same EObject. To solve that problem I check if the
> EObject of parent Node is the same as the EObject of current Node. But
> I'm not sure if the it will work with complex figures as the figure
> from GMF Tutorial 3
>
> HTH,
>
|
|
|
Powered by
FUDForum. Page generated in 0.03511 seconds