Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Sprotty » Sprotty Server: Tracing Attributes only knowing their name
Sprotty Server: Tracing Attributes only knowing their name [message #1841128] Tue, 04 May 2021 13:42 Go to next message
Robert Richter is currently offline Robert RichterFriend
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?
Re: Sprotty Server: Tracing Attributes only knowing their name [message #1841153 is a reply to message #1841128] Wed, 05 May 2021 06:56 Go to previous messageGo to next message
Miro Spönemann is currently offline Miro SpönemannFriend
Messages: 78
Registered: March 2015
Location: Kiel, Germany
Member

Hi Robert, it's hard to say what is missing or going wrong. I would start by debugging in the frontend and backend to see what actions are triggered and how they are processed.
Re: Sprotty Server: Tracing Attributes only knowing their name [message #1841159 is a reply to message #1841128] Wed, 05 May 2021 09:54 Go to previous messageGo to next message
Robert Richter is currently offline Robert RichterFriend
Messages: 4
Registered: March 2021
Junior Member
I found that my issue lay in the way the attributes were named. For renaming a Node, it seems to be required to have an attribute "name". Then this attribute will be changed, once a rename request arrives.

Now I am asking myself, is there a way to change that? So that for my case it renames "label" instead of "name".
Re: Sprotty Server: Tracing Attributes only knowing their name [message #1841163 is a reply to message #1841159] Wed, 05 May 2021 11:52 Go to previous messageGo to next message
Miro Spönemann is currently offline Miro SpönemannFriend
Messages: 78
Registered: March 2015
Location: Kiel, Germany
Member

That's part of the renaming strategy of Xtext. I guess you could change that by overriding the respective implementation classes, but I would recommend changing the attribute to "name" to avoid such problems.
Re: Sprotty Server: Tracing Attributes only knowing their name [message #1841165 is a reply to message #1841163] Wed, 05 May 2021 13:11 Go to previous message
Robert Richter is currently offline Robert RichterFriend
Messages: 4
Registered: March 2021
Junior Member
Thank you very much for your time! I followed your advice and renamed my attribute.
Previous Topic:Sprotty from Graphical Change to Text
Next Topic:Question: Binding openFeature to a dialog
Goto Forum:
  


Current Time: Fri Mar 29 05:45:05 GMT 2024

Powered by FUDForum. Page generated in 0.03224 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top