Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6609dcb8f8d65380e658e2a8557867733351aef5 (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
/*****************************************************************************
 * Copyright (c) 2011 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
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.edit.part;

import org.eclipse.draw2d.IFigure;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.tools.utils.ValueSpecificationUtil;
import org.eclipse.uml2.uml.Constraint;

/**
 * Abstract non-diagram specific edit part for node label representing {@link Constraint}.
 * This class is adapted from edit parts generated by GMF Tooling.
 */
public class ConstraintNodeLabelEditPart extends AbstractElementNodeLabelEditPart {

	protected static final String LEFT_BRACE = "{";
	protected static final String RIGHT_BRACE = "}";

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

	/**
	 * {@inheritDoc}
	 */
	public String getLabelRole() {
		return "Label"; //$NON-NLS-1$
	}

	/**
	 * {@inheritDoc}
	 */
	public String getIconPathRole() {
		return ""; //$NON-NLS-1$
	}
	
	@Override
	protected void refreshVisuals() {
		super.refreshVisuals();
		IFigure figure = getFigure();
		if (figure instanceof WrappingLabel) {
			EObject resolveSemanticElement = resolveSemanticElement();
			if (resolveSemanticElement instanceof Constraint) {
				String specificationValue = ValueSpecificationUtil.getSpecificationValue(((Constraint) resolveSemanticElement).getSpecification());
				specificationValue = (specificationValue == null ? "" : specificationValue);
				((WrappingLabel) figure).setText(LEFT_BRACE + specificationValue + RIGHT_BRACE);
			}
		}
	}
	
	@Override
	protected void handleNotificationEvent(Notification event) {
		// do nothing else refresh
		refresh();
	}
}

Back to the top