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