Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Arranging all nodes according to grid
Arranging all nodes according to grid [message #1837270] Tue, 26 January 2021 15:40 Go to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 197
Registered: June 2010
Senior Member
Hi,

My goal is to arrange all nodes according to a grid. My hope is to sort the nodes on my diagram according to some algorithm and then let Sirius do the calculation of the heights and the widths of the grid's rows and columns.

I looked at https://www.eclipse.org/sirius/doc/developer/extensions-provide_custom-arrange-all.html

My first attempt was to simply extend AbstractViewOrdering, create the corresponding extension and hope that my diagrams would use the provided ordering.

That didn't work. Could it be that this would have worked if applied on the subnodes of a container? I didn't try that as my intention is to arrange the nodes on the diagram.

My next attempt (and assumption) was to implement a layout provider by extending the GridLayoutProvider. Also in that case I need to create a corresponding extension right?

My layout provider simply delegates layoutEditParts to GridLayoutProvider::layoutEditParts and I can confirm that it is called. The delegated implementation looks like:

    public Command layoutEditParts(final List selectedObjects, final IAdaptable layoutHint) {
...
        GridViewOrdering viewOrdering = ViewOrderingHint.getInstance().consumeViewOrdering(getContainerEditPart(selectedObjects).getNotationView());
        if (viewOrdering == null) {
            viewOrdering = new SimpleViewOrdering();
        }
        viewOrdering.setViews(views);
        final GridView gridView = viewOrdering.getSortedViewsAsGrid();

...     
}


(Note, the code above is from GridLayoutProvider.) Somehow I would have liked to viewOrdering be an instance of my extension of AbstractViewOrdering. However, I don't understand how to get ViewOrderingHint to return an instance of this.

Am I completely on the wrong path or am I missing a small piece?

Regards,
Wilbert
Re: Arranging all nodes according to grid [message #1837640 is a reply to message #1837270] Wed, 03 February 2021 14:34 Go to previous messageGo to next message
Florian Barbin is currently offline Florian BarbinFriend
Messages: 262
Registered: August 2010
Senior Member
Hi Wilbert,

You may have solved your issue since last week but when you say the AbstractViewOrdering extension didn't work, you mean the extension is never called?
The view ordering provided by the extension point are populated here: org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDDiagramEditPart.populateViewOrderings(). It might be a good entry point to see what happens.

Regards,

Florian
Re: Arranging all nodes according to grid [message #1837685 is a reply to message #1837640] Thu, 04 February 2021 08:15 Go to previous messageGo to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 197
Registered: June 2010
Senior Member
Hi Florian,

First of all, I got it working but still thanks for getting back to me.
I recon there are two relevant extensions:

  • layoutProvider: is asked whether it provides a layouter for an IGraphicalEditPart
  • viewOrderingProvider: is asked whether it provides an ordering for a DiagramElementMapping

I assumed that the viewOrderingProvider would be asked whether it can provide an ordering for any Sirius diagram as a whole. If my 'logging' is correct, than I think that this is not the case. My viewOrderingProvider is queried for each element on the diagram, but not for the diagram as a whole. Does this correspond with your expectations/knowledge?

If that's true, (if a viewOrderingProvider is not called for the diagram as a whole) then the only way to layout the diagram elements on a grid, is to create an extension of GridLayoutProvider and provide it via the layoutProvider extension.

So here's what I did:

  • create an org.eclipse.sirius.diagram.ui.layoutProvider extension that provides a layouter for my kind of diagram.
  • create the implementation of the layouter by extending the GridLayoutProvider
  • in my layouter implementation, I overrid:

    • layoutEditParts and layoutLayoutNodes (but I am not sure whether both need to be overriden) to ensure that the colum and line size modes were set to DIMENSION_BY_LINE_OR_C)LUMN
    • buildGrid to create a grid containing the nodes that I want to be layouted accordingly.

By this, I got my diagram layoutted the way I wanted. (Just writing it down here in case someone has a similar task at hand.)

Regards,
Wilbert


[Updated on: Thu, 04 February 2021 08:15]

Report message to a moderator

Re: Arranging all nodes according to grid [message #1837745 is a reply to message #1837685] Fri, 05 February 2021 08:08 Go to previous message
Florian Barbin is currently offline Florian BarbinFriend
Messages: 262
Registered: August 2010
Senior Member
Indeed, the viewOrdering is intended to make it possible to provide your own ordering for the children of a given view. The viewOrderingProvider that provides the viewOrdering is selected on a particular mapping.

I do not see a simpler way than implementing your own GridLayoutProvider.

Thanks for your feedback!

Regards,
Florian
Previous Topic:Creation tool uses tool name instead of label for command label?
Next Topic:Is it possible to resize node image?
Goto Forum:
  


Current Time: Tue Apr 13 20:56:39 GMT 2021

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

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

Back to the top