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.NodeContext;
16 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
17 import org.simantics.browsing.ui.Tester;
18 import org.simantics.browsing.ui.BuiltinKeys.LabelDecoratorKey;
19 import org.simantics.browsing.ui.content.Contributor;
20 import org.simantics.browsing.ui.content.LabelDecorator;
21 import org.simantics.browsing.ui.content.LabelDecoratorFactory;
22 import org.simantics.browsing.ui.graph.impl.contribution.LabelDecoratorContributionImpl;
23 import org.simantics.db.ReadGraph;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.utils.ReflectionUtils;
27 abstract public class LabelDecoratorContributorImpl<T> implements Contributor<LabelDecoratorFactory> {
29 abstract public LabelDecorator getDecorator(ReadGraph graph, T input) throws DatabaseException;
31 final private Class<?> clazz;
34 public Tester getNodeContextTester() {
38 public LabelDecoratorContributorImpl() {
39 clazz = ReflectionUtils.getSingleParameterType(getClass());
42 public LabelDecoratorContributorImpl(Class<?> clazz) {
47 public LabelDecoratorFactory getFactory() {
49 return new LabelDecoratorFactory() {
52 public LabelDecorator create(final PrimitiveQueryUpdater updater, NodeContext context, LabelDecoratorKey key) {
54 return new LabelDecoratorContributionImpl(updater, context, key) {
56 @SuppressWarnings("unchecked")
58 public LabelDecorator getDecorator(ReadGraph graph, NodeContext context) throws DatabaseException {
60 T input = (T)context.getConstant(BuiltinKeys.INPUT);
62 return LabelDecoratorContributorImpl.this.getDecorator(graph, input);
75 public Class<?> getInputClass() {