Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Eclipse Layout Kernel » Getting started (GEF + ELK)
Getting started (GEF + ELK) [message #1794100] Thu, 23 August 2018 14:00 Go to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
Hello guys and thank your for developing ELK.

I have a GEF project and want ELK to integrate the project so that I can define Layout Algorithms and, more importantly, to define the number and labels for each node inputs/outputs.

However, I'm having difficulties with the "getting started" phase. With that said, can someone please provide me with a link to some GEF/ELK project examples? I'm looking online and I can't seem to find any.

Thank you in advance.

[Updated on: Thu, 23 August 2018 16:47]

Report message to a moderator

Re: Getting started (GEF + ELK) [message #1794101 is a reply to message #1794100] Thu, 23 August 2018 14:14 Go to previous messageGo to next message
Miro Spönemann is currently offline Miro SpönemannFriend
Messages: 78
Registered: March 2015
Location: Kiel, Germany
Member

Which version of GEF are you working with?
Re: Getting started (GEF + ELK) [message #1794103 is a reply to message #1794101] Thu, 23 August 2018 14:53 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
The latest one, GEF5.0.0. So far I'm actually using most of the parts of one of their tutorials - MindMap tutorial: https://info.itemis.com/en/gef/tutorials/

However, if there are only examples with previous versions of GEF, I don't mind and will probably learn from them as well.
Re: Getting started (GEF + ELK) [message #1794124 is a reply to message #1794103] Fri, 24 August 2018 06:53 Go to previous messageGo to next message
Miro Spönemann is currently offline Miro SpönemannFriend
Messages: 78
Registered: March 2015
Location: Kiel, Germany
Member

I haven't used the new GEF with ELK yet, but the general procedure is always the same. Read the following documentation section and its subsections to get started:

https://www.eclipse.org/elk/documentation/tooldevelopers/usingeclipselayout.html

You can also have a look at existing implementations like the GMF layout connector:

https://github.com/eclipse/elk/blob/master/plugins/org.eclipse.elk.conn.gmf/src/org/eclipse/elk/conn/gmf/GmfDiagramLayoutConnector.java
Re: Getting started (GEF + ELK) [message #1794136 is a reply to message #1794124] Fri, 24 August 2018 08:39 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
Thank you very much @Miro for the links.

One really specific designing doubt that I'm having: within GEF, as far as I know it, I can't have multiple ports. The GEF library has no idea of the port concept.
Thus, I can have one node with 5 outgoing connections to other nodes but I don't have controllable and distinguishable ports. My main question with the ELK+GEF integration is if ELK will be able to create ports and label them, or if I need to take care of that somehow in GEF side.

What do you think?

[Updated on: Fri, 24 August 2018 08:43]

Report message to a moderator

Re: Getting started (GEF + ELK) [message #1794156 is a reply to message #1794136] Fri, 24 August 2018 15:12 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
I tried for 6 hours and couldn't integrate ELK with GEF. Please help me.

Please provide some really small example of GEF+ELK if possible.

I already have my Module implementing MvcFxModule, so I have no idea of what I need to do to implement a new binding for IDiagramLayoutConnector and ILayoutConfigurationStore.Provider.

This is what I have in my module:
public class MapModule extends MvcFxModule {

	@Override
	protected void bindIContentPartFactoryAsContentViewerAdapter(MapBinder<AdapterKey<?>, Object> adapterMapBinder) {

		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(MapPartsFactory.class);
	}

	/**
	 *
	 * @param adapterMapBinder
	 */
	protected void bindMapNodePartAdapters(MapBinder<AdapterKey<?>, Object> adapterMapBinder) {
		// bind anchor provider used to create the connection anchors
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(MapAnchorProvider.class);

		// bind a geometry provider, which is used in our anchor provider
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(ShapeOutlineProvider.class);

		/**
		 * We need to tell GEF, how to render the hover and selection feedback for our
		 * parts. We do this by binding two providers to the MapNodePart.
		 */
		// provides a hover feedback to the shape, used by the HoverBehavior
		AdapterKey<?> role = AdapterKey.role(DefaultHoverFeedbackPartFactory.HOVER_FEEDBACK_GEOMETRY_PROVIDER);
		adapterMapBinder.addBinding(role).to(ShapeOutlineProvider.class);

		// provides a selection feedback to the shape
		role = AdapterKey.role(DefaultSelectionFeedbackPartFactory.SELECTION_FEEDBACK_GEOMETRY_PROVIDER);
		adapterMapBinder.addBinding(role).to(ShapeBoundsProvider.class);

		// support moving nodes via mouse drag
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(TransformPolicy.class);
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(TranslateSelectedOnDragHandler.class);
	
		// bind create connection handler
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(CreateMapConnectionOnClickHandler.class);
	
		// bind the context menu policy to the part
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(ShowMapNodeContextMenuOnClickHandler.class);
	}

	@Override
	protected void configure() {
		// start the default configuration
		super.configure();

		bindMapNodePartAdapters(AdapterMaps.getAdapterMapBinder(binder(), MapNodePart.class));
		binder().bind(IDiagramLayoutConnector.class).to(GEFDiagramLayoutConnector.class);
		

	}

	@Override
	protected void bindAbstractContentPartAdapters(MapBinder<AdapterKey<?>, Object> adapterMapBinder) {

		super.bindAbstractContentPartAdapters(adapterMapBinder);

		// binding the HoverOnHoverPolicy to every part
		// if a mouse is moving above a part it is set to the HoverModel
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(HoverOnHoverHandler.class);

		// add the focus and select policy to every part, listening to clicks
		// and changing the focus and selection model
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(FocusAndSelectOnClickHandler.class);
	}

	/**
	 * {@link HoverBehavior} listens to changes in the HoverModel and updates the
	 * graphical representation. The behaviors for selection and focus are already
	 * bound in the superclass.
	 */
	@Override
	protected void bindIRootPartAdaptersForContentViewer(MapBinder<AdapterKey<?>, Object> adapterMapBinder) {

		super.bindIRootPartAdaptersForContentViewer(adapterMapBinder);

		// support creation of nodes via mouse click
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(CreateMapNodeOnClickHandler.class);
	
		// adding the creation feedback behavior
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(CreateConnectionFeedbackBehavior.class);
	}
	
	@Override
	protected void bindIViewerAdaptersForContentViewer(MapBinder<AdapterKey<?>, Object> adapterMapBinder) {
		
		super.bindIViewerAdaptersForContentViewer(adapterMapBinder);
		
		// bind the model to the content viewer
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(ItemCreation.class);
	
		// binding the creation feedback part factory using the role that is specified in the behavior
		AdapterKey<?> role = AdapterKey.role(CreateConnectionFeedbackBehavior.CREATE_FEEDBACK_PART_FACTORY);
		adapterMapBinder.addBinding(role).to(CreateConnectionFeedbackFactory.class);
	}


Re: Getting started (GEF + ELK) [message #1794188 is a reply to message #1794136] Mon, 27 August 2018 07:18 Go to previous messageGo to next message
Miro Spönemann is currently offline Miro SpönemannFriend
Messages: 78
Registered: March 2015
Location: Kiel, Germany
Member

Quote:
My main question with the ELK+GEF integration is if ELK will be able to create ports and label them, or if I need to take care of that somehow in GEF side.


You don't need to use ports with ELK, you can connect edges directly to nodes instead.

Quote:
I already have my Module implementing MvcFxModule, so I have no idea of what I need to do to implement a new binding for IDiagramLayoutConnector and ILayoutConfigurationStore.Provider.


Don't use the same Guice module for different things. Create a new Guice module like it's done for the GMF layout connector (see link in my first post).
Re: Getting started (GEF + ELK) [message #1794344 is a reply to message #1794188] Wed, 29 August 2018 09:46 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
Miro Spönemann wrote on Mon, 27 August 2018 08:18
Quote:
My main question with the ELK+GEF integration is if ELK will be able to create ports and label them, or if I need to take care of that somehow in GEF side.


You don't need to use ports with ELK, you can connect edges directly to nodes instead.


Ok, but I need to have multiple distinguishable connections between nodes. For example:

index.php/fa/33756/0/

Can I then connect an outgoing edge of a node with another node with n incoming distinguishable inputs (edges with different names)?

Thank you for the help so far

P.S: Btw, I still couldn't connect ELK with GEF, almost giving up

[Updated on: Wed, 29 August 2018 09:51]

Report message to a moderator

Re: Getting started (GEF + ELK) [message #1794347 is a reply to message #1794188] Wed, 29 August 2018 10:34 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
[quote title=Miro Spönemann wrote on Mon, 27 August 2018 08:18]Quote:

Don't use the same Guice module for different things. Create a new Guice module like it's done for the GMF layout connector (see link in my first post).


I created a new Guice Module.

package mmi.presentation.views.graphicalEditor;

import java.util.Collection;

import org.eclipse.elk.core.service.IDiagramLayoutConnector;
import org.eclipse.elk.core.service.ILayoutSetup;

import com.google.inject.Binder;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.util.Modules;
import mmi.presentation.views.graphicalEditor.connectors.GEFDiagramLayoutConnector;
import mmi.presentation.views.graphicalEditor.parts.MapConnectionPart;
import mmi.presentation.views.graphicalEditor.parts.MapNodePart;
import mmi.presentation.views.graphicalEditor.parts.ParentMapPart;

public class GEFLayoutSetup implements ILayoutSetup {

	@Override
	public boolean supports(Object object) {
		if (object instanceof Collection) {
            Collection<?> collection = (Collection<?>) object;
            for (Object o : collection) {
                if (o instanceof MapNodePart) {
                    return true;
                }
            }
            return false;
        }
        return object instanceof ParentMapPart || object instanceof MapNodePart
                || object instanceof MapConnectionPart;
    
	}

	@Override
	public Injector createInjector(Module defaultModule) {
		return Guice.createInjector(Modules.override(defaultModule).with(new LayoutModule()));
	    
	}
	
	public static class LayoutModule implements Module {

		@Override
		public void configure(Binder binder) {
		      binder.bind(IDiagramLayoutConnector.class).to(GEFDiagramLayoutConnector.class);

		}

	}

}


But where do I now instantiate it? The other module, the one doing the GEF graphs is being instantiated like this:

		MapModule module = new MapModule();
		this.domain = (HistoricizingDomain) Guice.createInjector(module).getInstance(IDomain.class);

		
		// create viewers
		hookViewers(parent);
		
		// activate domain
		domain.activate();
		
		// load contents
		populateViewerContents();


I tried instantiating it there without success. I mean, "createInjector()" and "configure()" of Layout Module are being called but "buildLayoutGraph()" from GEFLayoutConnector is never called:

		//ELK Module
		GEFLayoutSetup layoutELK = new GEFLayoutSetup();
		
		layoutELK.createInjector(module);
		


Damn Miro, I know that you must be full of work and that for you this is easy as hell, but can you provide me with a little bit more help?

The GMF link you provided didn't help me at all

[Updated on: Wed, 29 August 2018 11:34]

Report message to a moderator

Re: Getting started (GEF + ELK) [message #1794437 is a reply to message #1794347] Thu, 30 August 2018 15:04 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
Okay, after a lot of time I managed to do something by writing this:

DiagramLayoutEngine.invokeLayout(null, getContentViewer().getAdapter(ParentMapPart.class), null);


where ParentMapPart is an instance of my GEF Grpah created by me.

Now, buildLayoutGraph is called and I correctly create the LayoutMapping within this function. I inspect the mapping variable and it has all the Nodes and Connections from my GEF Graph.

The new problem now is that applyLayout doesn't do anything and I can't see any differences applied to my GEF graph. From what I saw in the GMF example that you suggested previously, they use "org.gef.request" from a previous version of GEF to notify the Graph (not sure about this though! ). GEF5 does not have this class or equivalent.

Miro, do you know what I'm missing? I feel that I'm almost there...
Re: Getting started (GEF + ELK) [message #1795081 is a reply to message #1794437] Fri, 14 September 2018 07:51 Go to previous message
Miro Spönemann is currently offline Miro SpönemannFriend
Messages: 78
Registered: March 2015
Location: Kiel, Germany
Member

The injector is not created directly. Instead you register your layout setup with the layoutConnectors extension point.

I've never tried to apply layout to a GEF5 diagram, so I cannot help there. You should ask the GEF developers what is the best way to programmatically set a layout in your diagram.
Previous Topic:ELK algorithm change FixPointAnchor y Position to "-1"
Next Topic:ELK and Sirius "Arrange All"?
Goto Forum:
  


Current Time: Thu Apr 18 22:07:57 GMT 2024

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

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

Back to the top