Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8de6f1aaadf2c68b3808edf398b58549f1a62e68 (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
/*****************************************************************************
 * Copyright (c) 2013 CEA LIST, 2014 Flanders' Make.
 *
 * 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:
 *  Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
 *  Klaas Gadeyne (Flanders' Make) klaas.gadeyne@flandersmake.be - Extended for CallBehaviorActions,
 *  see bug 453721 
 *****************************************************************************/
package org.eclipse.papyrus.uml.navigation.contributor;

import java.util.Collections;

import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
import org.eclipse.papyrus.infra.widgets.util.NavigationTarget;
import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.Behavior;

/**
 * Navigates from a CallBehaviorAction to its Behavior declaration
 *
 * @author Klaas Gadeyne
 */
public class CBANavigableElement implements NavigableElement {

	protected final Behavior behavior;

	/**
	 *
	 * @param type
	 *            The Type to navigate to. May be null.
	 */
	public CBANavigableElement(Behavior behavior) {
		this.behavior = behavior;
	}

	public String getLabel() {
		String label = "Go to behavior" + getCBALabel();
		return label;
	}

	public String getDescription() {
		return "Go to the Behavior linked with to this CallBehaviorAction" + getCBALabel();
	}

	protected String getCBALabel() {
		if (behavior == null) {
			return " (Undefined)";
		} else {
			return " (" + behavior.getName() + ")";
		}
	}

	@Deprecated
	public void navigate(IRevealSemanticElement navigationContext) {
		if (!isEnabled()) {
			return;
		}

		navigationContext.revealSemanticElement(Collections.singletonList(behavior));
	}

	public Image getImage() {
		if (behavior == null) {
			return null;
		}

		try {
			return ServiceUtilsForEObject.getInstance().getServiceRegistry(behavior).getService(LabelProviderService.class).getLabelProvider().getImage(behavior);
		} catch (Exception ex) {
			return null;
		}
	}

	/**
	 * Enabled when the behavior is defined
	 */
	public boolean isEnabled() {
		return behavior != null;
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean navigate(NavigationTarget navigationContext) {
		if (!isEnabled()) {
			return false;
		}
		return navigationContext.revealElement(behavior);
	}
}

Back to the top