]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/node/StandardNodeTester.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.common / src / org / simantics / browsing / ui / common / node / StandardNodeTester.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.common.node;
13
14 import org.eclipse.core.expressions.PropertyTester;
15 import org.eclipse.jface.viewers.IStructuredSelection;
16 import org.simantics.browsing.ui.NodeContext;
17 import org.simantics.utils.ui.AdaptionUtils;
18
19 public class StandardNodeTester extends PropertyTester {
20
21     /**
22      * Tests if the received resource is an instance of any of the URIs
23      * listed in the arguments.
24      */
25     private static final String FUNCTION = "standardNodeFunction";
26
27     @Override
28     public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
29
30 //        System.out.println("TEST: " + receiver + ", " + property + ", " + Arrays.toString(args) + ", " + expectedValue);
31
32         if (!(receiver instanceof IStructuredSelection))
33             return false;
34
35         NodeContext context = AdaptionUtils.adaptToSingle(receiver, NodeContext.class);
36
37         if (context == null)
38             return false;
39
40         if(FUNCTION.equals(property)) {
41
42             Object function = context.getConstant(StandardNodes.FUNCTION);
43             if(function == null) return false;
44             return args[0].equals(function.toString());
45
46         }
47
48         return false;
49     }
50
51 }