Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: acc94b4160da5ce74967c542e13f5dd22e2062f2 (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
/*****************************************************************************
 * Copyright (c) 2013 Cedric Dumoulin.
 *
 *    
 * 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:
 *  Cedric Dumoulin  Cedric.dumoulin@lifl.fr - Initial API and implementation
 *
 *****************************************************************************/

package org.eclipse.papyrus.layers.stackmodel.util;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.layers.stackmodel.layers.Layer;
import org.eclipse.uml2.uml.NamedElement;

import com.google.common.base.Predicate;

/**
 * A Predicate used to filter {@link View} allowed by {@link Layer}.
 * 
 * @author cedric dumoulin
 *
 */
public class LayerDiagramViewPredicate implements Predicate<View> {

	/**
	 * Singleton instnace.
	 */
	public static final LayerDiagramViewPredicate instance = new LayerDiagramViewPredicate();
	
	/**
	 * Return true if the view is allowed by Layers.
	 * 
	 * @see com.google.common.base.Predicate#apply(java.lang.Object)
	 *
	 * @param view
	 * @return
	 */
	@Override
	public boolean apply(View view) {
		
		// View should be Shape or Edge
		if( ! (view instanceof Shape || view instanceof Edge ) ) {
			return false;
		}

		// Domain element should be set and should be NamedElement
		EObject ele = view.getElement();
		if( ele == null || !(ele instanceof NamedElement) ) {
			return false;
		}
		// ok
		return true;
	}

}

Back to the top