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