]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/modelBrowser/contributions/PartialEvaluatorFactory.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.structural.ui / src / org / simantics / structural / ui / modelBrowser / contributions / PartialEvaluatorFactory.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.structural.ui.modelBrowser.contributions;
13
14 import java.util.Collection;
15
16 import org.simantics.browsing.ui.common.EvaluatorImpl;
17 import org.simantics.browsing.ui.common.EvaluatorData.Evaluator;
18 import org.simantics.browsing.ui.common.extension.EvaluatorFactory;
19 import org.simantics.browsing.ui.content.ComparableContextFactory;
20 import org.simantics.browsing.ui.content.ImagerFactory;
21 import org.simantics.browsing.ui.content.LabelDecoratorFactory;
22 import org.simantics.utils.ReflectionUtils;
23
24 public abstract class PartialEvaluatorFactory<T> implements EvaluatorFactory {
25
26         final private Class<?> clazz;
27
28     public PartialEvaluatorFactory() {
29         clazz = ReflectionUtils.getSingleParameterType(getClass());
30     }
31     
32         @Override
33         public Evaluator create(Collection<String> browseContexts) {
34                 EvaluatorImpl result = new EvaluatorImpl();
35                 double preference = getPreference();
36                 {
37                         ComparableContextFactory factory = createComparableFactory();
38                         if(factory != null)
39                                 result.addComparator(factory, preference);
40                 }
41                 {
42                         LabelDecoratorFactory factory = createLabelDecoratorFactory();
43                         if(factory != null)
44                                 result.addLabelDecorator(factory, preference);
45                 }
46                 {
47                         ImagerFactory factory = createImagerFactory();
48                         if(factory != null)
49                                 result.addImager(factory, preference);
50                 }
51                 return result;
52         }
53         
54         protected double getPreference() {
55                 return 1.0;
56         }
57         
58         protected ComparableContextFactory createComparableFactory() {
59                 return null;
60         }
61         
62         protected LabelDecoratorFactory createLabelDecoratorFactory() {
63                 return null;
64         }       
65         
66         protected ImagerFactory createImagerFactory() {
67                 return null;
68         }       
69
70         @Override
71         public Class<?> getClazz() {
72                 return clazz;
73         }
74
75 }