Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 20f57affed3747ec3093f3f13c12b25bbc8abbf0 (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
/*****************************************************************************
 * Copyright (c) 2015 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
 *   Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 460356 : Refactor Stereotype Display
 *   
 *****************************************************************************/

package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeNamedElementFigure;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeUMLElementFigure;
import org.eclipse.swt.graphics.Image;

/**
 * @author Céline JANSSENS
 *         This Policy is in charge of create and delete the applied Stereotype Label Node into the Notation model
 */
public class AppliedStereotypeLabelEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy {

	/** constant for this edit policy role */
	public final static String STEREOTYPE_LABEL_POLICY = "AppliedStereotypeLabelEditPolicy"; //$NON-NLS-1$

	/**
	 * Creates a new AppliedStereotype display edit policy
	 */
	public AppliedStereotypeLabelEditPolicy() {
		super();
	}

	/**
	 * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy#refreshStereotypeDisplay()
	 *
	 */
	@Override
	protected void refreshStereotypeDisplay() {
		refreshStereotypeLabelDisplay();
	}

	protected void refreshStereotypeLabelDisplay() {
		if (getHost() instanceof IPapyrusEditPart) {
			IFigure figure = ((IPapyrusEditPart) getHost()).getPrimaryShape();

			// calculate text and icon to display
			final String stereotypesToDisplay = helper.getStereotypeTextToDisplay((View) getHost().getModel());
			final Image imageToDisplay = stereotypeIconToDisplay();

			// if the string is not empty, then, the figure has to display it.
			// Else, it displays nothing
			if (figure instanceof IPapyrusNodeUMLElementFigure) {

				// Refresh Stereotype Label
				((IPapyrusNodeUMLElementFigure) figure).setStereotypeDisplay(tag + stereotypesToDisplay, imageToDisplay);

				refreshAppliedStereotypesLabel((IPapyrusNodeUMLElementFigure) figure);

			}
		}

	}


	/**
	 * Refreshes the displayed stereotypes for this edit part.
	 */
	protected void refreshAppliedStereotypesLabel(IPapyrusNodeUMLElementFigure figure) {
		// If node has a Label
		if (figure instanceof IPapyrusNodeNamedElementFigure) {

			// Refresh Label
			boolean displayStereotypes = NotationUtils.getBooleanValue(getView(), NamedElementEditPart.DISPLAY_STEREOTYPES, true);
			if (!displayStereotypes) {
				((IPapyrusNodeNamedElementFigure) figure).removeStereotypeLabel();
			} else {
				((IPapyrusNodeNamedElementFigure) figure).restoreStereotypeLabel();
			}
		}
	}



}

Back to the top