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