Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Editor to outline view linking(Not able to link editor node to outline view node)
Editor to outline view linking [message #1783889] Tue, 20 March 2018 00:50 Go to next message
Eclipse UserFriend
Hello,

I am facing problem in editor to outline node linking.
I have just created a sample model for the problem, i am facing.

Grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	students+=Student*;
	
Student:
	name=ID seatNumber=INT address=STRING subjects=STRING;


Outline has been customised to made entries as child of other node.
@SuppressWarnings("all")
public class MyDslOutlineTreeProvider extends DefaultOutlineTreeProvider {
	@Override
	public void _createChildren(DocumentRootNode parent, EObject modelElement) {
		EObjectNode node = null;
		if (modelElement instanceof Model) {
			EList<Student> students = ((Model) modelElement).getStudents();
			createOutlineNode(students, parent);
		}
	}

	private void createOutlineNode(EList<Student> students, IOutlineNode node) {
		IOutlineNode nodeLocal = null;
		nodeLocal = node;
		for (Student student : students) {
			nodeLocal = (IOutlineNode) createEObjectNode(nodeLocal, student, labelProvider.getImage(student),
					student.getName(), true);
		}
	}
}

when I click in outline node, it is finding correct node in editor.
But from editor only on selection of first node, it reflects in outline view.
For the second, third and so on, it is not.
I am not able to link to correct node from editor to outline view.
Need support in this regard.


Thanks in advance.

Regards,
Virag Purnam
Re: Editor to outline view linking [message #1783890 is a reply to message #1783889] Tue, 20 March 2018 01:53 Go to previous messageGo to next message
Eclipse UserFriend
is there a reason you you this very strange outline structure?
you can debug
org.eclipse.xtext.ui.editor.outline.actions.OutlineWithEditorLinker.findBestNode(IOutlineNode, ITextRegion)

i think that your outline structure has the problem that the parent (first student) region does not include the childs (second and grandchild third student) regions
Re: Editor to outline view linking [message #1783891 is a reply to message #1783890] Tue, 20 March 2018 02:05 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the quick reply.

There is reason.
In actual grammar user can write sentence starting with number.
e.g
00 "Some Statement"
01 "Another statemente 2nd level"
02 "Statement for 3rd level"
01 "Some more 2nd level"
02 "More for 3rd Level"

In Outline, expectation is that it should come in order.
Outline view should look like this.
00 "Some Statement"
                         01 "Another statemente 2nd level"
                                                      02 "Statement for 3rd level"
                          01 "Some more 2nd level"
                                                      02 "More for 3rd Level"

Based on number we are making child and grandchild.
How can I override org.eclipse.xtext.ui.editor.outline.actions.OutlineWithEditorLinker.findBestNode(IOutlineNode, ITextRegion) this method?
How can I manually set the ITextRegion for IOutlineNode?

[Updated on: Tue, 20 March 2018 02:08] by Moderator

Re: Editor to outline view linking [message #1783892 is a reply to message #1783891] Tue, 20 March 2018 02:08 Go to previous messageGo to next message
Eclipse UserFriend
then you need to calculate correct regions
in your example e.g.

class MyDslOutlineTreeProvider extends DefaultOutlineTreeProvider {

	override void _createChildren(DocumentRootNode parent, EObject modelElement) {
		var EObjectNode node = null
		if (modelElement instanceof Model) {
			var EList<Student> students = ((modelElement as Model)).getStudents()
			createOutlineNode(students, parent)
		}
	}

	def private void createOutlineNode(EList<Student> students, IOutlineNode node) {
		var IOutlineNode nodeLocal = null
		nodeLocal = node
		var endOffset = if (node.fullTextRegion !== null) {
				node.fullTextRegion.offset + node.fullTextRegion.length
			} else {
				-1
			}

		for (Student student : students) {
			nodeLocal = createEObjectNode(nodeLocal, student, labelProvider.getImage(student), student.getName(),
				true) as IOutlineNode
			if (endOffset !== -1)
				if (nodeLocal instanceof EObjectNode) {
					if (nodeLocal.fullTextRegion !== null) {
						nodeLocal.textRegion = new TextRegion(nodeLocal.fullTextRegion.offset,
							endOffset - nodeLocal.fullTextRegion.offset)
					}

				}
		}
	}

}


and in your actual thing something that collects all statements that belong together
Re: Editor to outline view linking [message #1783893 is a reply to message #1783892] Tue, 20 March 2018 02:10 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the hint.
I will try with this approach.
Re: Editor to outline view linking [message #1783901 is a reply to message #1783893] Tue, 20 March 2018 04:15 Go to previous message
Eclipse UserFriend
Thanks a lot Mr. Christian Dietrich.
It worked for me.
I need to do some code refactoring, but this solution worked for me.
Thanks a lot again.
Previous Topic:instantiate object with type parameter
Next Topic:Using Xbase Expressions in JvmModelInferrer
Goto Forum:
  


Current Time: Thu Jun 12 09:46:02 EDT 2025

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

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

Back to the top