Sprotty Server: Tracing Attributes only knowing their name [message #1841128] |
Tue, 04 May 2021 13:42 |
Robert Richter Messages: 4 Registered: March 2021 |
Junior Member |
|
|
I want to trace my elements to be able to edit my diagram elements within the diagram editor. It should look similar to the result in the project https://github.com/TypeFox/theia-xtext-sprotty-example.
In my case, the content of a node is determined by an attribute "label". It is supposed to be read from an AST object and put inside a label within a node.
So I put up a diagram generator looking like this, which includes tracing methods & attributes:
class DiagramGenerator implements IDiagramGenerator {
@Inject extension ITraceProvider
@Inject extension SIssueMarkerDecorator
override generate(Context context) {
...
graph.children = #[ new StructuralElement(label, binding.structuralClass.toString(), context, obj, this) ]
...
return graph
}
def <T extends SModelElement> T traceElement(T traceable, EObject source) {
trace(traceable, source)
}
def <T extends SModelElement> T traceElement(T traceable, EObject source, EStructuralFeature feature, int index) {
trace(traceable, source, feature, index)
}
def <T extends SModelElement> T traceAndMark(T sElement, EObject element, Context context) {
sElement.trace(element).addIssueMarkers(element, context)
}
}
My diagram elements are objects of a class called StructuralElement. It looks like this:
class StructuralElement extends SNode {
public SPort port
public SLabel label
new(String label, Context context, EObject object, DiagramGenerator traceProvider) {
super()
val objId = label + "." + type
this.id = context.idCache.uniqueId(objId)
this.label = new SLabel [
id = context.idCache.uniqueId(objId + ".label")
text = label
]
// Tracing!!!
if (object !== null) {
val eAttributes = object.eClass.EAllAttributes
var EAttribute labelEAttribute
for (eAttribute : eAttributes) {
if (eAttribute.name.equals("label"))
labelEAttribute = eAttribute
}
traceProvider.traceElement(this.label, object, labelEAttribute, -1)
}
// Tracing done
this.port = new SPort [
id = context.idCache.uniqueId(objId + ".port")
]
this.children = #[ this.label, this.port ]
if (object !== null)
traceProvider.traceAndMark(this, object, context)
}
}
When I launch my code, clicking on nodes results in marking text in the textual code. Also double clicking on a node results in a window asking me to rename the node. Sadly, typing a new name and submitting it, does not change the textual instance of my dsl!
I believe, I did something wrong while retrieving the EAttribute corresponding to the "label" attribute of an EObject. Does someone have an idea what I did wrong about the tracing?
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03582 seconds