Multi-level Tree Custom Layout [message #1764568] |
Wed, 31 May 2017 10:27 |
Athanasios Zolotas Messages: 52 Registered: November 2016 Location: York |
Member |
|
|
I followed this guide to create a custom tree layout. However, as far as I understand, this describes how to create a 2-level tree layout. In my diagrams I would like to have a multi-level tree layout as shown in the provided screenshot. For example, I would like to have nodes of type "B" on top, then in the second level, nodes of types "A" and at the last level, nodes of type "C". I have managed to create the custom layout for the top and second level (B and A) but I can't figure out how to set the tree ordering to define the 3rd level. I tried creating a new tree ordering (that extends AbstractSemanitcTreeOrdering) to define that for the mappings of elements A (i.e., aContainer) this new should be called instead. This new tree ordering works as the one for bContainer but instead of As it set the appropriate Cs for semantic children of nodes of types A (I tried to return the As as roots and it failed. I also tried to return no roots for As - this is the version I attach). However, any of these work. Any idea how to proceed?
public class MyViewOrderingProvider implements ViewOrderingProvider {
@Override
public boolean provides(DiagramElementMapping mapping) {
return getMappingToViewOrdering().containsKey(getMappingName(mapping));
}
@Override
public ViewOrdering getViewOrdering(DiagramElementMapping mapping) {
System.out.println("Mapping: " + mapping);
ViewOrdering vo = (ViewOrdering) getMappingToViewOrdering().get(getMappingName(mapping));
System.out.println("VO: " + vo);
return vo;
}
private String getMappingName(DiagramElementMapping mapping) {
String result = null;
if (mapping instanceof NodeMapping) {
result = ((NodeMapping) mapping).getName();
} else if (mapping instanceof EdgeMapping) {
result = ((EdgeMapping) mapping).getName();
} else if (mapping instanceof ContainerMapping) {
result = ((ContainerMapping) mapping).getName();
}
System.out.println("Result: " + result);
return result;
}
private Map getMappingToViewOrdering() {
Map result = new HashMap();
result.put("bContainer", new MyTreeOrderingForB());
result.put("aContainer", new MyTreeOrderingForA());
return result;
}
}
public class MyTreeOrderingForB extends AbstractSemanticTreeOrdering {
@Override
public List getSemanticRoots(List eObjects) {
List<B> roots = new LinkedList<B>();
for (Object object : eObjects) {
EObject semantic = (EObject) object;
if (semantic instanceof B) {
B b_ = (B) semantic;
if (b_.eContainer() == null || !eObjects.contains(b_.eContainer())) {
roots.add(b_);
}
}
}
return roots;
}
@Override
public List getSemanticChildren(EObject semanticParent, List candidates) {
List result = Collections.EMPTY_LIST;
if (semanticParent instanceof B) {
result = new LinkedList<B>((Collection<? extends B>) ((B) semanticParent).getB2a());
result.retainAll(candidates);
}
return result;
}
}
public class MyTreeOrderingForA extends AbstractSemanticTreeOrdering {
@Override
public List getSemanticRoots(List eObjects) {
List<A> roots = new LinkedList<A>();
for (Object object : eObjects) {
EObject semantic = (EObject) object;
if (semantic instanceof A) {
A a_ = (A) semantic;
if (a_.eContainer() == null || !eObjects.contains(a_.eContainer())) {
roots.add(a_);
}
}
}
//return roots;
return Collections.EMPTY_LIST;
}
@Override
public List getSemanticChildren(EObject semanticParent, List candidates) {
List result = Collections.EMPTY_LIST;
if (semanticParent instanceof A) {
result = new LinkedList<A>((Collection<? extends A>) ((A) semanticParent).getA2c());
result.retainAll(candidates);
}
return result;
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02060 seconds