1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.graph.impl.contributor.labeler;
14 import org.simantics.browsing.ui.BuiltinKeys;
15 import org.simantics.browsing.ui.CheckedState;
16 import org.simantics.browsing.ui.NodeContext;
17 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
18 import org.simantics.browsing.ui.Tester;
19 import org.simantics.browsing.ui.BuiltinKeys.CheckedStateKey;
20 import org.simantics.browsing.ui.content.CheckedStateFactory;
21 import org.simantics.browsing.ui.content.Contributor;
22 import org.simantics.browsing.ui.graph.impl.contribution.CheckedStateContributionImpl;
23 import org.simantics.db.ReadGraph;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.utils.ReflectionUtils;
27 abstract public class CheckedStateContributorImpl<T> implements Contributor<CheckedStateFactory> {
29 abstract public CheckedState getState(ReadGraph graph, T input) throws DatabaseException;
31 final private Class<?> clazz;
34 public Tester getNodeContextTester() {
38 public CheckedStateContributorImpl() {
39 clazz = ReflectionUtils.getSingleParameterType(getClass());
42 public CheckedStateContributorImpl(Class<?> clazz) {
47 public CheckedStateFactory getFactory() {
49 return new CheckedStateFactory() {
52 public CheckedState create(final PrimitiveQueryUpdater updater, NodeContext context, final CheckedStateKey key) {
54 CheckedStateContributionImpl contrib = new CheckedStateContributionImpl(updater, context, key) {
56 @SuppressWarnings("unchecked")
58 public CheckedState getState(ReadGraph graph, NodeContext context) throws DatabaseException {
59 T input = (T)context.getConstant(BuiltinKeys.INPUT);
60 return CheckedStateContributorImpl.this.getState(graph, input);
65 return contrib.getState();
74 public Class<?> getInputClass() {