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