Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 52938ef5788b75eb02040a92fa347f73b94749b7 (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) 2012 Atos Origin.
 *
 *
 * 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:
 *  Anass Radouani (Atos) anass.radouani@atos.com - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.activity.testers;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.uml2.uml.InvocationAction;

/**
 * This class is a Property tester used to check if current element
 * is a UML Call Action.
 */
public class UMLCallActionTester extends PropertyTester {

	/** Tester ID for UML Call Action nature */
	public static final String IS_CALL_ACTION = "isCallAction";

	/** Default constructor */
	public UMLCallActionTester() {
	}

	/** Test the receiver against the selected property */
	@Override
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
		// Ensure Papyrus is the active editor
		IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
		if ((editor == null) || (!(editor instanceof IMultiDiagramEditor))) {
			return false;
		}
		Object currentValue = null;
		if (IS_CALL_ACTION.equals(property)) {
			if (receiver instanceof StructuredSelection) {
				StructuredSelection structuredSelection = (StructuredSelection) receiver;
				Object obj = structuredSelection.getFirstElement();
				EObject element = null;
				if (obj instanceof IAdaptable) {
					element = (EObject) ((IAdaptable) obj).getAdapter(EObject.class);
					if (element instanceof View) {
						element = ((View) element).getElement();
					}
				}
				currentValue = element instanceof InvocationAction;
			}
			return (currentValue == expectedValue);
		}
		return false;
	}
}

Back to the top