]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/modelBrowser/contributions/PartialEvaluatorFactory.java b/bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/modelBrowser/contributions/PartialEvaluatorFactory.java
new file mode 100644 (file)
index 0000000..9646169
--- /dev/null
@@ -0,0 +1,75 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.structural.ui.modelBrowser.contributions;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.common.EvaluatorImpl;\r
+import org.simantics.browsing.ui.common.EvaluatorData.Evaluator;\r
+import org.simantics.browsing.ui.common.extension.EvaluatorFactory;\r
+import org.simantics.browsing.ui.content.ComparableContextFactory;\r
+import org.simantics.browsing.ui.content.ImagerFactory;\r
+import org.simantics.browsing.ui.content.LabelDecoratorFactory;\r
+import org.simantics.utils.ReflectionUtils;\r
+\r
+public abstract class PartialEvaluatorFactory<T> implements EvaluatorFactory {\r
+\r
+       final private Class<?> clazz;\r
+\r
+    public PartialEvaluatorFactory() {\r
+       clazz = ReflectionUtils.getSingleParameterType(getClass());\r
+    }\r
+    \r
+       @Override\r
+       public Evaluator create(Collection<String> browseContexts) {\r
+               EvaluatorImpl result = new EvaluatorImpl();\r
+               double preference = getPreference();\r
+               {\r
+                       ComparableContextFactory factory = createComparableFactory();\r
+                       if(factory != null)\r
+                               result.addComparator(factory, preference);\r
+               }\r
+               {\r
+                       LabelDecoratorFactory factory = createLabelDecoratorFactory();\r
+                       if(factory != null)\r
+                               result.addLabelDecorator(factory, preference);\r
+               }\r
+               {\r
+                       ImagerFactory factory = createImagerFactory();\r
+                       if(factory != null)\r
+                               result.addImager(factory, preference);\r
+               }\r
+               return result;\r
+       }\r
+       \r
+       protected double getPreference() {\r
+               return 1.0;\r
+       }\r
+       \r
+       protected ComparableContextFactory createComparableFactory() {\r
+               return null;\r
+       }\r
+       \r
+       protected LabelDecoratorFactory createLabelDecoratorFactory() {\r
+               return null;\r
+       }       \r
+       \r
+       protected ImagerFactory createImagerFactory() {\r
+               return null;\r
+       }       \r
+\r
+       @Override\r
+       public Class<?> getClazz() {\r
+               return clazz;\r
+       }\r
+\r
+}\r