Problem:Hierarchical Presentation of Referential Syntax in the Outline. [message #1861432] |
Thu, 12 October 2023 11:53  |
Eclipse User |
|
|
|
Hi, everyone. I have a question regarding the outline presentation in DSL files, and I hope you can provide me with some suggestions. Below is my grammar:
Modele:
modeles+=(ModelePackage)*
;
ModelePackage:
A | B | C
;
A:
'A' name=ID
;
B:
'B' name=ID ref=[A]
;
C:
'C' name=ID ref=[B]
;
As you can see in the grammar, I'm using references to models B and C. Then, I've included an example of my DSL file:
A a1
A a2
B b a1
C c b
In the grammar definition, because I'm referencing A within B and C within B, I would like the DSL file's outline to display 'b' as a child of 'a1' and 'c' as a child of 'b',like this:
Model:
a1
-b
-c
a2
but the current result shows all elements in a single column without the correct containment relationships, like this:
Model:
a1
a2
b
c
I prefer to achieve the correct outline presentation by making changes to the grammar itself, without resorting to Java code in the OutlineTreeProvider. I'd appreciate any suggestions and insights you can offer, thanks!
|
|
|
|
|
Re: Problem:Hierarchical Presentation of Referential Syntax in the Outline. [message #1861575 is a reply to message #1861437] |
Thu, 19 October 2023 14:01   |
Eclipse User |
|
|
|
Hi Christian,
Based on the method you provided last time, I attempted to rewrite the code in the DefaultOutlineTreeProvider to achieve the correct hierarchy in the outline. However, I'm encountering some issues with the code implementation and would like to seek your advice.
Here is my grammar:
Modele:
modeles+=(ModelePackage)*
;
ModelePackage:
A | B | C
;
A:
'A' name=ID
;
B:
'B' name=ID 'To' ref=[A]
;
C:
'C' name=ID 'To' ref=[B]
;
And here's the code I've rewritten:
public class MyDslOutlineTreeProvider extends DefaultOutlineTreeProvider {
@Override
public void _createChildren(IOutlineNode parentNode, EObject modelElement) {
if (modelElement instanceof B) {
A parentB = ((B) modelElement).getRef();
if (parentB != null) {
EObject nodeA=parentB;
IOutlineNode parent=findOutlineNode(parentNode, nodeA);
if (parent != null) {
createEObjectNode(parent, modelElement);
}
}
} else if (modelElement instanceof C) {
B parentC = ((C) modelElement).getRef();
if (parentC != null) {
EObject nodeB=parentC;
IOutlineNode parent=findOutlineNode(parentNode, nodeB);
if (parent != null) {
createEObjectNode(parent, modelElement);
}
}
} else {
super._createChildren(parentNode, modelElement);
}
}
private IOutlineNode findOutlineNode(IOutlineNode node,EObject element) {
for(IOutlineNode child : node.getChildren()) {
if (child.getText().equals(element.eGet(EcorePackage.Literals.ENAMED_ELEMENT__NAME))){
return child;
}
}
return null;
}
}
In the code, my idea was to locate the position of the referenced parent element in the outline and then add the child elements under the parent, displaying the appropriate containment relationships. However, with the code I've written, the outline's hierarchy structure hasn't changed, and all elements are listed in the same column.
I would greatly appreciate your assistance in addressing this matter. Thank you!
|
|
|
Re: Problem:Hierarchical Presentation of Referential Syntax in the Outline. [message #1861595 is a reply to message #1861575] |
Fri, 20 October 2023 14:16   |
Eclipse User |
|
|
|
i dont understand why you search nodes in the outline. i would expect you to change the provider to create the nodes in the correct structure
public class MyDslOutlineTreeProvider extends DefaultOutlineTreeProvider {
@Override
protected void _createChildren(DocumentRootNode parentNode, EObject modelElement) {
if (modelElement instanceof Modele) {
EObjectNode modeleNode = createEObjectNode(parentNode, modelElement);
for (ModelePackage p : ((Modele) modelElement).getModeles()) {
if (p instanceof A) {
EObjectNode aNode = createEObjectNode(modeleNode, p);
for (ModelePackage px : ((Modele) modelElement).getModeles()) {
if (px instanceof B) {
if (((B) px).getRef() == p) {
EObjectNode bNode = createEObjectNode(aNode, px);
for (ModelePackage pxx : ((Modele) modelElement).getModeles()) {
if (pxx instanceof C) {
if (((C) pxx).getRef() == px) {
createEObjectNode(bNode, pxx);
}
}
}
}
}
}
}
}
} else {
super._createChildren(parentNode, modelElement);
}
}
}
[Updated on: Fri, 20 October 2023 14:59] by Moderator Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03281 seconds