--- /dev/null
+/*******************************************************************************\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.browsing.ui.graph.impl.contributor.labeler;\r
+\r
+import org.simantics.browsing.ui.BuiltinKeys;\r
+import org.simantics.browsing.ui.CheckedState;\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.PrimitiveQueryUpdater;\r
+import org.simantics.browsing.ui.Tester;\r
+import org.simantics.browsing.ui.BuiltinKeys.CheckedStateKey;\r
+import org.simantics.browsing.ui.content.CheckedStateFactory;\r
+import org.simantics.browsing.ui.content.Contributor;\r
+import org.simantics.browsing.ui.graph.impl.contribution.CheckedStateContributionImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.utils.ReflectionUtils;\r
+\r
+abstract public class CheckedStateContributorImpl<T> implements Contributor<CheckedStateFactory> {\r
+\r
+ abstract public CheckedState getState(ReadGraph graph, T input) throws DatabaseException;\r
+\r
+ final private Class<?> clazz;\r
+\r
+ @Override\r
+ public Tester getNodeContextTester() {\r
+ return null;\r
+ }\r
+\r
+ public CheckedStateContributorImpl() {\r
+ clazz = ReflectionUtils.getSingleParameterType(getClass());\r
+ }\r
+\r
+ public CheckedStateContributorImpl(Class<?> clazz) {\r
+ this.clazz = clazz;\r
+ }\r
+\r
+ @Override\r
+ public CheckedStateFactory getFactory() {\r
+\r
+ return new CheckedStateFactory() {\r
+\r
+ @Override\r
+ public CheckedState create(final PrimitiveQueryUpdater updater, NodeContext context, final CheckedStateKey key) {\r
+\r
+ CheckedStateContributionImpl contrib = new CheckedStateContributionImpl(updater, context, key) {\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public CheckedState getState(ReadGraph graph, NodeContext context) throws DatabaseException {\r
+ T input = (T)context.getConstant(BuiltinKeys.INPUT);\r
+ return CheckedStateContributorImpl.this.getState(graph, input);\r
+ }\r
+\r
+ };\r
+ \r
+ return contrib.getState();\r
+\r
+ }\r
+\r
+ };\r
+\r
+ }\r
+\r
+ @Override\r
+ public Class<?> getInputClass() {\r
+ return clazz;\r
+ }\r
+\r
+}\r