Custom Editpart IFigure children fall apart [message #652306] |
Thu, 03 February 2011 14:24 |
Patrick 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:
Here is the custom edit part. I defined an ellipse in the gmf model to hold the inner elements (primaryEllipse).
Thanks
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();
}
}
|
|
|
Re: Custom Editpart IFigure children fall apart [message #655430 is a reply to message #652306] |
Sun, 20 February 2011 20:27 |
Patrick 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
|
|
|
Powered by
FUDForum. Page generated in 0.03108 seconds