Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Nodes Customization with Java(Obtain customized figures style with Java code)
Nodes Customization with Java [message #1768412] Tue, 18 July 2017 12:40 Go to next message
Estibaliz Amparan is currently offline Estibaliz AmparanFriend
Messages: 7
Registered: July 2017
Junior Member
Hello,

I want to customize my nodes with complex styles like rhomboid and trapeze (I do not want to add "workspace image" format). I found this page https://www.eclipse.org/sirius/doc/developer/extensions-provide_custom_style.html and after reading it I understand that the second way is the most adjustable to my necessities. My issue is that I am not sure how I have to proceed.


First step: I select right click in my Node >> New Style >> Custom Style. (Green rectangle appears)

Second step: I add an Extension org.eclipse.gmf.runtime.diagram.ui.edipartProviders >> Priority: Highest. Then I create a class file and copy/paste all this code:

public class DiagSeqEditPartProvider extends AbstractEditPartProvider {
    @Override
    protected Class getNodeEditPartClass(View view) {
        if (view.getElement() instanceof CustomStyle) {
            CustomStyle customStyle = (CustomStyle) view.getElement();
            if (customStyle.getId().equals(DiagSeqConstants.INSTANCE_ROLE_STYLE_ID)) {
                return InstanceRoleStyleEditPart.class;
            }
        }
        return super.getNodeEditPartClass(view);
    }
}

But, a lot of errors appear in it and I am sure that I have some step missing before.

Could anyone help me please?
Thank you very much
Re: Nodes Customization with Java [message #1768471 is a reply to message #1768412] Wed, 19 July 2017 09:02 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
Hi,

If I understand correctly you have build error caused by missing dependencies.
You must add org.eclipse.gmf.runtime.diagram.ui and org.eclipse.sirius.diagram.ui as dependency required by your plugin.
Also you have to create the InstanceRoleStyleEditPart class described in the documentation that will provide the custom figure. You will have to modify this class to provide your own rhomboid or trapeze figure.

Regards,

Pierre


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Nodes Customization with Java [message #1768475 is a reply to message #1768471] Wed, 19 July 2017 09:08 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
You also have to create the DiagSeqConstants.INSTANCE_ROLE_STYLE_ID that point to the id you use in the custom style on the odesign.

Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Nodes Customization with Java [message #1768675 is a reply to message #1768475] Fri, 21 July 2017 10:14 Go to previous messageGo to next message
Estibaliz Amparan is currently offline Estibaliz AmparanFriend
Messages: 7
Registered: July 2017
Junior Member
Hello,

First of all, thank you very much for your quick answer.

I am trying to copy the sample of the page mentioned above to make a proof of concept. However, I cannot achieve it.
I attach some screen shoots of the steps I am following. Maybe in this way you can find out the mistakes that I made.

Add Custom Style in Employee Node (odesign file). ID: EMPLOYEE_ID
odesign.png

DiagSeqEditPartProvider Class: DiagSeqConstants.INSTANCE_ROLE_STYLE_ID replaced by EMPLOYEE_ID
DiagSeqEditPartProvider.jpg

InstanceRoleStyleEditPart Class:

package org.eclipse.gmf.runtime.diagram.ui.editparts;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ImageFigure;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.Request;
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.sirius.diagram.CustomStyle;
import org.eclipse.sirius.diagram.DNode;
import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractNotSelectableShapeNodeEditPart;
import org.eclipse.sirius.diagram.ui.edit.api.part.IStyleEditPart;
import org.eclipse.sirius.diagram.ui.tools.api.figure.AirStyleDefaultSizeNodeFigure;
import org.eclipse.sirius.viewpoint.SiriusPlugin;

public class InstanceRoleStyleEditPart extends AbstractNotSelectableShapeNodeEditPart
implements IStyleEditPart
{

    /**
     * the content pane.
     */
    protected IFigure contentPane;

    /**
     * the primary shape.
     */
    protected ImageFigure primaryShape;

    /**
     * Create a new {@link ChangingImageEditPart}.
     *
     * @param view
     *            the view.
     */
    public InstanceRoleStyleEditPart(View view) {
        super(view);
    }

    public DragTracker getDragTracker(Request request) {
        return getParent().getDragTracker(request);
    }

    protected NodeFigure createNodeFigure() {
        NodeFigure figure = createNodePlate();
        figure.setLayoutManager(new XYLayout());
        IFigure shape = createNodeShape();
        figure.add(shape);
        contentPane = setupContentPane(shape);
        return figure;
    }

    private NodeFigure createNodePlate() {
        DefaultSizeNodeFigure result = new AirStyleDefaultSizeNodeFigure(getMapMode().DPtoLP(40), getMapMode().DPtoLP(40));
        return result;
    }

    /**
     * Create the instance role figure.
     *
     * @return the created figure.
     */
    protected ImageFigure createNodeShape() {
        if (primaryShape == null) {
            primaryShape = new ImageFigure();
        }
        return primaryShape;
    }

    /**
     * Return the instance role figure.
     *
     * @return the instance role figure.
     */
    public ImageFigure getPrimaryShape() {
        return primaryShape;
    }

    /**
     * Default implementation treats passed figure as content pane. Respects
     * layout one may have set for generated figure.
     *
     * @param nodeShape
     *            instance of generated figure class
     * @return the figure
     */
    protected IFigure setupContentPane(IFigure nodeShape) {
        return nodeShape; // use nodeShape itself as contentPane
    }

    public IFigure getContentPane() {
        if (contentPane != null) {
            return contentPane;
        }
        return super.getContentPane();
    }

    protected void refreshVisuals() {
        CustomStyle customStyle = (CustomStyle) this.resolveSemanticElement();
        if (customStyle.eContainer() instanceof DNode) {
            this.getPrimaryShape().setImage(SiriusPlugin.getDefault().getBundleImage((DNode) customStyle.eContainer()).getName());
        }
    }

    protected void createDefaultEditPolicies() {
        // empty.
    }
}


In the last lines, this code has an error.
Error.png


Thank you
Re: Nodes Customization with Java [message #1768685 is a reply to message #1768675] Fri, 21 July 2017 14:08 Go to previous message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
Yes the example is not up to date.
Replace SiriusPlugin.getDefault().getBundleImage((DNode) customStyle.eContainer()).getName() by
@Override
    protected void refreshVisuals() {
        CustomStyle customStyle = (CustomStyle) this.resolveSemanticElement();
        if (customStyle.eContainer() instanceof DNode) {
            ImageDescriptor imageDescriptorFromPlugin = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "/icons/myIcon.png");
            this.getPrimaryShape().setImage(imageDescriptorFromPlugin.createImage());
        }
    }


where "/icons/myIcon.png" is the path to your icon in your plugin. And be sure that the folders of your path are ticked in the build section of your manifest.mf

Also your EMPLOYEE_ID value in DiagSeqEditPartProvider must be set to the value used in your odesign:
String EMPLOYEE_ID="EMPLOYEE_ID"


Regards


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

[Updated on: Fri, 21 July 2017 14:10]

Report message to a moderator

Previous Topic:Custom widget control description identifier is always null in Sirius 5.0
Next Topic:Add multi-touch gestures to Sirius
Goto Forum:
  


Current Time: Thu Jan 21 12:52:36 GMT 2021

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

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

Back to the top