Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d70f62d326e085e0127e0ccc83c4c3d1940045b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package org.eclipse.papyrus.infra.gmfdiag.common.linklf.editpolicies;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart;
import org.eclipse.gmf.runtime.diagram.ui.internal.commands.SetConnectionBendpointsCommand;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.RelativeBendpoints;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint;
import org.eclipse.papyrus.infra.gmfdiag.common.linklf.AbsoluteBendpointsConvention;

@SuppressWarnings("restriction")
public class SetAbsoluteBendpointsCommand extends SetConnectionBendpointsCommand {

	public SetAbsoluteBendpointsCommand(TransactionalEditingDomain editingDomain) {
		super(editingDomain);
	}

	public void setEdge(ConnectionEditPart editPart) {
		View edge = editPart.getNotationView();
		setEdgeAdapter(new EObjectAdapter(edge));
	}

	public void setNewPointList(PointList newPointList) {
		//our implementation does not use the refPoints, but super class still needs them != null
		super.setNewPointList(newPointList, new Point(), new Point());
	}

	@Override
	public void setEdgeAdapter(IAdaptable edgeAdapter) {
		super.setEdgeAdapter(edgeAdapter);
	}

	protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
		Assert.isNotNull(getNewPointList());
		Assert.isNotNull(getSourceRefPoint());
		Assert.isNotNull(getTargetRefPoint());

		Edge edge = (Edge)getEdgeAdaptor().getAdapter(Edge.class);
		Assert.isNotNull(edge);

		setAbsoluteBendpoints(edge, getNewPointList());

		return CommandResult.newOKCommandResult();
	}

	public static void setAbsoluteBendpoints(Edge edge, PointList newPointList) {
		List<RelativeBendpoint> newBendpoints = new ArrayList<RelativeBendpoint>();
		int numOfPoints = newPointList.size();
		for(short i = 0; i < numOfPoints; i++) {
			//Dimension s = getNewPointList().getPoint(i).getDifference(getSourceRefPoint());
			//Dimension t = getNewPointList().getPoint(i).getDifference(getTargetRefPoint());
			//newBendpoints.add(new RelativeBendpoint(s.width, s.height, t.width, t.height));
			newBendpoints.add(AbsoluteBendpointsConvention.createAbsoluteBendpointStoredAsRelative(newPointList.getPoint(i)));
		}

		StringBuffer toString = new StringBuffer();
		boolean atLeastOne = false;
		for(RelativeBendpoint next : newBendpoints) {
			if(atLeastOne) {
				toString.append(" - ");
			}
			toString.append(next.convertToString());
			atLeastOne = true;
		}
		System.err.println("SetAbsBendpoints: " + toString);

		RelativeBendpoints points = (RelativeBendpoints)edge.getBendpoints();
		points.setPoints(newBendpoints);
	}

	@Override
	public String toString() {
		return "SAbsBC[$" + System.identityHashCode(this) + "]";
	}

}

Back to the top