-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.swt;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-\r
-import org.simantics.browsing.ui.BuiltinKeys;\r
-import org.simantics.browsing.ui.CheckedState;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.NodeQueryManager;\r
-import org.simantics.browsing.ui.NodeQueryProcessor;\r
-import org.simantics.browsing.ui.Tester;\r
-import org.simantics.browsing.ui.BuiltinKeys.CheckedStateKey;\r
-import org.simantics.browsing.ui.NodeContext.QueryKey;\r
-import org.simantics.browsing.ui.common.EvaluatorData;\r
-import org.simantics.browsing.ui.common.Preference;\r
-import org.simantics.browsing.ui.common.EvaluatorData.Evaluator;\r
-import org.simantics.browsing.ui.common.EvaluatorData.EvaluatorTree;\r
-import org.simantics.browsing.ui.content.CheckedStateFactory;\r
-import org.simantics.utils.datastructures.collections.CollectionUtils;\r
-\r
-/**\r
- * @author Antti Villberg\r
- */\r
-public class DefaultIsCheckedProcessor2 implements NodeQueryProcessor<CheckedState> {\r
-\r
- private final EvaluatorData data;\r
-\r
- public DefaultIsCheckedProcessor2(EvaluatorData data) {\r
- this.data = data;\r
- }\r
-\r
- @Override\r
- public QueryKey<CheckedState> getIdentifier() {\r
- return BuiltinKeys.IS_CHECKED;\r
- }\r
-\r
- @Override\r
- public CheckedState query(final NodeQueryManager manager, final NodeContext context) {\r
- assert context != null;\r
-\r
- Object input = context.getConstant(BuiltinKeys.INPUT);\r
- assert input != null;\r
-\r
- Collection<Evaluator> evals = data.get(input);\r
- if (evals.isEmpty())\r
- return null;\r
-\r
- ArrayList<Preference<CheckedStateFactory>> factories = new ArrayList<Preference<CheckedStateFactory>>(4);\r
- for (Evaluator eval : evals) {\r
- evaluateTree(manager, context, eval.getCheckStateTree(), factories);\r
- }\r
-\r
- if (factories.isEmpty())\r
- return null;\r
-\r
- if (factories.size() >= 1) {\r
- Collections.sort(factories);\r
- return manager.query(context, new CheckedStateKey(factories.get(0).object));\r
- } else {\r
- return null;\r
- }\r
-\r
- }\r
-\r
- protected void evaluateTree(NodeQueryManager manager, NodeContext context, EvaluatorTree<CheckedStateFactory> tree, Collection<Preference<CheckedStateFactory>> result) {\r
- Tester test = tree.getTester();\r
-\r
- if (test.test(manager, context)) {\r
- CollectionUtils.checkedAdd(tree.getAcceptedFactories(), result);\r
-\r
- Collection<EvaluatorTree<CheckedStateFactory>> children = tree.getChildren();\r
- if (children == null)\r
- return;\r
- for (EvaluatorTree<CheckedStateFactory> e : children) {\r
- evaluateTree(manager, context, e, result);\r
- }\r
- }\r
- }\r
- \r
- @Override\r
- public String toString() {\r
- return "IsCheckedProcessor";\r
- }\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.swt;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.simantics.browsing.ui.BuiltinKeys;
+import org.simantics.browsing.ui.CheckedState;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.NodeQueryManager;
+import org.simantics.browsing.ui.NodeQueryProcessor;
+import org.simantics.browsing.ui.Tester;
+import org.simantics.browsing.ui.BuiltinKeys.CheckedStateKey;
+import org.simantics.browsing.ui.NodeContext.QueryKey;
+import org.simantics.browsing.ui.common.EvaluatorData;
+import org.simantics.browsing.ui.common.Preference;
+import org.simantics.browsing.ui.common.EvaluatorData.Evaluator;
+import org.simantics.browsing.ui.common.EvaluatorData.EvaluatorTree;
+import org.simantics.browsing.ui.content.CheckedStateFactory;
+import org.simantics.utils.datastructures.collections.CollectionUtils;
+
+/**
+ * @author Antti Villberg
+ */
+public class DefaultIsCheckedProcessor2 implements NodeQueryProcessor<CheckedState> {
+
+ private final EvaluatorData data;
+
+ public DefaultIsCheckedProcessor2(EvaluatorData data) {
+ this.data = data;
+ }
+
+ @Override
+ public QueryKey<CheckedState> getIdentifier() {
+ return BuiltinKeys.IS_CHECKED;
+ }
+
+ @Override
+ public CheckedState query(final NodeQueryManager manager, final NodeContext context) {
+ assert context != null;
+
+ Object input = context.getConstant(BuiltinKeys.INPUT);
+ assert input != null;
+
+ Collection<Evaluator> evals = data.get(input);
+ if (evals.isEmpty())
+ return null;
+
+ ArrayList<Preference<CheckedStateFactory>> factories = new ArrayList<Preference<CheckedStateFactory>>(4);
+ for (Evaluator eval : evals) {
+ evaluateTree(manager, context, eval.getCheckStateTree(), factories);
+ }
+
+ if (factories.isEmpty())
+ return null;
+
+ if (factories.size() >= 1) {
+ Collections.sort(factories);
+ return manager.query(context, new CheckedStateKey(factories.get(0).object));
+ } else {
+ return null;
+ }
+
+ }
+
+ protected void evaluateTree(NodeQueryManager manager, NodeContext context, EvaluatorTree<CheckedStateFactory> tree, Collection<Preference<CheckedStateFactory>> result) {
+ Tester test = tree.getTester();
+
+ if (test.test(manager, context)) {
+ CollectionUtils.checkedAdd(tree.getAcceptedFactories(), result);
+
+ Collection<EvaluatorTree<CheckedStateFactory>> children = tree.getChildren();
+ if (children == null)
+ return;
+ for (EvaluatorTree<CheckedStateFactory> e : children) {
+ evaluateTree(manager, context, e, result);
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "IsCheckedProcessor";
+ }
+
}
\ No newline at end of file