]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/EvaluatorImpl.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.browsing.ui.common / src / org / simantics / browsing / ui / common / EvaluatorImpl.java
diff --git a/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/EvaluatorImpl.java b/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/EvaluatorImpl.java
new file mode 100644 (file)
index 0000000..ca9b417
--- /dev/null
@@ -0,0 +1,177 @@
+/*******************************************************************************\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.common;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.Tester;\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.browsing.ui.content.ComparableContextFactory;\r
+import org.simantics.browsing.ui.content.ImageDecoratorFactory;\r
+import org.simantics.browsing.ui.content.ImagerFactory;\r
+import org.simantics.browsing.ui.content.LabelDecoratorFactory;\r
+import org.simantics.browsing.ui.content.LabelerFactory;\r
+import org.simantics.browsing.ui.content.ViewpointFactory;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class EvaluatorImpl implements Evaluator {\r
+\r
+    private final EvaluatorTree<ViewpointFactory>      viewpointTree           = new EvaluatorTreeImpl<ViewpointFactory>("Viewpoint", Testers.PASS);\r
+    private final EvaluatorTree<LabelerFactory>        labelerTree             = new EvaluatorTreeImpl<LabelerFactory>("Labeler", Testers.PASS);\r
+    private final EvaluatorTree<CheckedStateFactory>     checkStateTree             = new EvaluatorTreeImpl<CheckedStateFactory>("Check state", Testers.PASS);\r
+    private final EvaluatorTree<LabelDecoratorFactory> labelDecoratorTree      = new EvaluatorTreeImpl<LabelDecoratorFactory>("Label decorator", Testers.PASS);\r
+    private final EvaluatorTree<ImagerFactory>         imagerTree              = new EvaluatorTreeImpl<ImagerFactory>("Imager", Testers.PASS);\r
+    private final EvaluatorTree<ImageDecoratorFactory> imageDecoratorTree              = new EvaluatorTreeImpl<ImageDecoratorFactory>("Image decorator", Testers.PASS);\r
+    private final EvaluatorTree<ComparableContextFactory>     comparableContextTree          = new EvaluatorTreeImpl<ComparableContextFactory>("Comparable", Testers.PASS);\r
+\r
+    @Override\r
+    public Evaluator addViewpoint(ViewpointFactory factory, double preference) {\r
+        viewpointTree.addFactory(factory, preference);\r
+        return this;\r
+    }\r
+    @Override\r
+    public Evaluator addComparableContext(ComparableContextFactory factory, double preference) {\r
+        comparableContextTree.addFactory(factory, preference);\r
+        return this;\r
+    }\r
+    @Override\r
+    public Evaluator addLabeler(LabelerFactory factory, double preference) {\r
+        labelerTree.addFactory(factory, preference);\r
+        return this;\r
+    }\r
+    @Override\r
+    public Evaluator addCheckState(CheckedStateFactory factory, double preference) {\r
+        checkStateTree.addFactory(factory, preference);\r
+        return this;\r
+    }\r
+    @Override\r
+    public Evaluator addLabelDecorator(LabelDecoratorFactory factory, double preference) {\r
+        labelDecoratorTree.addFactory(factory, preference);\r
+        return this;\r
+    }\r
+    @Override\r
+    public Evaluator addComparator(ComparableContextFactory factory, double preference) {\r
+        comparableContextTree.addFactory(factory, preference);\r
+        return this;\r
+    }\r
+    @Override\r
+    public Evaluator addImager(ImagerFactory factory, double preference) {\r
+        imagerTree.addFactory(factory, preference);\r
+        return this;\r
+    }\r
+    @Override\r
+    public Evaluator addImageDecorator(ImageDecoratorFactory factory, double preference) {\r
+        imageDecoratorTree.addFactory(factory, preference);\r
+        return this;\r
+    }\r
+\r
+    @Override\r
+    public EvaluatorTree<ComparableContextFactory> getComparableContextTree() {\r
+        return comparableContextTree;\r
+    }\r
+\r
+    @Override\r
+    public EvaluatorTree<ImagerFactory> getImagerTree() {\r
+        return imagerTree;\r
+    }\r
+\r
+    @Override\r
+    public EvaluatorTree<ImageDecoratorFactory> getImageDecoratorTree() {\r
+        return imageDecoratorTree;\r
+    }\r
+\r
+    @Override\r
+    public EvaluatorTree<LabelDecoratorFactory> getLabelDecoratorTree() {\r
+        return labelDecoratorTree;\r
+    }\r
+\r
+    @Override\r
+    public EvaluatorTree<LabelerFactory> getLabelerTree() {\r
+        return labelerTree;\r
+    }\r
+\r
+    @Override\r
+    public EvaluatorTree<CheckedStateFactory> getCheckStateTree() {\r
+        return checkStateTree;\r
+    }\r
+\r
+    @Override\r
+    public EvaluatorTree<ViewpointFactory> getViewpointTree() {\r
+        return viewpointTree;\r
+    }\r
+\r
+    /**\r
+     * @param <Factory>\r
+     */\r
+    public class EvaluatorTreeImpl<Factory> implements EvaluatorTree<Factory> {\r
+        private final String                             factory;\r
+        private final Tester                             tester;\r
+        private final Collection<Preference<Factory>>    acceptedFactories = new ArrayList<Preference<Factory>>();\r
+        private final Collection<EvaluatorTree<Factory>> children          = new ArrayList<EvaluatorTree<Factory>>();\r
+\r
+        public EvaluatorTreeImpl(String factory, Tester tester) {\r
+            if (tester == null)\r
+                throw new NullPointerException("null tester");\r
+            this.tester = tester;\r
+            this.factory = factory;\r
+        }\r
+\r
+        @Override\r
+        public EvaluatorTree<Factory> addFactory(Factory factory, double preference) {\r
+            if (factory == null)\r
+                throw new NullPointerException("null factory");\r
+            acceptedFactories.add(new Preference<Factory>(factory, preference));\r
+            return this;\r
+        }\r
+\r
+        @Override\r
+        public EvaluatorTree<Factory> addBranch(Tester tester) {\r
+            if (tester == null)\r
+                throw new NullPointerException("null tester");\r
+            EvaluatorTree<Factory> result = new EvaluatorTreeImpl<Factory>(factory, tester);\r
+            children.add(result);\r
+            return result;\r
+        }\r
+\r
+        @Override\r
+        public Collection<Preference<Factory>> getAcceptedFactories() {\r
+            return acceptedFactories;\r
+        }\r
+\r
+        @Override\r
+        public Collection<EvaluatorTree<Factory>> getChildren() {\r
+            return children;\r
+        }\r
+\r
+        @Override\r
+        public Tester getTester() {\r
+            return tester;\r
+        }\r
+\r
+        @Override\r
+        public String toString() {\r
+            return factory + " tree [" + tester + "]";\r
+        }\r
+\r
+    }\r
+\r
+    @Override\r
+    public String toString() {\r
+        return "Evaluator";\r
+    }\r
+\r
+}
\ No newline at end of file