Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Extending Square Edit Part
Extending Square Edit Part [message #1787107] Fri, 18 May 2018 20:13 Go to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 193
Registered: February 2014
Senior Member
Hi,

There is a tutorial on how to create custom styles and provide our own edit part for it using extensions https://www.eclipse.org/sirius/doc/developer/extensions-provide_custom_style.html

However, the tutorial shows how to set an image for the figure. What if we don't want to set an image for it. Let's say I just want to have the same style as the Sirius Square style for a node but with more control over it that what the Sirius offers.

Should I extend SquareEditPart and work on it? Is there any example of such situation ?

P.S. My whole goal is to create a Polygon (not a square) as I read somewhere that polygons are the only rotatable shapes. But I though maybe starting with simple Square should be fine also.

Thanks,
Parsa

[Updated on: Fri, 18 May 2018 21:16]

Report message to a moderator

Re: Extending Square Edit Part [message #1787221 is a reply to message #1787107] Tue, 22 May 2018 09:43 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 238
Registered: July 2009
Senior Member
Hello,

Yes, you can extend SquareEditPart and customize what you want.
For information, in the Sirius development team, there is no test or POC to offer the end-user the capability to rotate a figure.
We are interested about your investigation. Feel free to exchange about it here.

Best regards,

Laurent


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Extending Square Edit Part [message #1787261 is a reply to message #1787221] Tue, 22 May 2018 22:17 Go to previous messageGo to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 193
Registered: February 2014
Senior Member
Hi Laurent,

Thanks for the reply. Currently, I have a Sqaure style in my design file for the Platform Node. In my editpart extension as you can see below, I am trying to return my custom Square editpart provider. But, it is not functioning as it should be. Do you have any idea ? Please note that, the Square that the Sirius is giving me is fine and nice, all I'm trying to do is to extend what Sirius is giving to have more control over the edit part for maybe some day in the future!
public class CustomEditPartProvider extends AbstractEditPartProvider {

	String TrainCustomStyleID = "org.polarsys.capella.vp.guidewayscenario.TrainCustomStyle";

	@Override
	protected Class getNodeEditPartClass(View view) {
		if (view.getElement() instanceof CustomStyle) {
			CustomStyle customStyle = (CustomStyle) view.getElement();
			if (customStyle.getId().equals(TrainCustomStyleID)) {
				return CustomEditPartForTrain.class;
			}
		}

		if (view.getElement() instanceof DNodeSpec) {
			if (((DNodeSpec) view.getElement()).getTarget() instanceof Platform)
				return CustomSquareEditPartForPlatForm.class;

		}
		return super.getNodeEditPartClass(view);

	}
}


public class CustomSquareEditPartForPlatForm extends SquareEditPart {

	public CustomSquareEditPartForPlatForm(View view) {
		super(view);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	protected void refreshVisuals() {
		// TODO Auto-generated method stub
		super.refreshVisuals();
		
	}

}

index.php/fa/32889/0/

Thanks,
Parsa
  • Attachment: Capture.PNG
    (Size: 2.02KB, Downloaded 70 times)

[Updated on: Tue, 22 May 2018 22:25]

Report message to a moderator

Re: Extending Square Edit Part [message #1787305 is a reply to message #1787261] Wed, 23 May 2018 13:24 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 238
Registered: July 2009
Senior Member
Hi,

In debug mode, is the method CustomEditPartProvider.getNodeEditPartClass() called? If not, I think that the CustomEditPartProvider is not correctly declared.

Regards,

Laurent


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Extending Square Edit Part [message #1787322 is a reply to message #1787305] Wed, 23 May 2018 17:25 Go to previous messageGo to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 193
Registered: February 2014
Senior Member
Thanks Laurent, I am now trying to achieve it by declaring customstyle and set its background image. The code below is my class for CustomStyle (which is what I got from the Sirius example on editpart provider extensions). It works OK but has one issue :( I can't autosize the parent client area for the image. If you see in the image that is attached, the shape is smaller than the client area. I'd like to auto fit the figure's client area and the shape with each other.Do you have any suggestion for this?
index.php/fa/32892/0/


I have also tried ((GraphicalEditPart) this.getParent()).setLayoutConstraint(this.getPrimaryChildEditPart(), this.getFigure(), new Rectangle(0, 0, getPrimaryShape().getPreferredSize().width, getPrimaryShape().getPreferredSize().height)); which I found from UMLDesigner, but didn't help.

public class CustomEditPartForTrain extends AbstractNotSelectableShapeNodeEditPart implements IStyleEditPart {

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

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

	/**
	 * Create a new {@link ChangingImageEditPart}.
	 *
	 * @param view
	 *            the view.
	 */
	public CustomEditPartForTrain(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 MyAttributeBasedImageFigure createNodeShape() {
		if (primaryShape == null) {

			primaryShape = new MyAttributeBasedImageFigure();
		}
		return primaryShape;
	}

	/**
	 * Return the instance role figure.
	 *
	 * @return the instance role figure.
	 */
	public MyAttributeBasedImageFigure 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) {
			

			EObject train = ((DNode) customStyle.eContainer()).getTarget();
			if (train instanceof Train) {
//	           ((GraphicalEditPart) this.getParent()).setLayoutConstraint(this.getPrimaryChildEditPart(), this.getFigure(), new Rectangle(0, 0, getPrimaryShape().getPreferredSize().width, getPrimaryShape().getPreferredSize().height));

			}
		}

	}

	@Override
	protected void addSemanticListeners() {
		CustomStyle customStyle = (CustomStyle) this.resolveSemanticElement();
		if (customStyle.eContainer() instanceof DNode) {
			EObject train = ((DNode) customStyle.eContainer()).getTarget();
			if (train instanceof Train) {
				addListenerFilter(this.elementGuid, this, train);
			}
		}

		super.addSemanticListeners();
	}

	@Override
	protected void handleNotificationEvent(Notification notification) {
		if (notification.getNotifier() instanceof Train) {
			getPrimaryShape().updateFace();
		}
		super.handleNotificationEvent(notification);
	}

	protected void createDefaultEditPolicies() {

	}
}

  • Attachment: train.png
    (Size: 7.65KB, Downloaded 46 times)
Re: Extending Square Edit Part [message #1787441 is a reply to message #1787322] Fri, 25 May 2018 12:24 Go to previous message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 238
Registered: July 2009
Senior Member
Sorry but, I'll not have time to analysis more this problem.
And I have no idea that comes directly to me.


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Customization of sirius editor tab bar and palette toolbar
Next Topic:Reconnecting Source Problems
Goto Forum:
  


Current Time: Wed Sep 26 08:25:07 GMT 2018

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

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

Back to the top