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.imager;
14 import org.simantics.browsing.ui.BuiltinKeys;
15 import org.simantics.browsing.ui.BuiltinKeys.ImageDecoratorKey;
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.content.Contributor;
20 import org.simantics.browsing.ui.content.ImageDecorator;
21 import org.simantics.browsing.ui.content.ImageDecoratorFactory;
22 import org.simantics.browsing.ui.graph.impl.contribution.ImageDecoratorContributionImpl;
23 import org.simantics.db.ReadGraph;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.utils.ReflectionUtils;
28 * @author Tuukka Lehtonen
32 public abstract class ImageDecoratorContributorImpl<T> implements Contributor<ImageDecoratorFactory> {
34 abstract public ImageDecorator getDecorator(ReadGraph graph, T input) throws DatabaseException;
36 final private Class<?> clazz;
39 public Tester getNodeContextTester() {
43 public ImageDecoratorContributorImpl() {
44 clazz = ReflectionUtils.getSingleParameterType(getClass());
47 public ImageDecoratorContributorImpl(Class<?> clazz) {
52 public ImageDecoratorFactory getFactory() {
54 return new ImageDecoratorFactory() {
57 public ImageDecorator create(final PrimitiveQueryUpdater updater, NodeContext context, ImageDecoratorKey key) {
59 return new ImageDecoratorContributionImpl(updater, context, key) {
61 @SuppressWarnings("unchecked")
63 public ImageDecorator getDecorator(ReadGraph graph, NodeContext context) throws DatabaseException {
65 T input = (T)context.getConstant(BuiltinKeys.INPUT);
67 return ImageDecoratorContributorImpl.this.getDecorator(graph, input);
80 public Class<?> getInputClass() {