Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4efb67728577fd942535144f6f9ad64b80489f45 (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
/*****************************************************************************
 * Copyright (c) 2017 Ericsson Communications.
 * 
 * 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:
 *   Ericsson Communications - Initial API and implementation
 *   
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.activity.edit.policies;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.papyrus.uml.diagram.activity.edit.parts.ActivityPartitionEditPart;
import org.eclipse.papyrus.uml.diagram.activity.edit.parts.ActivityPartitionNameEditPart;
import org.eclipse.papyrus.uml.diagram.activity.helper.ActivityPartitionLabelHelper;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.AbstractMaskManagedEditPolicy;
import org.eclipse.uml2.uml.ActivityPartition;
import org.eclipse.uml2.uml.Element;

/**
 * @since 3.0
 */
public class ActivityPartitionLabelEditPolicy extends AbstractMaskManagedEditPolicy {

	@Override
	public void addAdditionalListeners() {
		super.addAdditionalListeners();

		ActivityPartition activityPartition = getUMLElement();
		// check host semantic element is not null
		if (activityPartition == null) {
			return;
		}
		// adds a listener to the element itself, and to linked elements, like Type
		getDiagramEventBroker().addNotificationListener(activityPartition, this);
		Element el = activityPartition.getRepresents();
		if (el != null) {
			getDiagramEventBroker().addNotificationListener(el, this);
		}
	}

	@Override
	protected void removeAdditionalListeners() {
		super.removeAdditionalListeners();
		ActivityPartition activityPartition = getUMLElement();
		// check host semantic element is not null
		if (activityPartition == null) {
			return;
		}
		getDiagramEventBroker().removeNotificationListener(activityPartition, this);
		Element el = activityPartition.getRepresents();
		if (el != null) {
			getDiagramEventBroker().removeNotificationListener(el, this);
		}
	}


	@Override
	public void refreshDisplay() {
		// calls the helper for this edit Part
		ActivityPartitionEditPart lp = (ActivityPartitionEditPart) getHost();
		List children = lp.getChildren();
		for (Object p : children) {
			if (p instanceof ActivityPartitionNameEditPart) {
				ActivityPartitionLabelHelper.getInstance().refreshEditPartDisplay((GraphicalEditPart) p);
			}
		}
	}


	@Override
	public Collection<String> getDefaultDisplayValue() {
		return ActivityPartitionLabelHelper.DEFAULT_LABEL_DISPLAY;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Map<String, String> getMasks() {
		return ActivityPartitionLabelHelper.getInstance().getMasks();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ActivityPartition getUMLElement() {
		return (ActivityPartition) hostSemanticElement;

	}

}

Back to the top