Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Customising Edge styles
Customising Edge styles [message #1775211] Thu, 26 October 2017 11:13 Go to next message
Ran Wei is currently offline Ran WeiFriend
Messages: 119
Registered: September 2012
Location: York, UK
Senior Member
Hi,

We are currently trying to customise the style of edges in our editor. Instead of the three line styles (Straight/Tree/Manhattan) provided by Sirius/GMF. We want to implement a edge what is actually a cubic curve. Is there anyway that we could provide an edit part for the edges? Any pointer to that direction is hugely appreciated.


Cheers,
Will


Research Associate
Department of Computer Science
University of York
Re: Customising Edge styles [message #1775226 is a reply to message #1775211] Thu, 26 October 2017 14:00 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
Hi,

You can contribute a custom edit part with a gmf extension point.
You have some example in Sirius documentation: https://www.eclipse.org/sirius/doc/developer/extensions-provide_custom_style.html and UML Designer project https://github.com/ObeoNetwork/UML-Designer/blob/master/plugins/org.obeonetwork.gmf.runtime.diagram.ui.extension/src/org/obeonetwork/gmf/runtime/diagram/ui/extension/rotatable/provider/RotatableImageEditPartProvider.java https://github.com/ObeoNetwork/UML-Designer/blob/master/plugins/org.obeonetwork.gmf.runtime.diagram.ui.extension/src/org/obeonetwork/gmf/runtime/diagram/ui/extension/rotatable/editPart/RotatableNodeEditPart.java https://github.com/ObeoNetwork/UML-Designer/blob/master/plugins/org.obeonetwork.gmf.runtime.diagram.ui.extension/plugin.xml

Though you will not be able to use the custom style configuration part that is specific to nodes and cannot be used for edge.
It means you cannot specify your custom style throughout a style item under the edge mapping in the odesign.

So in the method getNodeEditPartClass you will check if the element is an edge and if so you will provide your custom part
All edges will have the specificity defined by your edit part regardless of the styles defined in odesign for the parts overriden.

Regards,

Pierre


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Mon, 30 October 2017 15:22]

Report message to a moderator

Re: Customising Edge styles [message #1775295 is a reply to message #1775226] Fri, 27 October 2017 09:59 Go to previous messageGo to next message
Ran Wei is currently offline Ran WeiFriend
Messages: 119
Registered: September 2012
Location: York, UK
Senior Member
Hi Pierre,

Thanks very much for your response.

We have tried providing cutomised EditParts through the EditPartProviders extension of GMF. As a matter of fact all our shapes need a customised EditPart.

As far as I understand, what you suggested is to create the Edges as they are in the odesign file, and then in the EditPart Provider we look for Edges and return our customised EditPart?

If this is the case, could you please point me to the direction which class to extend? For example, for nodes we extend AbstractNotSelectableShapeNodeEditPart. What of edges?

Cheers,
Ran


Research Associate
Department of Computer Science
University of York
Re: Customising Edge styles [message #1775465 is a reply to message #1775295] Mon, 30 October 2017 14:07 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
Hi,

You have well understood what I suggested.
The class to extend is AbstractDiagramEdgeEditPart.

Regarding your need are you aware of the option "Smoothness" that seems to fit well?

To test it just select an edge and in the "properties view" activate the smoothness in "appearence" tab to have curved edges:
index.php/fa/31181/0/

Though this option need to be manually activated for all edges with default mechanism.

So your custom edge part can activate by default this option.

Regards,

Pierre


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Mon, 30 October 2017 15:09]

Report message to a moderator

Re: Customising Edge styles [message #1776185 is a reply to message #1775465] Mon, 13 November 2017 14:05 Go to previous messageGo to next message
Ran Wei is currently offline Ran WeiFriend
Messages: 119
Registered: September 2012
Location: York, UK
Senior Member
Hi Pierre,

Thank you very much for your reply. I have tried the smooth edge, unfortunately it does not meet our requirement.

I have implemented a editpart for the edge. However i have ran into some other problems.

See this is the code for my editpart:
public class EdgeEditPart extends AbstractDiagramEdgeEditPart implements IStyleEditPart{

	public EdgeEditPart(View view) {
		super(view);
	}
	
	public DragTracker getDragTracker(Request request) {
        return getParent().getDragTracker(request);
    }
	
	@Override
	protected Connection createConnectionFigure() {
		Figure figure = new EdgePipeConnection();
		return (Connection) figure;
	}
	
}


The EdgePipeConnection is a subclass of PolylineConnectionEx, we have tried PolylineConnection but it gives me a IllegalStateException. However, when I tried PolylineConnectionEx, we had this exception:

java.lang.NullPointerException
at org.eclipse.draw2d.Figure.add(Figure.java:149)
at org.eclipse.draw2d.Figure.add(Figure.java:185)
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.addChildVisual(AbstractGraphicalEditPart.java:209)
at org.eclipse.gef.editparts.AbstractEditPart.addChild(AbstractEditPart.java:211)
at org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart.addChild(ConnectionEditPart.java:213)
at org.eclipse.gef.editparts.AbstractEditPart.refreshChildren(AbstractEditPart.java:781)
at org.eclipse.gef.editparts.AbstractEditPart.refresh(AbstractEditPart.java:726)
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.refresh(AbstractGraphicalEditPart.java:644)
at org.eclipse.gef.editparts.AbstractConnectionEditPart.refresh(AbstractConnectionEditPart.java:226)
at org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart.access$1(ConnectionEditPart.java:1)
at org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart$5.run(ConnectionEditPart.java:1127)
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:328)

Which is telling me that the parent of the figure is null. Do you have any idea how to solve this please?


Cheers,
Ran


Research Associate
Department of Computer Science
University of York
Re: Customising Edge styles [message #1776317 is a reply to message #1776185] Wed, 15 November 2017 09:41 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
In what situation does this happen?

Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Customising Edge styles [message #1776320 is a reply to message #1776317] Wed, 15 November 2017 10:28 Go to previous messageGo to next message
Ran Wei is currently offline Ran WeiFriend
Messages: 119
Registered: September 2012
Location: York, UK
Senior Member
Hi Pierre,

As previously discussed, I provide a EditPartProvider, this is the code of my implmentation:
public class TreeEditPartProvider extends AbstractEditPartProvider {

	public TreeEditPartProvider() {
		super();
	}

	@Override
	protected Class<?> getNodeEditPartClass(View view) {
		if (view.getElement() instanceof CustomStyle) {
			CustomStyle customStyle = (CustomStyle) view.getElement();
			if (customStyle.getId().equals(TreeEditPart.TREE_EDITPART_ID)) {
				return TreeEditPart.class;
			}
		}
		return super.getNodeEditPartClass(view);
	}

	@Override
	protected Class<?> getEdgeEditPartClass(View view) {
		if (view.getElement() instanceof DEdge) {
			return EdgeEditPart.class;
		}
		return super.getEdgeEditPartClass(view);
	}
}


The EdigeEditPart class:

public class EdgeEditPart extends AbstractDiagramEdgeEditPart implements IStyleEditPart{

	public EdgeEditPart(View view) {
		super(view);
	}
	
	public DragTracker getDragTracker(Request request) {
        return getParent().getDragTracker(request);
    }
	
	@Override
	protected Connection createConnectionFigure() {
		Figure figure = new EdgePipeConnection();
		return (Connection) figure;
	}
	
}


And the EdgePipeConnection:

public class EdgePipeConnection extends PolylineConnectionEx {

	// offset X
	private static int OFFSET_X = 70;

	// offset Y
	private static int OFFSET_Y = 0;

	// list of precision points
	private List<PrecisionPoint> connectionPoints = new ArrayList<PrecisionPoint>();

	// bend x
	private int bend_X;
	// bend y
	private int bend_Y;

	// counter for queue entries
	private int queueEntries = 0;
...


Here I omit the source code for the EdgePipeConnection as 1) it is a lot and 2) it works in a GEF implementation.

So when I create edges in Sirius I got the aforementioned Exception. Any ideas why?

Thanks very much for your help.

Cheers,
Will


Research Associate
Department of Computer Science
University of York
Re: Customising Edge styles [message #1776353 is a reply to message #1776320] Wed, 15 November 2017 15:32 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
What is the complete stack? I don't see your part called.
By "when creating an edge" you mean when using a tool from the palette to create an edge between two nodes?


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Wed, 15 November 2017 15:34]

Report message to a moderator

Re: Customising Edge styles [message #1776355 is a reply to message #1776353] Wed, 15 November 2017 15:37 Go to previous messageGo to next message
Ran Wei is currently offline Ran WeiFriend
Messages: 119
Registered: September 2012
Location: York, UK
Senior Member
Hi Pierre,

In TreeEditPartProvider, when getEdgeEditPartClass() is called, I provide EdgeEditPart, which in turn creates an EdgePipeConnection.

When EdgePipeConnection extends PolylineConnection, the edge can be drawn, just it is now allowed by Sirius.

When EdgePipeConnection extends PolylineConnectionEx , I had the previous exception.

By when creating an edge, i meant when using a tool from the palette to create an edge between two nodes, that is correct.

Thank you very much for your help.

Cheers,
Will


Research Associate
Department of Computer Science
University of York
Re: Customising Edge styles [message #1776358 is a reply to message #1776355] Wed, 15 November 2017 16:34 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
You must add this code in your part:

/**
     * @was-generated
     */
    protected boolean addFixedChild(EditPart childEditPart) {
        if (childEditPart instanceof DEdgeNameEditPart) {
            ((DEdgeNameEditPart) childEditPart).setLabel(getPrimaryShape().getFigureViewEdgeNameFigure());
            return true;
        }
        if (childEditPart instanceof DEdgeEndNameEditPart) {
            ((DEdgeEndNameEditPart) childEditPart).setLabel(getPrimaryShape().getFigureViewEndEdgeNameFigure());
            return true;
        }
        if (childEditPart instanceof DEdgeBeginNameEditPart) {
            ((DEdgeBeginNameEditPart) childEditPart).setLabel(getPrimaryShape().getFigureViewBeginEdgeNameFigure());
            return true;
        }
        return false;
    }

    /**
     * @was-generated
     */
    public AbstractDiagramEdgeEditPart.ViewEdgeFigure getPrimaryShape() {
        return (AbstractDiagramEdgeEditPart.ViewEdgeFigure) getFigure();
    }

    /**
     * @was-generated
     */
    @Override
    protected void addChildVisual(EditPart childEditPart, int index) {
        if (addFixedChild(childEditPart)) {
            return;
        }
        super.addChildVisual(childEditPart, -1);
    }


It handle labels parts of the edge.

Regards,

Pierre


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Customising Edge styles [message #1776360 is a reply to message #1776358] Wed, 15 November 2017 16:39 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
In fact, you should try to extends DEdgeEditPart instead of AbstractDiagramEdgeEditPart and just override the createConnectionFigure methods.

You customize only the figure so you want to keep others behaviors brought by policies. I am not completely sure it is all compatible with a different figure. But you will know really soon :)

Regards,

Pierre


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Customising Edge styles [message #1776440 is a reply to message #1776360] Thu, 16 November 2017 13:12 Go to previous messageGo to next message
Ran Wei is currently offline Ran WeiFriend
Messages: 119
Registered: September 2012
Location: York, UK
Senior Member
Hi Pierre,

Many thanks for your suggestions. As expected, new issues arise. For the editpart, instead of extending DEdgeEditPart, I extended AbstractExtendableEdgeEditPart, which seems to be the right choice as DEdgeEditPart gives me warnings saying it is not supposed to be extended.

However, I have a ClassCastException after the change:

java.lang.ClassCastException: tree.example.extension.edit.part.EdgePipeConnection cannot be cast to org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramEdgeEditPart$ViewEdgeFigure
at org.eclipse.sirius.diagram.ui.internal.edit.parts.DEdgeEditPart.getPrimaryShape(DEdgeEditPart.java:113)
at org.eclipse.sirius.diagram.ui.graphical.edit.part.specific.AbstractExtendableEdgeEditPart.installRouter(AbstractExtendableEdgeEditPart.java:86)
at org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart.addNotify(ConnectionEditPart.java:1084)
at org.eclipse.gef.editparts.AbstractConnectionEditPart.setParent(AbstractConnectionEditPart.java:268)
at org.eclipse.gef.editparts.AbstractConnectionEditPart.setSource(AbstractConnectionEditPart.java:282)
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.addSourceConnection(AbstractGraphicalEditPart.java:260)
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.refreshSourceConnections(AbstractGraphicalEditPart.java:697)


Any ideas if we can go around this problem?

Cheers,
Will


Research Associate
Department of Computer Science
University of York
Re: Customising Edge styles [message #1776462 is a reply to message #1776440] Thu, 16 November 2017 15:24 Go to previous message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
Hi,

AbstractExtendableEdgeEditPart extends DEdgeEditPart that is internal that is why you have warnings.
So it does not change anything. You should keep DEdgeEditPart

Internal means we can do some changes that will break your code if you use the internal code.
If this is ok for your project you can use it. If you want to industrialize it then you should extend AbstractDiagramEdgeEditPart and add the code that was missing and causing exception and that I gave you in previous message.

In both case you must change the method getPrimaryShape() to return your figure type.
Your figure must also provide label figures like ViewEdgeFigure with methods called by your addFixedChild(EditPart) method (getFigureViewEdgeNameFigure,getFigureViewEndEdgeNameFigure,getFigureViewBeginEdgeNameFigure).
You can just copy the code handling these labels in your figure.

Anyway there is no guarantee that you will not be blocked completely at some point because Sirius architecture does not allow you to do what you seek.
What you are doing is out of the box and can lead to nothing.

Regards,

Pierre


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Thu, 16 November 2017 15:26]

Report message to a moderator

Previous Topic:Widget: Text
Next Topic:Create Edge in Sirius like the Reference Relation in ecore editor
Goto Forum:
  


Current Time: Sat Apr 20 01:48:41 GMT 2024

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

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

Back to the top