Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » "Root" layout
"Root" layout [message #1839481] Mon, 22 March 2021 11:50 Go to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 195
Registered: January 2013
Location: Sweden
Senior Member
Hi,

When doing a re-layout using 'Arrange' the layout is in a form a tree with the 'top' element at the bottom.

How can I get it as a 'root system' / upside -down tree with the top element at the top?

/Patrik
Re: "Root" layout [message #1839615 is a reply to message #1839481] Wed, 24 March 2021 15:23 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 195
Registered: January 2013
Location: Sweden
Senior Member
Never mind this. it works.

However, how do I create my onw layout algorithm, regardless?
Re: "Root" layout [message #1839934 is a reply to message #1839615] Thu, 01 April 2021 12:34 Go to previous messageGo to next message
Quentin Le Menez is currently offline Quentin Le MenezFriend
Messages: 83
Registered: September 2014
Location: Paris Saclay, France
Member
Hi Patrik,

We do not support a quick creation of new layout. The ELK [1] layout on the other hand can be configured quite quickly and is compatible with the gmf stack that is used by Papyrus.
I can add further precisions if you need it (the custom layout can be implemented with very little adaptation).

hth,
/Quentin
[1] https://www.eclipse.org/elk/

[Updated on: Thu, 01 April 2021 12:34]

Report message to a moderator

Re: "Root" layout [message #1840357 is a reply to message #1839934] Tue, 13 April 2021 06:54 Go to previous messageGo to next message
Yoann Farré is currently offline Yoann FarréFriend
Messages: 235
Registered: November 2017
Senior Member
Hello Quentin,
I'm interested to have more pieces of information about the way to implement a custom layout. Could you give me some indications and pointers?
Thank you.
Regards.
Yoann.
Re: "Root" layout [message #1840837 is a reply to message #1840357] Mon, 26 April 2021 12:27 Go to previous message
Quentin Le Menez is currently offline Quentin Le MenezFriend
Messages: 83
Registered: September 2014
Location: Paris Saclay, France
Member
Hi Yoann,

Sorry for the delay. The way to use the ELK layouts is pretty simple and quick, you can see the detailed documentation on their own website [1].

You'll need the ELK tool installed or in you workspace for the runtime (from memory I used the 5.0 las time I tested this but I'd think this should still be functional).
Because there is a Papyrus editor connector and the GMF/EMF layer used you a should only need to implement the following steps to begin using the elk layouts (again, from memory).
1- registering your elk extension point:
<extension
      point="org.eclipse.elk.core.service.layoutConnectors">
   <setup class="org.eclipse.<yourpath>.PapyrusDiagramtemplateElkLayoutSetup">
   </setup>
</extension>


2- Extend ELK's GMFLayoutSetup and GMFDiagramLayoutConnector:
public class PapyrusDiagramtemplateElkLayoutSetup extends GmfLayoutSetup {
	// Use this class to add new customization options
	/** Guice module for the generic GMF connector. */
	public static class GmfLayoutModule implements Module {
		@Override
		public void configure(final Binder binder) {	
binder.bind(IDiagramLayoutConnector.class).to(PapyrusDiagramtemplateELKLayoutConnector.class);
binder.bind(ILayoutConfigurationStore.Provider.class).to(GmfLayoutConfigurationStore.Provider.class);
		}
	}
}

public class PapyrusDiagramtemplateELKLayoutConnector extends GmfDiagramLayoutConnector {
	// Use this class to add new customization options
}


Then you'll just have to set an interface through which you can call a custom layout configured with the required features, such as (and this might very well not be the best implementation of it ever ^^):
       /**
       * Helper method used to arrange recursively editparts
       *
       * @param editpart
       *            the editpart to process
       */
       @SuppressWarnings("unchecked")
       public static void arrangeDiagram(EditPart editPart) {
             arrangeDiagramEditParts(editPart);
             arrangeDiagramEditPartsWithELK(editPart);
             arrangeConnectors((IGraphicalEditPart) editPart);
       }

       private static void arrangeDiagramEditParts(EditPart editPart) {
             ArrangeRequest request = new ArrangeRequest(RequestConstants.REQ_ARRANGE_DEFERRED);
             List<EditPart> listToArrange = new ArrayList<>();
             listToArrange.addAll(editPart.getChildren());

             if (!listToArrange.isEmpty()) {
                    for (Object element : editPart.getChildren()) {
                           if (element instanceof EditPart) {
                                  arrangeDiagramEditParts((EditPart) element);
                           }
                    }

                    request.setViewAdaptersToArrange(listToArrange);

                    Command command = editPart.getCommand(request);
                    if (null != command && command.canExecute()) {
                           command.execute();
                    }
             }
       }

       private static void arrangeDiagramEditPartsWithELK(EditPart editPart) {
             LayoutConfigurator layoutConfigurator = new LayoutConfigurator();
             // You might want or need to add new customized parameters to either ElkNodes or ElkEdges following the same template
             layoutConfigurator.configure(ElkNode.class).setProperty(CoreOptions.ALGORITHM, "org.eclipse.elk.layered");
             layoutConfigurator.configure(ElkNode.class).setProperty(CoreOptions.DIRECTION, Direction.DOWN);
             layoutConfigurator.configure(ElkNode.class).setProperty(CoreOptions.SPACING_NODE_NODE, 60.0);
              layoutConfigurator.configure(ElkNode.class).setProperty(CoreOptions.SEPARATE_CONNECTED_COMPONENTS, true);
             DiagramLayoutEngine.Parameters params = new DiagramLayoutEngine.Parameters();

             params.addLayoutRun(layoutConfigurator);
             params.getGlobalSettings()
                           .setProperty(CoreOptions.ANIMATE, false)
                           .setProperty(CoreOptions.PROGRESS_BAR, false)
                           .setProperty(CoreOptions.LAYOUT_ANCESTORS, false)
                           .setProperty(CoreOptions.ZOOM_TO_FIT, false);

             DiagramLayoutEngine.invokeLayout(getWorkbenchPart(), null, params);
       }

       private static IWorkbenchPart getWorkbenchPart() {
             return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
       }

       private static void arrangeConnectors(IGraphicalEditPart modelEditPart) {
             DiagramTemplateSelectAction selectAction = new DiagramTemplateSelectAction(SelectAction.SELECT_ALL_CONNECTORS, Collections.singletonList(modelEditPart));
             List<IGraphicalEditPart> list = selectAction.getAvailableConnectors();
             LineStyleAction lineStyleAction = new LineStyleAction(LineStyleAction.RECTILINEAR, list);
             Command RectilinearCommand = lineStyleAction.getCommand();
             modelEditPart.getEditingDomain().getCommandStack().execute(new GEFtoEMFCommandWrapper(RectilinearCommand));
       }

public class DiagramTemplateSelectAction extends SelectAction {

       public DiagramTemplateSelectAction(String parameter, List<IGraphicalEditPart> selectedElements) {
             super(parameter, selectedElements);
       }

       public List<IGraphicalEditPart> getAvailableConnectors() {
             refreshAllEditParts(getDiagramEditPart());
             System.err.println("getAvailableConnectors_getSelectableNodes: " + getSelectableNodes(getDiagramEditPart()).size());
             System.err.println("getAvailableConnectors_getAllDiagramEditParts: " + DiagramEditPartsUtil.getAllEditParts(getDiagramEditPart()).size());
             List<IGraphicalEditPart> connectorEditParts = getAllConnectors(DiagramEditPartsUtil.getAllEditParts(getDiagramEditPart()));

             return connectorEditParts;
       }

       private void refreshAllEditParts(IGraphicalEditPart gEditPart) {
             Iterator<IGraphicalEditPart> it = gEditPart.getChildren().iterator();
             while (it.hasNext()) {
                    IGraphicalEditPart igep = it.next();
                    igep.refresh();
                    refreshAllEditParts(igep);
             }
       }

       private List<IGraphicalEditPart> getAllConnectors(List<IGraphicalEditPart> allgEditParts) {
             System.err.println("getAllConnectors:" + addSelectableConnections(allgEditParts).size());
             return addSelectableConnections(allgEditParts);
       }
}



HTH,
/Quentin

[1] https://www.eclipse.org/elk/documentation/tooldevelopers/usingeclipselayout.html
Previous Topic:State Machine - Transition Effect
Next Topic:Code generator for Java not working (Papyrus Standalone 2020-10)
Goto Forum:
  


Current Time: Fri Apr 26 10:53:21 GMT 2024

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

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

Back to the top