Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Move diagram along with text
Move diagram along with text [message #1721403] Wed, 27 January 2016 07:51 Go to next message
Kailas Patil is currently offline Kailas PatilFriend
Messages: 5
Registered: January 2016
Junior Member
i am try to draw diagram with name on bottom ,but when i move my diagram ,name not movie along with it.
my Code :
{

final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
gaService.setLocationAndSize(invisibleRectangle, context.getX(), context.getY(), width, height);

ellipse = gaService.createPlainEllipse(invisibleRectangle);
ellipse.setStyle(StyleUtil.getStyleForStartClass(featureSupport.getCustomDiagram()));
gaService.setLocationAndSize(ellipse, 0, 0, width, height);




final Text text = gaService.createPlainText(containerDecorator, "Script");
text.setStyle(StyleUtil.getStyleForEClassText(featureSupport.getCustomDiagram()));
text.setFont(gaService.manageDefaultFont(featureSupport.getCustomDiagram(), false, true));
gaService.setLocationAndSize(text, context.getX()-15, context.getY()+30, decoratorWidth, decoratorHeight);

featureSupport.customLink(containerShape, addedClass);
featureSupport.customLink(containerDecorator, addedClass);


}
Re: Move diagram along with text [message #1721472 is a reply to message #1721403] Wed, 27 January 2016 16:08 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi,

sorry, but I'm not sure if I exactly got what you intend with the coding above, e.g. what is containerDecorator and how is it linked to any of the other objects?

In general when you have a container shape, all child shapes and graphics algorithms will be moved when you move the container. When you have a separate shape (something outside the container hierarchy) then you will have to write a custom move shape feature theat will adapt the coordinates of the the external shape when you move the container.

HTH,
Michael
Re: Move diagram along with text [message #1721550 is a reply to message #1721472] Thu, 28 January 2016 09:22 Go to previous messageGo to next message
Kailas Patil is currently offline Kailas PatilFriend
Messages: 5
Registered: January 2016
Junior Member
Hi Michael

i am try using shape which contain text graphic algorithms but it underlapped with ellipse.
Ellipse ellipse;

{

final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
gaService.setLocationAndSize(invisibleRectangle, context.getX(), context.getY(), width, height);

ellipse = gaService.createPlainEllipse(invisibleRectangle);
ellipse.setStyle(StyleUtil.getStyleForStartClass(featureSupport.getCustomDiagram()));
gaService.setLocationAndSize(ellipse, 0, 0, width, height);

if (addedClass.eResource() == null) {
featureSupport.getCustomDiagram().eResource().getContents().add(addedClass);
}



featureSupport.customLink(containerShape, addedClass);

}
{
final Shape shape = peCreateService.createShape(containerShape, true);
final Text text = gaService.createPlainText(shape, addedClass.getName());
text.setStyle(StyleUtil.getStyleForEClassText(featureSupport.getCustomDiagram()));
text.setFont(gaService.manageDefaultFont(featureSupport.getCustomDiagram(), false, true));

gaService.setLocationAndSize(text, context.getX() - 22, context.getY() + 33, decoratorWidth,
decoratorHeight);
featureSupport.customLink(shape, addedClass);

}

thats why i make another container with name containerDecorator. for just simplify i want diagram with name , but invisible rectangle of diagram not contain a name ,name should be independent from invisible rectangle
Re: Move diagram along with text [message #1721701 is a reply to message #1721550] Fri, 29 January 2016 10:06 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Ok, if the Text containing the name should be independent you will need to create your own move feature for the diagram (based upon DefaultMoveShapeFeature) and call its super method to do the move for the diagram shape itself. After that you will need to move your test shape containing the name as well, probably with the same offset as the diagram moved.

HTH,
Michael
Re: Move diagram along with text [message #1721718 is a reply to message #1721701] Fri, 29 January 2016 12:29 Go to previous messageGo to next message
Kailas Patil is currently offline Kailas PatilFriend
Messages: 5
Registered: January 2016
Junior Member
Thanks Michael
Re: Move diagram along with text [message #1721764 is a reply to message #1721718] Fri, 29 January 2016 22:52 Go to previous messageGo to next message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
You can look at my code for inspiration:
public class MoveElementFeature extends DefaultMoveShapeFeature {

	public MoveElementFeature(IFeatureProvider fp) {
		super(fp);
	}

	@Override
	public boolean canMoveShape(IMoveShapeContext context) {
		if(context.getSourceContainer() == null) return false;
		if(context.getSourceContainer().equals(context.getTargetContainer())) return true;

		Shape shape = context.getShape();
		ContainerShape targetShape = null;

		// can move on label place
		for(EObject o : shape.getLink().getBusinessObjects())
			if(o instanceof Shape && Graphiti.getPeService().getPropertyValue((Shape) o, SicConstants.LABEL_PROPERTY) != null)
				targetShape = (ContainerShape) o;
		if(targetShape != null && targetShape.equals(context.getTargetContainer())) return true;

		return false;
	}

	@Override
	protected void preMoveShape(IMoveShapeContext context) {
		super.preMoveShape(context);
	}

	@Override
	public void moveShape(IMoveShapeContext context) {
		Shape shape = context.getTargetContainer();
		if(Graphiti.getPeService().getPropertyValue(shape, SicConstants.LABEL_PROPERTY) != null) {
			MoveShapeContext c = (MoveShapeContext) context;
			c.setTargetContainer(shape.getContainer());
			c.setDeltaX(c.getDeltaX() + shape.getGraphicsAlgorithm().getX());
			c.setDeltaY(c.getDeltaY() + shape.getGraphicsAlgorithm().getY());
			c.setX(c.getX() + shape.getGraphicsAlgorithm().getX());
			c.setY(c.getY() + shape.getGraphicsAlgorithm().getY());
		}
		super.moveShape(context);
	}

	@Override
	protected void postMoveShape(final IMoveShapeContext context) {
		Shape shape = context.getShape();

		// move also label
		for (EObject o : shape.getLink().getBusinessObjects()) {
			if (o instanceof Shape && Graphiti.getPeService().getPropertyValue((Shape)o, SicConstants.LABEL_PROPERTY) != null) {
				ContainerShape textContainerShape = (ContainerShape)o;
				int dx = context.getDeltaX();
				int dy = context.getDeltaY();

				textContainerShape.getGraphicsAlgorithm().setX(textContainerShape.getGraphicsAlgorithm().getX() + dx);
				textContainerShape.getGraphicsAlgorithm().setY(textContainerShape.getGraphicsAlgorithm().getY() + dy);
			}
		}

		super.postMoveShape(context);
	}
}


1. MoveElementFeature handle all object with label.
2. In canMoveShape I enable to put shape where the label is as label will move from its place.
3. In moveShape I handle above situation.
4. In postMoveShape I move linked label.

Marek

[Updated on: Fri, 29 January 2016 22:53]

Report message to a moderator

Re: Move diagram along with text [message #1721858 is a reply to message #1721764] Mon, 01 February 2016 06:15 Go to previous message
Kailas Patil is currently offline Kailas PatilFriend
Messages: 5
Registered: January 2016
Junior Member
Thanks Marek , it's really helpful.
Previous Topic:Cancelling model changes done in a CustomFeature
Next Topic:can not save connection Feature
Goto Forum:
  


Current Time: Fri Apr 19 23:02:43 GMT 2024

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

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

Back to the top