Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a724044f542dc21abddf9ce35afc537ac7841040 (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
/*****************************************************************************
 * Copyright (c) 2013 CEA
 *
 *
 * 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:
 *   Soyatec - Initial API and implementation
 *
 *****************************************************************************/

package org.eclipse.papyrus.uml.diagram.sequence.util;

import org.eclipse.gef.EditPart;
import org.eclipse.papyrus.infra.constraints.SimpleConstraint;
import org.eclipse.papyrus.infra.constraints.constraints.Constraint;
import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CommentAnnotatedElementEditPart;

public class DurationLinkConstraint extends org.eclipse.papyrus.infra.constraints.constraints.AbstractConstraint {

	private String sourcePart;

	@Override
	protected void setDescriptor(SimpleConstraint descriptor) {
		sourcePart = getValue("sourcePart"); //$NON-NLS-1$
	}

	@Override
	public boolean match(Object selection) {
		if (selection instanceof CommentAnnotatedElementEditPart) {
			CommentAnnotatedElementEditPart sel = (CommentAnnotatedElementEditPart) selection;
			EditPart source = sel.getSource();
			if (source != null && sourcePart != null) {
				Class<?> clazz = ClassLoaderHelper.loadClass(sourcePart);
				return clazz.isInstance(source);
			}
		}
		return false;
	}

	@Override
	protected boolean equivalent(Constraint constraint) {
		if (constraint == null) {
			return false;
		}
		if (!(constraint instanceof DurationLinkConstraint)) {
			return false;
		}
		DurationLinkConstraint other = (DurationLinkConstraint) constraint;
		if (sourcePart == null) {
			if (other.sourcePart != null) {
				return false;
			}
		} else if (!sourcePart.equals(other.sourcePart)) {
			return false;
		}

		return true;
	}

}

Back to the top