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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.common;
\r
14 import org.simantics.browsing.ui.BuiltinKeys;
\r
15 import org.simantics.browsing.ui.NodeContext;
\r
16 import org.simantics.browsing.ui.NodeContext.ConstantKey;
\r
17 import org.simantics.browsing.ui.NodeQueryManager;
\r
18 import org.simantics.browsing.ui.Tester;
\r
19 import org.simantics.browsing.ui.common.node.StandardNodes;
\r
21 public final class Testers {
\r
24 * Simple pass all tester.
\r
26 public static final Tester PASS = new Tester() {
\r
28 public boolean test(NodeQueryManager manager, NodeContext context) {
\r
32 public String toString() {
\r
38 * Simple fail all tester.
\r
40 public static final Tester FAIL = new Tester() {
\r
42 public boolean test(NodeQueryManager manager, NodeContext context) {
\r
46 public String toString() {
\r
53 * @return tester for checking whether node context input is an instance of
\r
54 * the specified class
\r
56 public static Tester instanceOfTester(final Class<?> clazz) {
\r
57 return new Tester() {
\r
59 public boolean test(NodeQueryManager manager, NodeContext context) {
\r
60 return clazz.isInstance(context.getConstant(BuiltinKeys.INPUT));
\r
63 public String toString() {
\r
64 return "class " + clazz.getName() + " test";
\r
69 public static Tester standardFunctionTester(final Object object) {
\r
70 return new Tester() {
\r
73 public boolean test(NodeQueryManager manager, NodeContext context) {
\r
74 Object function = context.getConstant(StandardNodes.FUNCTION);
\r
75 return object.equals(function);
\r
81 public static <T> Tester exists(final ConstantKey<T> key) {
\r
82 return new Tester() {
\r
85 public boolean test(NodeQueryManager manager, NodeContext context) {
\r
86 return context.getConstant(key) != null;
\r
92 public static Tester and(final Tester ... testers) {
\r
93 return new Tester() {
\r
96 public boolean test(NodeQueryManager manager, NodeContext context) {
\r
97 for(Tester tester : testers) if(!tester.test(manager, context)) return false;
\r