Skip to main content



      Home
Home » Eclipse Projects » Sirius » Trying to automatically a custom layout
Trying to automatically a custom layout [message #1725640] Sat, 05 March 2016 10:52 Go to next message
Eclipse UserFriend
Hello,

I want to force layout when creating/editing diagram. I don't want manual positionning. I don't know if it's possible with sirius/gmf.
I succeed to force layout at the layout creation step (call "arrange all" action) but i am not able to call "arrange selection" action.

Below some test code

import org.eclipse.draw2d.Animation;
import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.ArrangeRequest;
import org.eclipse.gmf.runtime.diagram.ui.services.layout.AbstractLayoutEditPartProvider;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDDiagramEditPart;
import org.eclipse.sirius.diagram.ui.tools.api.layout.provider.CompoundLayoutProvider;
import org.eclipse.sirius.diagram.ui.tools.api.layout.provider.LayoutProvider;
import org.eclipse.sirius.diagram.ui.tools.api.layout.provider.LineLayoutProvider;

public class CustomLayoutProvider implements LayoutProvider {

	private static String UI_DIAGRAM_NAME = "ui_diagram";

	/** The GMF layout provider. */
	private CompoundLayoutProvider layoutProvider;
	
	private void arrangeLayout(IGraphicalEditPart container, String action){		
		
		// OK: only the first selection when view start 
		if(ActionIds.ACTION_ARRANGE_ALL.equals(action)){			
			ArrangeRequest layoutRequest = new ArrangeRequest(action);	
			Animation.markBegin();	
			container.performRequest(layoutRequest);
		    Animation.run(500);
		}
		
		// KO: I tried this, but i have exception (seems to be a loop causing the error)
		if(ActionIds.ACTION_ARRANGE_SELECTION.equals(action)){
			ArrangeRequest layoutRequest = new ArrangeRequest(action);						
			layoutRequest.setPartsToArrange(container.getChildren());
			Animation.markBegin();	
			container.performRequest(layoutRequest);
		    Animation.run(500);
		}
	    
	}
		
	public AbstractLayoutEditPartProvider getLayoutNodeProvider(IGraphicalEditPart container) {
		
		if (isUIDiagram(container)) {					
			
			if (this.layoutProvider == null) {
				System.out.println("Create Layout provider");
				this.layoutProvider = new CompoundLayoutProvider();
				LineLayoutProvider lineLayoutProvider = new LineLayoutProvider();
				lineLayoutProvider.getPadding().right = 10;
				lineLayoutProvider.setHorizontal(true);
				this.layoutProvider.addProvider(lineLayoutProvider);
				arrangeLayout(container, ActionIds.ACTION_ARRANGE_ALL);
								
			} else			
				arrangeLayout(container, ActionIds.ACTION_ARRANGE_SELECTION);
						
			return this.layoutProvider;
		} 
		return null;
	}

	public boolean provides(IGraphicalEditPart container) {
		return isUIDiagram(container);
	}

	private boolean isUIDiagram(IGraphicalEditPart container) {
		if (container instanceof AbstractDDiagramEditPart) {
			AbstractDDiagramEditPart editPart = (AbstractDDiagramEditPart) container;
			if (editPart.resolveSemanticElement() instanceof DDiagram) {
				DDiagram diagram = (DDiagram) editPart.resolveSemanticElement();
				return UI_DIAGRAM_NAME.equals(diagram.getDescription().getName());
			}
		} 
		return false;
	}

	@Override
	public boolean isDiagramLayoutProvider() {
		// TODO Auto-generated method stub
		return false;
	}
}


Could you help me ? or guide me on better approche ?

Regards
Re: Trying to automatically a custom layout [message #1726679 is a reply to message #1725640] Tue, 15 March 2016 12:10 Go to previous messageGo to next message
Eclipse UserFriend
Hi Julien,

Sirius layouts are called indirectly by the GMF LayoutService, indeed
Sirius provides the
org.eclipse.sirius.diagram.ui.tools.api.layout.provider.DefaultLayoutProvider
as default GMF layout to choose the needed Sirius layout.
You can debug in this part to see why your layout is not called for a
selection.

Best Regards.

Le 06/03/2016 15:31, Julien Deplat a écrit :
> Hello,
>
> I want to force layout when creating/editing diagram. I don't want
> manual positionning. I don't know if it's possible with sirius/gmf.
> I succeed to force layout at the layout creation step (call "arrange
> all" action) but i am not able to call "arrange selection" action.
>
> Below some test code
>
>
> import org.eclipse.draw2d.Animation;
> import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
> import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
> import org.eclipse.gmf.runtime.diagram.ui.requests.ArrangeRequest;
> import
> org.eclipse.gmf.runtime.diagram.ui.services.layout.AbstractLayoutEditPartProvider;
>
> import org.eclipse.sirius.diagram.DDiagram;
> import
> org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDDiagramEditPart;
> import
> org.eclipse.sirius.diagram.ui.tools.api.layout.provider.CompoundLayoutProvider;
>
> import
> org.eclipse.sirius.diagram.ui.tools.api.layout.provider.LayoutProvider;
> import
> org.eclipse.sirius.diagram.ui.tools.api.layout.provider.LineLayoutProvider;
>
> public class CustomLayoutProvider implements LayoutProvider {
>
> private static String UI_DIAGRAM_NAME = "ui_diagram";
>
> /** The GMF layout provider. */
> private CompoundLayoutProvider layoutProvider;
>
> private void arrangeLayout(IGraphicalEditPart container, String
> action){
>
> // OK: only the first selection when view start
> if(ActionIds.ACTION_ARRANGE_ALL.equals(action)){
> ArrangeRequest layoutRequest = new ArrangeRequest(action);
> Animation.markBegin();
> container.performRequest(layoutRequest);
> Animation.run(500);
> }
>
> // KO: I tried this, but i have exception (seems to be a loop
> causing the error)
> if(ActionIds.ACTION_ARRANGE_SELECTION.equals(action)){
> ArrangeRequest layoutRequest = new ArrangeRequest(action);
> layoutRequest.setPartsToArrange(container.getChildren());
> Animation.markBegin();
> container.performRequest(layoutRequest);
> Animation.run(500);
> }
> }
>
> public AbstractLayoutEditPartProvider
> getLayoutNodeProvider(IGraphicalEditPart container) {
>
> if (isUIDiagram(container)) {
>
> if (this.layoutProvider == null) {
> System.out.println("Create Layout provider");
> this.layoutProvider = new CompoundLayoutProvider();
> LineLayoutProvider lineLayoutProvider = new
> LineLayoutProvider();
> lineLayoutProvider.getPadding().right = 10;
> lineLayoutProvider.setHorizontal(true);
> this.layoutProvider.addProvider(lineLayoutProvider);
> arrangeLayout(container, ActionIds.ACTION_ARRANGE_ALL);
>
> } else
> arrangeLayout(container,
> ActionIds.ACTION_ARRANGE_SELECTION);
>
> return this.layoutProvider;
> } return null;
> }
>
> public boolean provides(IGraphicalEditPart container) {
> return isUIDiagram(container);
> }
>
> private boolean isUIDiagram(IGraphicalEditPart container) {
> if (container instanceof AbstractDDiagramEditPart) {
> AbstractDDiagramEditPart editPart =
> (AbstractDDiagramEditPart) container;
> if (editPart.resolveSemanticElement() instanceof DDiagram) {
> DDiagram diagram = (DDiagram)
> editPart.resolveSemanticElement();
> return
> UI_DIAGRAM_NAME.equals(diagram.getDescription().getName());
> }
> } return false;
> }
>
> @Override
> public boolean isDiagramLayoutProvider() {
> // TODO Auto-generated method stub
> return false;
> }
> }
>
>
> Could you help me ? or guide me on better approche ?
>
> Regards



--
Esteban Dugueperoux - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Trying to automatically a custom layout [message #1730039 is a reply to message #1726679] Thu, 21 April 2016 03:01 Go to previous message
Eclipse UserFriend
Hello Julien,
I have created customLayoutProvider class and also added the extension in plugin.xml file.
but still, when I am clicking on arrange all button,It is not calling any single method from my CustomLayoutProvider class (Even I tried your CustomLayoutProvider class code too).
can you please suggest something about that.
I have added the following extensions in my plugin.xml file

<extension point="org.eclipse.sirius.diagram.ui.viewOrderingProvider">
<viewOrderingProvider providerClass="com.model.domain.mnc.design.layout.CustomViewOrderingProvider" />
</extension>

<extension
point="org.eclipse.sirius.diagram.ui.layoutProvider">
<layoutProvider
priority="highest"
providerClass="com.model.domain.mnc.design.layout.CustomLayoutProvider">
</layoutProvider>
</extension>

Previous Topic:Diagram Layouting Problem - Strange Behaviour, Nodes over Nodes...
Next Topic:ConcurrentModificationException in Container Drop
Goto Forum:
  


Current Time: Sat Mar 15 11:13:18 EDT 2025

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

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

Back to the top