Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » CustomStyle EditPart Size Change
CustomStyle EditPart Size Change [message #1790251] Thu, 07 June 2018 13:36 Go to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 197
Registered: February 2014
Senior Member
Hello,
(Note that I have posted this in GEF forum and got not working reply, so I thought maybe you got some experience on this)

I have a customStyle node. The edit part code for my custom style node is shown below. The custom style node has an image (the train area) as its primary shape. However, the size of the node edit part does not auto grow or shrink to the size of its primary shape. I have tried to set the size(layoutconstraints(bounds)) in refreshVisual method but it throws write transaction exception. I have tried to set the figure size , content pane size , and every thing! but still can not resize the figure's client area.

So, there are a few main concerns about customStyles:

1. Can we change the figure's initial size at all ?
2. More importantly, can we set a node's initial position ? I tried https://wiki.eclipse.org/index.php?title=Graphical_Modeling_Framework/Tips&redirect=no#Setting_Initial_Position_of_a_Node ,but it only works on diagram reopen and not on node creation.
3. When I use customeStyle, it does not show the label of the node (when set to node and not the border). Is it the intended behaviour?


index.php/fa/33033/0/


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) {
        	ImageDescriptor imageDescriptorFromPlugin;
        	Image image;
        	
        	imageDescriptorFromPlugin = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
					"images/shapes/shape_Train_Left45.png");
			image = imageDescriptorFromPlugin.createImage();

            this.getPrimaryShape().setImage(image);
        }
    }

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


Thanks,
Parsa
  • Attachment: train.png
    (Size: 7.65KB, Downloaded 199 times)

[Updated on: Thu, 07 June 2018 19:33]

Report message to a moderator

Re: CustomStyle EditPart Size Change [message #1790370 is a reply to message #1790251] Fri, 08 June 2018 17:12 Go to previous messageGo to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 197
Registered: February 2014
Senior Member
Note that I also used SiriusLayoutDataManager.INSTANCE.addData(new RootLayoutData(this, new Point(10, 10), new Dimension(200, 300))); on the edit part createFigure method to set its initial position but it says that LayoutDataManager is not designed for CustomStyles yet...

!MESSAGE This kind of diagram element (org.eclipse.sirius.diagram.business.internal.metamodel.spec.WorkspaceImageSpec) is not yet managed by the LayoutDataManager.

* this editpart is a workspaceimage, but the same thing for the customstyle is thrown.

Regards,
Parsa

[Updated on: Fri, 08 June 2018 17:34]

Report message to a moderator

Re: CustomStyle EditPart Size Change [message #1790374 is a reply to message #1790370] Fri, 08 June 2018 17:49 Go to previous message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 197
Registered: February 2014
Senior Member
OK , never mind, I could kind of making it happen by extending the refresh extension point (not sure if this is the best way though).

For ppl who might be interested:
/**
 */
public class GuideWayDiagramRefreshExtension implements IRefreshExtension {

	/**
	 * @see org.eclipse.sirius.business.api.refresh.IRefreshExtension#postRefresh(org.eclipse.sirius.DDiagram)
	 */
	public void postRefresh(DDiagram dDiagram_p) {
		for (DDiagramElement d : dDiagram_p.getDiagramElements()) {
			if (d.getTarget() instanceof Train) {
				SiriusLayoutDataManager.INSTANCE
						.addData(new RootLayoutData(d, new Point(500, 10), new Dimension(-1, -1)));
			}

		}

	}

	@Override
	public void beforeRefresh(DDiagram dDiagram) {
		// TODO Auto-generated method stub

	}
Previous Topic:Provide Advanced Custom Widget to odesign
Next Topic:Sirius Editor
Goto Forum:
  


Current Time: Sat Nov 17 23:12:12 GMT 2018

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

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

Back to the top