Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 990ff0c9f012f3c7357e5e60ce3b94e202565a1c (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
/**
 * Copyright (c) 2014 CEA LIST.
 *
 * 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
 *  Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905
 */
package org.eclipse.papyrus.uml.diagram.statemachine.custom.edit.part;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.statemachine.custom.figures.ConnectionPointReferenceFigure;
import org.eclipse.papyrus.uml.diagram.statemachine.edit.parts.ConnectionPointReferenceEditPart;
import org.eclipse.papyrus.uml.diagram.statemachine.edit.parts.ConnectionPointReferenceNameEditPart;
import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization;
import org.eclipse.uml2.uml.ConnectionPointReference;
import org.eclipse.uml2.uml.Pseudostate;


public class CustomConnectionPointReferenceNameEditPart extends ConnectionPointReferenceNameEditPart {

	public CustomConnectionPointReferenceNameEditPart(View view) {
		super(view);
	}

	@Override
	protected void handleNotificationEvent(Notification event) {
		
		super.handleNotificationEvent(event);

		refreshVisuals();
	}

	public String getLinks(ConnectionPointReference ref) {
		String label = "";
		if (!ref.getEntries().isEmpty()) {
			boolean first = true;
			for (Pseudostate p : ref.getEntries()) {
				if (!first) {
					label += ", ";
				} else {
					first = false;
				}
				label += UMLLabelInternationalization.getInstance().getLabel(p);
			}
		} else if (!ref.getExits().isEmpty()) {
			boolean first = true;
			for (Pseudostate p : ref.getExits()) {
				if (!first) {
					label += ", ";
				} else {
					first = false;
				}
				label += UMLLabelInternationalization.getInstance().getLabel(p);
			}
		}
		return label;
	}

	@Override
	protected void refreshVisuals() {
		super.refreshVisuals();

		ConnectionPointReferenceFigure connPtRefFigure = ((ConnectionPointReferenceEditPart) getParent()).getPrimaryShape();
		ConnectionPointReference connPtRef = (ConnectionPointReference) ((View) getModel()).getElement();

		if (connPtRef.getEntries().isEmpty() && connPtRef.getExits().isEmpty()) {
			connPtRefFigure.setKind(0);
		} else {
			setLabelText(getLinks(connPtRef));
			if (!connPtRef.getEntries().isEmpty()) {
				connPtRefFigure.setKind(1);

			} else if (!connPtRef.getExits().isEmpty()) {
				connPtRefFigure.setKind(2);
			}
		}

	}

}

Back to the top