Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 59813c8635b6558ff7afed67cd2a0548cce6dcdf (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
/*****************************************************************************
 * Copyright (c) 2016 CEA LIST and others.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   CEA LIST - Initial API and implementation
 *   
 *****************************************************************************/

package org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.notation.Bounds;
import org.eclipse.gmf.runtime.notation.DecorationNode;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.IdentityAnchor;
import org.eclipse.gmf.runtime.notation.LayoutConstraint;
import org.eclipse.gmf.runtime.notation.Location;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.AutomaticNotationEditPolicy;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.IdentityAnchorHelper;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
import org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin;
import org.eclipse.papyrus.uml.diagram.sequence.util.LogOptions;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ExecutionSpecification;

/**
 * this class is used to connect a node to the grid
 * X, Y, X+Width, Y+HEIGHT
 *
 */
public class ConnectRectangleToGridEditPolicy extends ConnectToGridEditPolicy implements AutomaticNotationEditPolicy, NotificationListener, IGrillingEditpolicy {

	protected GrillingEditpart grillingCompartment = null;

	public static String CONNECT_TO_GRILLING_MANAGEMENT = "CONNECT_TO_GRILLING_MANAGEMENT"; //$NON-NLS-1$

	protected DecorationNode rowStart = null;
	protected DecorationNode rowFinish = null;
	protected DecorationNode columnStart = null;
	protected DecorationNode columnFinish = null;
	protected int margin = 0;

	/**
	 * Constructor.
	 *
	 */
	public ConnectRectangleToGridEditPolicy() {
	}

	/**
	 * avoid to modify it directly, try to modify call of sub-methods: initListeningXXX
	 * 
	 * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#activate()
	 *
	 */
	@Override
	public void activate() {
		super.activate();
		getDiagramEventBroker().addNotificationListener(((EObject) getHost().getModel()), this);
		DiagramEditPart diagramEditPart = getDiagramEditPart(getHost());
		Node node = ((Node) ((GraphicalEditPart) getHost()).getNotationView());
		try {
			GridManagementEditPolicy grilling = (GridManagementEditPolicy) diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRID_MANAGEMENT);
			Node nodeContainer = (Node) (((GraphicalEditPart) getHost()).getNotationView()).eContainer();
			Element element = (Element) ((GraphicalEditPart) getHost()).resolveSemanticElement();
			if (grilling != null) {
				PrecisionRectangle p = NotationHelper.getAbsoluteBounds((Node) ((GraphicalEditPart) getHost()).getNotationView());
				initListeningRowStart(grilling, element, p);
				initListeningColumnStart(grilling, element, p);
				initListeningRowFinish(node, grilling, element, p);
				initListeningColumnFinish(node, grilling, element, p);
			}
		} catch (NoGrillElementFound e) {
			UMLDiagramEditorPlugin.log.error(e);
		}

	}

	/**
	 * this method is called during the activate
	 * It initialize a columnFinish and listen it
	 * 
	 * @param grilling
	 *            the grid manager that allow creating rows
	 * @param element
	 *            the semantic element
	 * @param bounds
	 *            the absolute position of the current node (the origin of the referencial is the diagram)
	 * @throws NoGrillElementFound
	 */
	protected void initListeningColumnFinish(Node node, GridManagementEditPolicy grilling, Element element, PrecisionRectangle bounds) throws NoGrillElementFound {
		columnFinish = grilling.createColumnTolisten(bounds.x + BoundForEditPart.getWidthFromView(node), element);
		getDiagramEventBroker().addNotificationListener(columnFinish, this);
	}

	/**
	 * this method is called during the activate
	 * It initialize a rowFinish and listen it
	 * 
	 * @param grilling
	 *            the grid manager that allow creating rows
	 * @param element
	 *            the semantic element
	 * @param bounds
	 *            the absolute position of the current node (the origin of the referential is the diagram)
	 * @throws NoGrillElementFound
	 */
	protected void initListeningRowFinish(Node node, GridManagementEditPolicy grilling, Element element, PrecisionRectangle bounds) throws NoGrillElementFound {
		rowFinish = grilling.createRowTolisten(bounds.y + BoundForEditPart.getHeightFromView(node) + margin, element);
		getDiagramEventBroker().addNotificationListener(rowFinish, this);
	}

	/**
	 * this method is called during the activate
	 * It initialize a ColumnStart and listen it
	 * 
	 * @param grilling
	 *            the grid manager that allow creating rows
	 * @param element
	 *            the semantic element
	 * @param bounds
	 *            the absolute position of the current node ( the origin of the referential is the diagram)
	 * @throws NoGrillElementFound
	 */
	protected void initListeningColumnStart(GridManagementEditPolicy grilling, Element element, PrecisionRectangle bounds) throws NoGrillElementFound {
		columnStart = grilling.createColumnTolisten(bounds.x(), element);
		getDiagramEventBroker().addNotificationListener(columnStart, this);
	}

	/**
	 * this method is called during the activate
	 * It initialize a rowStart and listen it
	 * 
	 * @param grilling
	 *            the grid manager that allow creating rows
	 * @param element
	 *            the semantic element
	 * @param bounds
	 *            position of the current node in absolute ( the origin is the diagram)
	 * @throws NoGrillElementFound
	 */
	protected void initListeningRowStart(GridManagementEditPolicy grid, Element element, PrecisionRectangle bounds) throws NoGrillElementFound {
		rowStart = grid.createRowTolisten(bounds.y + margin, element);
		getDiagramEventBroker().addNotificationListener(rowStart, this);
	}

	/*
	 * Gets the diagram event broker from the editing domain.
	 *
	 * @return the diagram event broker
	 */
	protected DiagramEventBroker getDiagramEventBroker() {
		TransactionalEditingDomain theEditingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
		if (null != theEditingDomain) {
			return DiagramEventBroker.getInstance(theEditingDomain);
		}
		return null;
	}


	/**
	 * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#deactivate()
	 *
	 */
	@Override
	public void deactivate() {
		getDiagramEventBroker().removeNotificationListener(((EObject) getHost().getModel()), this);
		if (rowStart != null) {
			getDiagramEventBroker().removeNotificationListener(rowStart, this);
		}
		if (columnStart != null) {
			getDiagramEventBroker().removeNotificationListener(columnStart, this);
		}
		if (rowFinish != null) {
			getDiagramEventBroker().removeNotificationListener(rowFinish, this);
		}
		if (columnFinish != null) {
			getDiagramEventBroker().removeNotificationListener(columnFinish, this);
		}
		super.deactivate();
	}

	/**
	 * avoid to modify it directly, try to modify call of sub-methods: updateXXX
	 * 
	 * @see org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener#notifyChanged(org.eclipse.emf.common.notify.Notification)
	 *
	 * @param notification
	 */
	@Override
	public void notifyChanged(Notification notification) {
		// Display imprecision
		if (notification.getEventType() == Notification.REMOVE) {
			return;
		}
		Node nodeContainer = (Node) (((GraphicalEditPart) getHost()).getNotationView()).eContainer();
		if (nodeContainer != null) {
			PrecisionRectangle originPosition = NotationHelper.getAbsoluteBounds(nodeContainer);
			Bounds currentBounds = (Bounds) ((Node) ((GraphicalEditPart) getHost()).getNotationView()).getLayoutConstraint();

			// the ROW has changed so we must update the position of the combined fragment
			if (notification.getEventType() == Notification.SET && notification.getNotifier() instanceof Location && (((EObject) notification.getNotifier()).eContainer().equals(rowStart))) {
				// The grid is in absolute
				// compute next position for View.bound.y
				updateYFromAxisNotification(originPosition, currentBounds);
			}
			// the COLUMN has changed so we must update the postion of the combined fragment
			if (notification.getEventType() == Notification.SET && notification.getNotifier() instanceof Location && (((EObject) notification.getNotifier()).eContainer().equals(columnStart))) {
				// The grill is in absolute
				updateXFromAxisNotification(originPosition, currentBounds);

			}
			if (notification.getEventType() == Notification.SET && notification.getNotifier() instanceof Location && (((EObject) notification.getNotifier()).eContainer().equals(rowFinish))) {
				// The grill is in absolute
				updateHeightFromAxisNotification(originPosition, currentBounds);

			}
			if (notification.getEventType() == Notification.SET && notification.getNotifier() instanceof Location && (((EObject) notification.getNotifier()).eContainer().equals(columnFinish))) {
				// The grill is in absolute
				updateWidthFromAxisNotification(originPosition, currentBounds);

			}

			// UPDATE COLUM AND ROW of THE GRID
			if (notification.getEventType() == Notification.SET && notification.getNotifier() instanceof Bounds) {
				PrecisionRectangle bounds = NotationHelper.getAbsoluteBounds((Node) ((GraphicalEditPart) getHost()).getNotationView());
				UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+ EVENT: BOUNDS change " + notification.getNewValue());//$NON-NLS-1$

				if (notification.getFeature().equals(NotationPackage.eINSTANCE.getSize_Height())) {
					updateRowFinishFromHeightNotification(bounds);
					// update anchors
					if ((((EObject) notification.getNotifier()).eContainer().equals(((EObject) getHost().getModel())))) {
						Node node = (Node) this.getHost().getModel();
						java.util.List<Edge> sourceEdge = node.getSourceEdges();
						for (Edge edge : sourceEdge) {
							IdentityAnchor anchor = (IdentityAnchor) edge.getSourceAnchor();
							if (anchor instanceof IdentityAnchor) {
								updateAnchorFromHeight(anchor, ((Node) getHost().getModel()), notification.getNewIntValue() - notification.getOldIntValue());
							}
						}
						java.util.List<Edge> targetEdge = node.getTargetEdges();
						for (Edge edge : targetEdge) {
							IdentityAnchor anchor = (IdentityAnchor) edge.getTargetAnchor();
							if (anchor instanceof IdentityAnchor) {
								updateAnchorFromHeight(anchor, ((Node) getHost().getModel()), notification.getNewIntValue() - notification.getOldIntValue());
							}
						}
					}
				}
				if (notification.getFeature().equals(NotationPackage.eINSTANCE.getSize_Width())) {
					updateColumFinishFromWitdhNotification(bounds);
				}
				if (notification.getFeature().equals(NotationPackage.eINSTANCE.getLocation_Y())) {
					// compute next position for RowStart
					updateRowStartFromYNotification(bounds);
					// updateAnchors
					if (((EObject) notification.getNotifier()).eContainer().equals(((EObject) getHost().getModel()))) {
						Node node = (Node) this.getHost().getModel();

						// children case
						for (Object child : node.getChildren()) {
							// Nodes
							if (child instanceof Node) {
								EObject element = ((Node) child).getElement();
								// ExecutionSpecification
								if (element instanceof ExecutionSpecification) {
									updateExecutionSpecificationFromY((Node) child, notification.getNewIntValue(), notification.getOldIntValue());
								}
							}
						}

						java.util.List<Edge> sourceEdge = node.getSourceEdges();
						for (Edge edge : sourceEdge) {
							IdentityAnchor anchor = (IdentityAnchor) edge.getSourceAnchor();
							if (anchor instanceof IdentityAnchor) {
								updateAnchorFromY(anchor, ((Node) getHost().getModel()), notification.getOldIntValue(), notification.getNewIntValue());
							}
						}
						java.util.List<Edge> targetEdge = node.getTargetEdges();
						for (Edge edge : targetEdge) {
							IdentityAnchor anchor = (IdentityAnchor) edge.getTargetAnchor();
							if (anchor instanceof IdentityAnchor) {
								updateAnchorFromY(anchor, ((Node) getHost().getModel()), notification.getOldIntValue(), notification.getNewIntValue());
							}
						}
					}
				}
				if (notification.getFeature().equals(NotationPackage.eINSTANCE.getLocation_X())) {
					// compute next position for RowStart
					updateColumnStartFromXNotification(bounds);
				}
			}
		}
	}

	/**
	 * This update the position of {@link ExecutionSpecification} {@link Node} after the Y move of lifeline parent.
	 * 
	 * @param execSpecNode
	 *            the {@link ExecutionSpecification} {@link Node}
	 * @param newYValue
	 *            the new Y value
	 * @param oldYValue
	 *            the old Y value
	 */
	protected void updateExecutionSpecificationFromY(final Node execSpecNode, final int newYValue, final int oldYValue) {
		LayoutConstraint layoutConstraint = execSpecNode.getLayoutConstraint();
		if (layoutConstraint instanceof Bounds) {
			int delta = newYValue - oldYValue;
			execute(new SetBoundsCommand(getDiagramEditPart(getHost()).getEditingDomain(), "update ExecutionSpecification", new EObjectAdapter(execSpecNode), //$NON-NLS-1$
					new Point(((Bounds) layoutConstraint).getX(), ((Bounds) layoutConstraint).getY() - delta)));
		}
	}

	/**
	 * When the bounds of the notation has change the axis must change
	 * In this case this is the height that has change so rowFinish must change
	 * 
	 * @param originPosition
	 *            the position of the node is the relative position ( relative to the container)
	 */
	protected void updateRowFinishFromHeightNotification(PrecisionRectangle p) {
		int newY = p.y + p.height + margin;
		updatePositionGridAxis(rowFinish, 0, newY);
	}

	/**
	 * When the bounds of the notation has change the axis must change
	 * In this case this is the width that has changed so ColumnFinish must change
	 * 
	 * @param notationBound
	 *            the position of the node is the absolute position ( the origin to the referential is the diagram)
	 */
	protected void updateColumFinishFromWitdhNotification(PrecisionRectangle notationBound) {
		int newX = notationBound.x + notationBound.width;
		updatePositionGridAxis(columnFinish, newX, 0);
		UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+---->ACTION: modifiy AXIS to  x=" + newX);//$NON-NLS-1$

	}

	/**
	 * When the bounds of the notation has change the axis must change
	 * In this case this is the position Y that has change so RowStart must change
	 * 
	 * @param bounds
	 *            the position of the node is the absolute position ( the origin to the referential is the diagram)
	 */
	protected void updateRowStartFromYNotification(PrecisionRectangle bounds) {

		int newY = bounds.y() + margin;
		updatePositionGridAxis(rowStart, 0, newY);

		if (rowFinish != null) {
			newY = bounds.y + bounds.height + margin;
			updatePositionGridAxis(rowFinish, 0, newY);
		}
	}

	/**
	 * When the bounds of the notation has change the axis must change
	 * In this case this is the position X that has change so ColumnStart must change
	 * 
	 * @param bounds
	 *            the position of the node is the absolute position ( the origin to the referential is the diagram)
	 */
	protected void updateColumnStartFromXNotification(PrecisionRectangle bounds) {
		int newX = bounds.x();
		updatePositionGridAxis(columnStart, newX, 0);
		UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+---->ACTION: modifiy AXIS START to  x=" + newX);//$NON-NLS-1$

	}

	/**
	 * When the axis columnFinish has changed , the width of the controler has to change
	 * 
	 * @param originPosition
	 *            the position of the container in absolute (origin the diagram)
	 * @param currentBounds
	 *            the current position of the node (relative to the container)
	 */
	protected void updateWidthFromAxisNotification(PrecisionRectangle originPosition, Bounds currentBounds) {
		Location boundsColumn = (Location) ((Node) columnFinish).getLayoutConstraint();
		int newX = boundsColumn.getX() - originPosition.x() - currentBounds.getX();
		UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+ EVENT: AXIS ROW FINISH change " + newX);//$NON-NLS-1$

		updateSizeOfControler(newX, currentBounds.getHeight());
	}

	/**
	 * When the axis rowFinish has changed , the height of the controler has to change
	 * 
	 * @param originPosition
	 *            the position of the container in absolute (origin the diagram)
	 * @param currentBounds
	 *            the current position of the node (relative to the container)
	 */
	protected void updateHeightFromAxisNotification(PrecisionRectangle originPosition, Bounds currentBounds) {
		Location boundsColumn = (Location) ((Node) rowFinish).getLayoutConstraint();
		int newHeight = boundsColumn.getY() - originPosition.y() - currentBounds.getY() - margin;
		UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+ EVENT: AXIS ROW FINISH change " + newHeight);//$NON-NLS-1$

		updateSizeOfControler(currentBounds.getWidth(), newHeight);
	}

	/**
	 * When the axis columnStart has changed , the position X of the controler has to change
	 * 
	 * @param originPosition
	 *            the position of the container in absolute (origin the diagram)
	 * @param currentBounds
	 *            the current position of the node (relative to the container)
	 */
	protected void updateXFromAxisNotification(PrecisionRectangle originPosition, Bounds currentBounds) {
		Location boundsColumn = (Location) ((Node) columnStart).getLayoutConstraint();
		int newX = boundsColumn.getX() - originPosition.x();
		UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+ EVENT: AXIS COLUMN START change " + newX);//$NON-NLS-1$

		updateNodePositionOfControler(newX, currentBounds.getY());
	}

	/**
	 * When the axis rowStart has changed , the position Y of the controler has to change
	 * 
	 * @param originPosition
	 *            the position of the container in absolute (origin the diagram)
	 * @param currentBounds
	 *            the current position of the node (relative to the container)
	 */
	protected void updateYFromAxisNotification(PrecisionRectangle originPosition, Bounds currentBounds) {
		Location boundsRow = (Location) ((Node) rowStart).getLayoutConstraint();
		int newY = boundsRow.getY() - originPosition.y() - margin;
		UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+ EVENT: AXIS ROW START change " + newY);//$NON-NLS-1$
		updateNodePositionOfControler(currentBounds.getX(), newY);

		if (rowFinish != null) {
			updatePositionGridAxis(rowFinish, 0, boundsRow.getY() + BoundForEditPart.getHeightFromView((Node) ((GraphicalEditPart) getHost()).getNotationView()) - margin);
		}
	}


	/**
	 * this class update the position of anchor after the resize
	 * 
	 * @param edge
	 *            the edge anchor to update
	 * @param node
	 * @param deltaHeight
	 * @param isSource
	 *            true is it is the anchor source to update, false for the target.
	 */
	protected void updateAnchorFromHeight(IdentityAnchor anchor, Node node, int deltaHeight) {
		if (null != anchor) {
			double yPercent = IdentityAnchorHelper.getYPercentage(anchor);
			double xPercent = IdentityAnchorHelper.getXPercentage(anchor);

			// calculate bounds from notation
			PrecisionRectangle bounds = NotationHelper.getAbsoluteBounds(node);
			double oldHeight = BoundForEditPart.getHeightFromView(node) - deltaHeight;

			double newPercentY = (yPercent * oldHeight) / (bounds.preciseHeight());
			if (newPercentY <= 1 && newPercentY >= 0 && newPercentY <= 1 && newPercentY >= 0) {
				final String newIdValue = IdentityAnchorHelper.createNewAnchorIdValue(xPercent, newPercentY);
				execute(new SetCommand(getDiagramEditPart(getHost()).getEditingDomain(), anchor, NotationPackage.eINSTANCE.getIdentityAnchor_Id(), newIdValue));
			}
		}
	}

	/**
	 * this class update the position of anchor after the move
	 * 
	 * @param sourceEdge
	 * @param eObject
	 */
	protected void updateAnchorFromY(IdentityAnchor anchor, Node node, int oldY, int newY) {
		if (null != anchor && !anchor.getId().trim().equals("")) { //$NON-NLS-1$
			double yPercent = IdentityAnchorHelper.getYPercentage(anchor);
			double xPercent = IdentityAnchorHelper.getXPercentage(anchor);

			// calculate bounds from notation
			double height = BoundForEditPart.getHeightFromView(node);

			double newPercentY = (oldY - newY) / (height) + yPercent;
			if (newPercentY < 0) {
				newPercentY = 0.01;
			}
			if (newPercentY > 1) {
				newPercentY = 0.99;
			}
			if (newPercentY <= 1 && newPercentY >= 0 && newPercentY <= 1 && newPercentY >= 0) {
				final String newIdValue = IdentityAnchorHelper.createNewAnchorIdValue(xPercent, newPercentY);
				execute(new SetCommand(getDiagramEditPart(getHost()).getEditingDomain(), anchor, NotationPackage.eINSTANCE.getIdentityAnchor_Id(), newIdValue));
			}
		}
	}

}

Back to the top