How to observe obj.eContainer().name [message #686903] |
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 :-)
--
|
|
|
Powered by
FUDForum. Page generated in 0.01756 seconds