Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 382770054f1dacdc573df254464a4de521bcb9d5 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*****************************************************************************
 * Copyright (c) 2008 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:
 *  Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
 *  Emilien Perico (Atos Origin) - adapt class for use case association
 *
 *****************************************************************************/
package org.eclipse.papyrus.diagram.usecase.figure;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.PolylineDecoration;
import org.eclipse.draw2d.RotatableDecoration;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.papyrus.diagram.common.figure.edge.UMLEdgeFigure;
import org.eclipse.swt.SWT;

/**
 * this is the figure to display a association figure.
 */
public class AssociationFigure extends UMLEdgeFigure {

	/** the end of the association is navigable so this is an arrow. */
	public static final int navigable = 1;

	/** the end of contained the property. */
	public static final int owned = 8;

	/** The association name label. */
	private WrappingLabel fAssociationNameLabel;

	/** The multiplicity source label. */
	private WrappingLabel fMultiplicitySourceLabel;

	/** The multiplicity target label. */
	private WrappingLabel fMultiplicityTargetLabel;

	/** The f role source label. */
	private WrappingLabel fRoleSourceLabel;

	/** The f role target label. */
	private WrappingLabel fRoleTargetLabel;

	public AssociationFigure() {
		super();
		setAntialias(SWT.ON);
		createContents();
	}

	/**
	 * create an association figure.
	 * 
	 * @param targetType
	 *        the type of end of the association {@link AssociationFigure#navigable}
	 * @param sourceType
	 *        the type of end of the association {@link AssociationFigure#navigable}
	 */
	public AssociationFigure(int sourceType, int targetType) {
		super();
		this.setEnd(sourceType, targetType);
		createContents();
	}

	/**
	 * Creates the contents of the association
	 */
	protected void createContents() {
		super.createContents();

		fAssociationNameLabel = new WrappingLabel();
		fAssociationNameLabel.setText("");
		this.add(fAssociationNameLabel);

		fMultiplicitySourceLabel = new WrappingLabel();
		fMultiplicitySourceLabel.setText("");
		this.add(fMultiplicitySourceLabel);

		fMultiplicityTargetLabel = new WrappingLabel();
		fMultiplicityTargetLabel.setText("");
		this.add(fMultiplicityTargetLabel);

		fRoleSourceLabel = new WrappingLabel();
		fRoleSourceLabel.setText("");
		this.add(fRoleSourceLabel);

		fRoleTargetLabel = new WrappingLabel();
		fRoleTargetLabel.setText("");
		this.add(fRoleTargetLabel);
	}

	/**
	 * Gets the decoration.
	 * 
	 * @param typeDecoration
	 *        the type decoration
	 * 
	 * @return the appropriate decoration
	 */
	public RotatableDecoration getDecoration(int typeDecoration) {
		int remain = typeDecoration % owned;
		int navigationValue = remain / navigable;

		if(navigationValue == 1) {
			return getNavigationDecoration();
		}
		return null;

	}

	/**
	 * Gets the navigation decoration.
	 * 
	 * @return the navigation decoration
	 */
	protected RotatableDecoration getNavigationDecoration() {
		PolylineDecoration dec = new PolylineDecoration();
		dec.setScale(15, 5);
		dec.setLineWidth(1);
		return dec;
	}

	/**
	 * @{inheritDoc
	 */
	public void paintFigure(Graphics graphics) {
		graphics.setAntialias(SWT.ON);
		super.paintFigure(graphics);
	}

	/**
	 * used to display end of the association.
	 * 
	 * @param targetType
	 *        the type of end of the association {@link AssociationFigure#navigable}
	 * @param sourceType
	 *        the type of end of the association {@link AssociationFigure#navigable}
	 */
	public void setEnd(int sourceType, int targetType) {
		this.setSourceDecoration(getDecoration(sourceType));
		this.setTargetDecoration(getDecoration(targetType));
	}

	/**
	 * @generated
	 */
	public WrappingLabel getAssociationNameLabel() {
		return fAssociationNameLabel;
	}

	/**
	 * @generated
	 */
	public WrappingLabel getMultiplicitySourceLabel() {
		return fMultiplicitySourceLabel;
	}

	/**
	 * @generated
	 */
	public WrappingLabel getMultiplicityTargetLabel() {
		return fMultiplicityTargetLabel;
	}

	/**
	 * @generated
	 */
	public WrappingLabel getRoleSourceLabel() {
		return fRoleSourceLabel;
	}

	/**
	 * @generated
	 */
	public WrappingLabel getRoleTargetLabel() {
		return fRoleTargetLabel;
	}
}

Back to the top