Home » Modeling » EMF » How to observe obj.eContainer().name
How to observe obj.eContainer().name [message #686744] |
Fri, 13 May 2011 19:59 |
Eclipse User |
|
|
|
Originally posted by: Dongyue Mou
Hello,
I have a question for observing an attribute of an EObject's eContainer.
Basically, there are 3 classes in my model (here as pseudo code)
class Graph {
String name
Node[] nodes
Edge[] edges
}
class Node {
int id
Edge[] outgoings
Edge[] incomings
}
class Edge{
int weight
Node source
Edge target
}
In this model, if given a node N, I can access its Graph by calling
N.eContainer().
Now, I want to add a table into the GUI, which takes a list of edges and
showes all weights of the edges and the names of target node's Graphes. As
pseudo code, it looks like:
String LabelProvider.getText(Edge e, int col) {
if(col == 0)
return e.weight+ "";
else if(col == 1)
return e.target.eContainer().name;
}
This works fine, until I find that, if the name of Graph is changed
somewhere outside the table, the content of the table cannot be updated
automatically.
To fix this bug, I want to bind the table and the model together, which
looks like:
----------------------------------------------------------
IObservableList edges = EMFObserveables.observeList(.........);
IObservableMap[] attributeMap = new IObservableMap[] {
EMFObservables.observeMap(edges,
MyPackage.Literals.EDGE__WEIGHT),
EMFProperties.value(
FeaturePath.fromList(new EStructuralFeature[] {
MyPackage.Literals.EDGE__TARGET,
EcorePackage.Literals.EOBJECT__ECONTAINER, //
<---- Compiler error: EOBJECT__ECONTAINER is of type EOperator not
EStructuredFeature
MyPackage.Literals.GRAPH__NAME
}
).observeDetail(edges)
}
tableviewer.setLableProvider(new ObserveableMapLableProvider(attributeMap));
---------------------------------------------------------------
Since the eContainer() is an operation, it cannot be used in FeaturePath
structure. So this is my question:
How can I observe the name of the graph via the complex chain
Edge->target:Node->eContainer():Graph->name:String?
And thanks for read the whole boring story :-)
--
|
|
|
Re: How to observe obj.eContainer().name [message #686747 is a reply to message #686744] |
Fri, 13 May 2011 23:41 |
Ed Merks Messages: 33113 Registered: July 2009 |
Senior Member |
|
|
The path of least resistance would be to model an EReference.eOpposite
for both nodes and edges, i.e., a "graph" feature of type "Graph" in
each of Node and Edge.
Dongyue Mou wrote:
> Hello,
>
> I have a question for observing an attribute of an EObject's eContainer.
>
> Basically, there are 3 classes in my model (here as pseudo code)
>
> class Graph {
> String name
> Node[] nodes
> Edge[] edges
> }
>
> class Node {
> int id
> Edge[] outgoings
> Edge[] incomings
> }
>
> class Edge{
> int weight
> Node source
> Edge target
> }
>
> In this model, if given a node N, I can access its Graph by calling
> N.eContainer().
>
> Now, I want to add a table into the GUI, which takes a list of edges
> and showes all weights of the edges and the names of target node's
> Graphes. As pseudo code, it looks like:
>
> String LabelProvider.getText(Edge e, int col) {
> if(col == 0)
> return e.weight+ "";
> else if(col == 1)
> return e.target.eContainer().name;
> }
>
> This works fine, until I find that, if the name of Graph is changed
> somewhere outside the table, the content of the table cannot be
> updated automatically.
>
> To fix this bug, I want to bind the table and the model together,
> which looks like:
>
> ----------------------------------------------------------
> IObservableList edges = EMFObserveables.observeList(.........);
>
> IObservableMap[] attributeMap = new IObservableMap[] {
> EMFObservables.observeMap(edges,
> MyPackage.Literals.EDGE__WEIGHT),
> EMFProperties.value(
> FeaturePath.fromList(new EStructuralFeature[] {
> MyPackage.Literals.EDGE__TARGET,
> EcorePackage.Literals.EOBJECT__ECONTAINER,
> // <---- Compiler error: EOBJECT__ECONTAINER is of type EOperator not
> EStructuredFeature
> MyPackage.Literals.GRAPH__NAME
> }
> ).observeDetail(edges)
> }
>
> tableviewer.setLableProvider(new
> ObserveableMapLableProvider(attributeMap));
> ---------------------------------------------------------------
>
> Since the eContainer() is an operation, it cannot be used in
> FeaturePath structure. So this is my question:
>
> How can I observe the name of the graph via the complex chain
> Edge->target:Node->eContainer():Graph->name:String?
>
> And thanks for read the whole boring story :-)
>
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to observe obj.eContainer().name [message #686780 is a reply to message #686747] |
Tue, 17 May 2011 22:14 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Ed is right you can't construct a model-path without explicitly modeling
the parent relationship as an opposite.
The reason for this is that there's no real feature for the parent
relationship. I have not yet investigated this problem but I'm quite
sure it can't be solved as of now so the only solution is to model it as
an eOpposite.
Tom
Am 14.05.11 01:41, schrieb Ed Merks:
> The path of least resistance would be to model an EReference.eOpposite
> for both nodes and edges, i.e., a "graph" feature of type "Graph" in
> each of Node and Edge.
>
> Dongyue Mou wrote:
>> Hello,
>>
>> I have a question for observing an attribute of an EObject's eContainer.
>>
>> Basically, there are 3 classes in my model (here as pseudo code)
>>
>> class Graph {
>> String name
>> Node[] nodes
>> Edge[] edges
>> }
>>
>> class Node {
>> int id
>> Edge[] outgoings
>> Edge[] incomings
>> }
>>
>> class Edge{
>> int weight
>> Node source
>> Edge target
>> }
>>
>> In this model, if given a node N, I can access its Graph by calling
>> N.eContainer().
>>
>> Now, I want to add a table into the GUI, which takes a list of edges
>> and showes all weights of the edges and the names of target node's
>> Graphes. As pseudo code, it looks like:
>>
>> String LabelProvider.getText(Edge e, int col) {
>> if(col == 0)
>> return e.weight+ "";
>> else if(col == 1)
>> return e.target.eContainer().name;
>> }
>>
>> This works fine, until I find that, if the name of Graph is changed
>> somewhere outside the table, the content of the table cannot be
>> updated automatically.
>>
>> To fix this bug, I want to bind the table and the model together,
>> which looks like:
>>
>> ----------------------------------------------------------
>> IObservableList edges = EMFObserveables.observeList(.........);
>>
>> IObservableMap[] attributeMap = new IObservableMap[] {
>> EMFObservables.observeMap(edges,
>> MyPackage.Literals.EDGE__WEIGHT),
>> EMFProperties.value(
>> FeaturePath.fromList(new EStructuralFeature[] {
>> MyPackage.Literals.EDGE__TARGET,
>> EcorePackage.Literals.EOBJECT__ECONTAINER,
>> // <---- Compiler error: EOBJECT__ECONTAINER is of type EOperator not
>> EStructuredFeature
>> MyPackage.Literals.GRAPH__NAME
>> }
>> ).observeDetail(edges)
>> }
>>
>> tableviewer.setLableProvider(new
>> ObserveableMapLableProvider(attributeMap));
>> ---------------------------------------------------------------
>>
>> Since the eContainer() is an operation, it cannot be used in
>> FeaturePath structure. So this is my question:
>>
>> How can I observe the name of the graph via the complex chain
>> Edge->target:Node->eContainer():Graph->name:String?
>>
>> And thanks for read the whole boring story :-)
>>
>>
>>
>>
|
|
|
Re: How to observe obj.eContainer().name [message #686906 is a reply to message #686744] |
Fri, 13 May 2011 23:41 |
Ed Merks Messages: 33113 Registered: July 2009 |
Senior Member |
|
|
The path of least resistance would be to model an EReference.eOpposite
for both nodes and edges, i.e., a "graph" feature of type "Graph" in
each of Node and Edge.
Dongyue Mou wrote:
> Hello,
>
> I have a question for observing an attribute of an EObject's eContainer.
>
> Basically, there are 3 classes in my model (here as pseudo code)
>
> class Graph {
> String name
> Node[] nodes
> Edge[] edges
> }
>
> class Node {
> int id
> Edge[] outgoings
> Edge[] incomings
> }
>
> class Edge{
> int weight
> Node source
> Edge target
> }
>
> In this model, if given a node N, I can access its Graph by calling
> N.eContainer().
>
> Now, I want to add a table into the GUI, which takes a list of edges
> and showes all weights of the edges and the names of target node's
> Graphes. As pseudo code, it looks like:
>
> String LabelProvider.getText(Edge e, int col) {
> if(col == 0)
> return e.weight+ "";
> else if(col == 1)
> return e.target.eContainer().name;
> }
>
> This works fine, until I find that, if the name of Graph is changed
> somewhere outside the table, the content of the table cannot be
> updated automatically.
>
> To fix this bug, I want to bind the table and the model together,
> which looks like:
>
> ----------------------------------------------------------
> IObservableList edges = EMFObserveables.observeList(.........);
>
> IObservableMap[] attributeMap = new IObservableMap[] {
> EMFObservables.observeMap(edges,
> MyPackage.Literals.EDGE__WEIGHT),
> EMFProperties.value(
> FeaturePath.fromList(new EStructuralFeature[] {
> MyPackage.Literals.EDGE__TARGET,
> EcorePackage.Literals.EOBJECT__ECONTAINER,
> // <---- Compiler error: EOBJECT__ECONTAINER is of type EOperator not
> EStructuredFeature
> MyPackage.Literals.GRAPH__NAME
> }
> ).observeDetail(edges)
> }
>
> tableviewer.setLableProvider(new
> ObserveableMapLableProvider(attributeMap));
> ---------------------------------------------------------------
>
> Since the eContainer() is an operation, it cannot be used in
> FeaturePath structure. So this is my question:
>
> How can I observe the name of the graph via the complex chain
> Edge->target:Node->eContainer():Graph->name:String?
>
> And thanks for read the whole boring story :-)
>
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to observe obj.eContainer().name [message #686951 is a reply to message #686747] |
Tue, 17 May 2011 22:14 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Ed is right you can't construct a model-path without explicitly modeling
the parent relationship as an opposite.
The reason for this is that there's no real feature for the parent
relationship. I have not yet investigated this problem but I'm quite
sure it can't be solved as of now so the only solution is to model it as
an eOpposite.
Tom
Am 14.05.11 01:41, schrieb Ed Merks:
> The path of least resistance would be to model an EReference.eOpposite
> for both nodes and edges, i.e., a "graph" feature of type "Graph" in
> each of Node and Edge.
>
> Dongyue Mou wrote:
>> Hello,
>>
>> I have a question for observing an attribute of an EObject's eContainer.
>>
>> Basically, there are 3 classes in my model (here as pseudo code)
>>
>> class Graph {
>> String name
>> Node[] nodes
>> Edge[] edges
>> }
>>
>> class Node {
>> int id
>> Edge[] outgoings
>> Edge[] incomings
>> }
>>
>> class Edge{
>> int weight
>> Node source
>> Edge target
>> }
>>
>> In this model, if given a node N, I can access its Graph by calling
>> N.eContainer().
>>
>> Now, I want to add a table into the GUI, which takes a list of edges
>> and showes all weights of the edges and the names of target node's
>> Graphes. As pseudo code, it looks like:
>>
>> String LabelProvider.getText(Edge e, int col) {
>> if(col == 0)
>> return e.weight+ "";
>> else if(col == 1)
>> return e.target.eContainer().name;
>> }
>>
>> This works fine, until I find that, if the name of Graph is changed
>> somewhere outside the table, the content of the table cannot be
>> updated automatically.
>>
>> To fix this bug, I want to bind the table and the model together,
>> which looks like:
>>
>> ----------------------------------------------------------
>> IObservableList edges = EMFObserveables.observeList(.........);
>>
>> IObservableMap[] attributeMap = new IObservableMap[] {
>> EMFObservables.observeMap(edges,
>> MyPackage.Literals.EDGE__WEIGHT),
>> EMFProperties.value(
>> FeaturePath.fromList(new EStructuralFeature[] {
>> MyPackage.Literals.EDGE__TARGET,
>> EcorePackage.Literals.EOBJECT__ECONTAINER,
>> // <---- Compiler error: EOBJECT__ECONTAINER is of type EOperator not
>> EStructuredFeature
>> MyPackage.Literals.GRAPH__NAME
>> }
>> ).observeDetail(edges)
>> }
>>
>> tableviewer.setLableProvider(new
>> ObserveableMapLableProvider(attributeMap));
>> ---------------------------------------------------------------
>>
>> Since the eContainer() is an operation, it cannot be used in
>> FeaturePath structure. So this is my question:
>>
>> How can I observe the name of the graph via the complex chain
>> Edge->target:Node->eContainer():Graph->name:String?
>>
>> And thanks for read the whole boring story :-)
>>
>>
>>
>>
|
|
|
Goto Forum:
Current Time: Fri Mar 29 14:10:52 GMT 2024
Powered by FUDForum. Page generated in 0.02568 seconds
|