]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/EvaluatorImpl.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.common / src / org / simantics / browsing / ui / common / EvaluatorImpl.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.common;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16
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;
27
28 /**
29  * @author Tuukka Lehtonen
30  */
31 public class EvaluatorImpl implements Evaluator {
32
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);
40
41     @Override
42     public Evaluator addViewpoint(ViewpointFactory factory, double preference) {
43         viewpointTree.addFactory(factory, preference);
44         return this;
45     }
46     @Override
47     public Evaluator addComparableContext(ComparableContextFactory factory, double preference) {
48         comparableContextTree.addFactory(factory, preference);
49         return this;
50     }
51     @Override
52     public Evaluator addLabeler(LabelerFactory factory, double preference) {
53         labelerTree.addFactory(factory, preference);
54         return this;
55     }
56     @Override
57     public Evaluator addCheckState(CheckedStateFactory factory, double preference) {
58         checkStateTree.addFactory(factory, preference);
59         return this;
60     }
61     @Override
62     public Evaluator addLabelDecorator(LabelDecoratorFactory factory, double preference) {
63         labelDecoratorTree.addFactory(factory, preference);
64         return this;
65     }
66     @Override
67     public Evaluator addComparator(ComparableContextFactory factory, double preference) {
68         comparableContextTree.addFactory(factory, preference);
69         return this;
70     }
71     @Override
72     public Evaluator addImager(ImagerFactory factory, double preference) {
73         imagerTree.addFactory(factory, preference);
74         return this;
75     }
76     @Override
77     public Evaluator addImageDecorator(ImageDecoratorFactory factory, double preference) {
78         imageDecoratorTree.addFactory(factory, preference);
79         return this;
80     }
81
82     @Override
83     public EvaluatorTree<ComparableContextFactory> getComparableContextTree() {
84         return comparableContextTree;
85     }
86
87     @Override
88     public EvaluatorTree<ImagerFactory> getImagerTree() {
89         return imagerTree;
90     }
91
92     @Override
93     public EvaluatorTree<ImageDecoratorFactory> getImageDecoratorTree() {
94         return imageDecoratorTree;
95     }
96
97     @Override
98     public EvaluatorTree<LabelDecoratorFactory> getLabelDecoratorTree() {
99         return labelDecoratorTree;
100     }
101
102     @Override
103     public EvaluatorTree<LabelerFactory> getLabelerTree() {
104         return labelerTree;
105     }
106
107     @Override
108     public EvaluatorTree<CheckedStateFactory> getCheckStateTree() {
109         return checkStateTree;
110     }
111
112     @Override
113     public EvaluatorTree<ViewpointFactory> getViewpointTree() {
114         return viewpointTree;
115     }
116
117     /**
118      * @param <Factory>
119      */
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>>();
125
126         public EvaluatorTreeImpl(String factory, Tester tester) {
127             if (tester == null)
128                 throw new NullPointerException("null tester");
129             this.tester = tester;
130             this.factory = factory;
131         }
132
133         @Override
134         public EvaluatorTree<Factory> addFactory(Factory factory, double preference) {
135             if (factory == null)
136                 throw new NullPointerException("null factory");
137             acceptedFactories.add(new Preference<Factory>(factory, preference));
138             return this;
139         }
140
141         @Override
142         public EvaluatorTree<Factory> addBranch(Tester tester) {
143             if (tester == null)
144                 throw new NullPointerException("null tester");
145             EvaluatorTree<Factory> result = new EvaluatorTreeImpl<Factory>(factory, tester);
146             children.add(result);
147             return result;
148         }
149
150         @Override
151         public Collection<Preference<Factory>> getAcceptedFactories() {
152             return acceptedFactories;
153         }
154
155         @Override
156         public Collection<EvaluatorTree<Factory>> getChildren() {
157             return children;
158         }
159
160         @Override
161         public Tester getTester() {
162             return tester;
163         }
164
165         @Override
166         public String toString() {
167             return factory + " tree [" + tester + "]";
168         }
169
170     }
171
172     @Override
173     public String toString() {
174         return "Evaluator";
175     }
176
177 }