Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Custom Editpart IFigure children fall apart
Custom Editpart IFigure children fall apart [message #652306] Thu, 03 February 2011 14:24 Go to next message
Patrick  is currently offline Patrick Friend
Messages: 10
Registered: December 2010
Junior Member
Hi,

I've got another problem that seems easy to me but i can't figure out what is going on here. I'm creating a custom edit part where i add two polylineShapes to an ellipse. The inner ellipse behaves well, but the polylines dont want to stick to their parent. Either they open up at the top left corner of the whole diagram, or, if i set their position to their parents, they stay there stubborn.

I want to acomplish the two types of circular final nodes shown in this diagram:
http://www.gentleware.com/fileadmin/media/archives/userguides/poseidon_users_guide/images/spec_initialfinalnodes.png

Here is the custom edit part. I defined an ellipse in the gmf model to hold the inner elements (primaryEllipse).

Thanks Smile

public class CustomStopNodeEditPart extends StopNodeEditPart {

	public CustomStopNodeEditPart(View view) {
		super(view);
	}
	
	private void updateFigure() {
		
		StopNode stopnode = (StopNode) ((View) getModel()).getElement();
		Ellipse primaryEllipse = ((Ellipse) getPrimaryShape());

		if (stopnode.isFlowStopOnly()) {
			primaryEllipse.removeAll();
			primaryEllipse.setLayoutManager(null);
			primaryEllipse.setForegroundColor(ColorConstants.black);
			
			Polyline flowFinalNodeSlash0 = new Polyline();
			flowFinalNodeSlash0.addPoint(new Point(getMapMode().DPtoLP(4), getMapMode().DPtoLP(4)));
			flowFinalNodeSlash0.addPoint(new Point(getMapMode().DPtoLP(19), getMapMode().DPtoLP(19)));
			flowFinalNodeSlash0.setLineWidth(1);
			flowFinalNodeSlash0.setForegroundColor(ColorConstants.black);

			primaryEllipse.add(flowFinalNodeSlash0);

			Polyline flowFinalNodeBackSlash0 = new Polyline();
			flowFinalNodeBackSlash0.addPoint(new Point(getMapMode().DPtoLP(4), getMapMode().DPtoLP(19)));
			flowFinalNodeBackSlash0.addPoint(new Point(getMapMode().DPtoLP(19), getMapMode().DPtoLP(4)));
			flowFinalNodeBackSlash0.setLineWidth(1);
			flowFinalNodeBackSlash0.setForegroundColor(ColorConstants.black);

			primaryEllipse.add(flowFinalNodeBackSlash0);
			
		}
		else {
			primaryEllipse.removeAll();
			
			GridLayout layoutThis = new GridLayout();
			layoutThis.numColumns = 1;
			layoutThis.makeColumnsEqualWidth = true;
			primaryEllipse.setLayoutManager(layoutThis);
			
			Ellipse stopNodeInnerEllipse0 = new Ellipse();
			stopNodeInnerEllipse0.setBackgroundColor(ColorConstants.black);
			stopNodeInnerEllipse0.setPreferredSize(new Dimension(getMapMode()
					.DPtoLP(15), getMapMode().DPtoLP(15)));
			stopNodeInnerEllipse0.setMaximumSize(new Dimension(getMapMode()
					.DPtoLP(15), getMapMode().DPtoLP(15)));
			stopNodeInnerEllipse0.setMinimumSize(new Dimension(getMapMode()
					.DPtoLP(15), getMapMode().DPtoLP(15)));

			GridData constraintStopNodeInnerEllipse0 = new GridData();
			constraintStopNodeInnerEllipse0.verticalAlignment = GridData.CENTER;
			constraintStopNodeInnerEllipse0.horizontalAlignment = GridData.CENTER;
			constraintStopNodeInnerEllipse0.horizontalIndent = 0;
			constraintStopNodeInnerEllipse0.horizontalSpan = 1;
			constraintStopNodeInnerEllipse0.verticalSpan = 1;
			constraintStopNodeInnerEllipse0.grabExcessHorizontalSpace = true;
			constraintStopNodeInnerEllipse0.grabExcessVerticalSpace = true;
			primaryEllipse.add(stopNodeInnerEllipse0, constraintStopNodeInnerEllipse0);
		
			}
	}
	
	@Override
	protected void handleNotificationEvent(Notification event) {
		super.handleNotificationEvent(event);
		updateFigure();
	}

}



icon1.gif  Re: Custom Editpart IFigure children fall apart [message #655430 is a reply to message #652306] Sun, 20 February 2011 20:27 Go to previous message
Patrick  is currently offline Patrick Friend
Messages: 10
Registered: December 2010
Junior Member
The solution was quite easy but took me another few hours. Kind of stupid mistake...

The error was here:
Polyline flowFinalNodeSlash0 = new Polyline();


New Code:
PolylineShape flowFinalNodeSlash0 = new PolylineShape();


It has to be a PolylineShape. Although have almost same inheritance tree they have different behaviour. Polyline takes a PointList and it is drawn with absolute points. So they stayed at this position all the time, although they were children of the ellipse.

PolylineShape also takes a PointList but they are interpreted as relative points. So it behaves well and stays with its parent.

[Updated on: Sun, 20 February 2011 20:28]

Report message to a moderator

Previous Topic:Change source/target of a Connection
Next Topic:GMF: annoying popup window when creating connections
Goto Forum:
  


Current Time: Fri Apr 26 22:04:17 GMT 2024

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

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

Back to the top