Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Multi-level Tree Custom Layout
Multi-level Tree Custom Layout [message #1764568] Wed, 31 May 2017 10:27 Go to next message
Athanasios Zolotas is currently offline Athanasios ZolotasFriend
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?

https://s24.postimg.org/vmvyrr5lh/Screen_Shot_2017-05-31_at_11.15.27.png

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;
	}

Re: Multi-level Tree Custom Layout [message #1764569 is a reply to message #1764568] Wed, 31 May 2017 10:35 Go to previous messageGo to next message
Athanasios Zolotas is currently offline Athanasios ZolotasFriend
Messages: 52
Registered: November 2016
Location: York
Member
Well, I managed to find the solution on my own.

I discarded the MyTreeOrderingForA class and I updated the getSemanticChildren method of the MyTreeOrderingForB class to the following:
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);
        } else if (semanticParent instanceof A) {
             result = new LinkedList<A>((Collection<? extends A>) ((A) semanticParent).getA2c());
             result.retainAll(candidates);
        }
        return result;
}

Re: Multi-level Tree Custom Layout [message #1764601 is a reply to message #1764569] Wed, 31 May 2017 15:37 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello,

Nice that you found a solution. However, I wanted to know if you had tried to use the "Ordered Tree Layout"[1]? That can be added as a sub-element of the diagram description. It will display the elements (corresponding to the selected mappings) in a tree layout. With edge mapping rooting style set to tree, children will be linked by a fork-like group of connections and you will have folding capabilities.

Regards,
Steve

[1] https://www.eclipse.org/sirius/doc/specifier/diagrams/Diagrams.html#layout


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Multi-level Tree Custom Layout [message #1764655 is a reply to message #1764601] Thu, 01 June 2017 08:19 Go to previous message
Athanasios Zolotas is currently offline Athanasios ZolotasFriend
Messages: 52
Registered: November 2016
Location: York
Member
Hi Steve,

To be honest I didn't know about the Ordered Tree Layout. I will give a try. Thanks!

Thanos
Previous Topic:Create diagram editor
Next Topic:No icon on workspace image node
Goto Forum:
  


Current Time: Fri Apr 26 16:47:20 GMT 2024

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

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

Back to the top