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 java.util.ArrayList;
\r
15 import java.util.Collection;
\r
17 import org.simantics.browsing.ui.Tester;
\r
18 import org.simantics.browsing.ui.common.EvaluatorData.Evaluator;
\r
19 import org.simantics.browsing.ui.common.EvaluatorData.EvaluatorTree;
\r
20 import org.simantics.browsing.ui.content.CheckedStateFactory;
\r
21 import org.simantics.browsing.ui.content.ComparableContextFactory;
\r
22 import org.simantics.browsing.ui.content.ImageDecoratorFactory;
\r
23 import org.simantics.browsing.ui.content.ImagerFactory;
\r
24 import org.simantics.browsing.ui.content.LabelDecoratorFactory;
\r
25 import org.simantics.browsing.ui.content.LabelerFactory;
\r
26 import org.simantics.browsing.ui.content.ViewpointFactory;
\r
29 * @author Tuukka Lehtonen
\r
31 public class EvaluatorImpl implements Evaluator {
\r
33 private final EvaluatorTree<ViewpointFactory> viewpointTree = new EvaluatorTreeImpl<ViewpointFactory>("Viewpoint", Testers.PASS);
\r
34 private final EvaluatorTree<LabelerFactory> labelerTree = new EvaluatorTreeImpl<LabelerFactory>("Labeler", Testers.PASS);
\r
35 private final EvaluatorTree<CheckedStateFactory> checkStateTree = new EvaluatorTreeImpl<CheckedStateFactory>("Check state", Testers.PASS);
\r
36 private final EvaluatorTree<LabelDecoratorFactory> labelDecoratorTree = new EvaluatorTreeImpl<LabelDecoratorFactory>("Label decorator", Testers.PASS);
\r
37 private final EvaluatorTree<ImagerFactory> imagerTree = new EvaluatorTreeImpl<ImagerFactory>("Imager", Testers.PASS);
\r
38 private final EvaluatorTree<ImageDecoratorFactory> imageDecoratorTree = new EvaluatorTreeImpl<ImageDecoratorFactory>("Image decorator", Testers.PASS);
\r
39 private final EvaluatorTree<ComparableContextFactory> comparableContextTree = new EvaluatorTreeImpl<ComparableContextFactory>("Comparable", Testers.PASS);
\r
42 public Evaluator addViewpoint(ViewpointFactory factory, double preference) {
\r
43 viewpointTree.addFactory(factory, preference);
\r
47 public Evaluator addComparableContext(ComparableContextFactory factory, double preference) {
\r
48 comparableContextTree.addFactory(factory, preference);
\r
52 public Evaluator addLabeler(LabelerFactory factory, double preference) {
\r
53 labelerTree.addFactory(factory, preference);
\r
57 public Evaluator addCheckState(CheckedStateFactory factory, double preference) {
\r
58 checkStateTree.addFactory(factory, preference);
\r
62 public Evaluator addLabelDecorator(LabelDecoratorFactory factory, double preference) {
\r
63 labelDecoratorTree.addFactory(factory, preference);
\r
67 public Evaluator addComparator(ComparableContextFactory factory, double preference) {
\r
68 comparableContextTree.addFactory(factory, preference);
\r
72 public Evaluator addImager(ImagerFactory factory, double preference) {
\r
73 imagerTree.addFactory(factory, preference);
\r
77 public Evaluator addImageDecorator(ImageDecoratorFactory factory, double preference) {
\r
78 imageDecoratorTree.addFactory(factory, preference);
\r
83 public EvaluatorTree<ComparableContextFactory> getComparableContextTree() {
\r
84 return comparableContextTree;
\r
88 public EvaluatorTree<ImagerFactory> getImagerTree() {
\r
93 public EvaluatorTree<ImageDecoratorFactory> getImageDecoratorTree() {
\r
94 return imageDecoratorTree;
\r
98 public EvaluatorTree<LabelDecoratorFactory> getLabelDecoratorTree() {
\r
99 return labelDecoratorTree;
\r
103 public EvaluatorTree<LabelerFactory> getLabelerTree() {
\r
104 return labelerTree;
\r
108 public EvaluatorTree<CheckedStateFactory> getCheckStateTree() {
\r
109 return checkStateTree;
\r
113 public EvaluatorTree<ViewpointFactory> getViewpointTree() {
\r
114 return viewpointTree;
\r
120 public class EvaluatorTreeImpl<Factory> implements EvaluatorTree<Factory> {
\r
121 private final String factory;
\r
122 private final Tester tester;
\r
123 private final Collection<Preference<Factory>> acceptedFactories = new ArrayList<Preference<Factory>>();
\r
124 private final Collection<EvaluatorTree<Factory>> children = new ArrayList<EvaluatorTree<Factory>>();
\r
126 public EvaluatorTreeImpl(String factory, Tester tester) {
\r
127 if (tester == null)
\r
128 throw new NullPointerException("null tester");
\r
129 this.tester = tester;
\r
130 this.factory = factory;
\r
134 public EvaluatorTree<Factory> addFactory(Factory factory, double preference) {
\r
135 if (factory == null)
\r
136 throw new NullPointerException("null factory");
\r
137 acceptedFactories.add(new Preference<Factory>(factory, preference));
\r
142 public EvaluatorTree<Factory> addBranch(Tester tester) {
\r
143 if (tester == null)
\r
144 throw new NullPointerException("null tester");
\r
145 EvaluatorTree<Factory> result = new EvaluatorTreeImpl<Factory>(factory, tester);
\r
146 children.add(result);
\r
151 public Collection<Preference<Factory>> getAcceptedFactories() {
\r
152 return acceptedFactories;
\r
156 public Collection<EvaluatorTree<Factory>> getChildren() {
\r
161 public Tester getTester() {
\r
166 public String toString() {
\r
167 return factory + " tree [" + tester + "]";
\r
173 public String toString() {
\r
174 return "Evaluator";
\r