Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cf50423a1b6fd2402e5ee0a2adb8c973a6f010e0 (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
/*****************************************************************************
 * Copyright (c) 2018 CEA LIST, EclipseSource and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   EclipseSource - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.parts;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gmf.runtime.notation.Connector;
import org.eclipse.gmf.runtime.notation.IntValueStyle;
import org.eclipse.gmf.runtime.notation.NamedStyle;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.DurationLinkSelectionHandlesEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.figures.DurationLinkFigure;

public class CustomDurationConstraintLinkEditPart extends DurationConstraintLinkEditPart {

	/**
	 * Constructor.
	 *
	 * @param view
	 */
	public CustomDurationConstraintLinkEditPart(View view) {
		super(view);
	}

	@Override
	protected void createDefaultEditPolicies() {
		super.createDefaultEditPolicies();
		installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE, new DurationLinkSelectionHandlesEditPolicy(this, getEditingDomain()));
	}

	@Override
	protected void refreshVisuals() {
		Connector connector = (Connector) getNotationView();
		NamedStyle namedStyle = connector.getNamedStyle(NotationPackage.Literals.INT_VALUE_STYLE, "delta");
		if (namedStyle instanceof IntValueStyle) {
			refreshArrowDelta((IntValueStyle) namedStyle);
		}
		super.refreshVisuals();
	}

	@Override
	protected void handleNotificationEvent(Notification event) {
		if (event.getNotifier() instanceof IntValueStyle
				&& "delta".equals(((IntValueStyle) event.getNotifier()).getName())) {
			refreshArrowDelta((IntValueStyle) event.getNotifier());
		} else if (event.getNotifier() == getNotationView()
				&& event.getFeature() == NotationPackage.Literals.VIEW__STYLES) {
			refreshVisuals();
		}
		super.handleNotificationEvent(event);
	}

	private void refreshArrowDelta(IntValueStyle deltaStyle) {
		int delta = deltaStyle.getIntValue();
		((DurationLinkFigure) getFigure()).setArrowPositionDelta(delta);
	}
}

Back to the top