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;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.simantics.browsing.ui.BuiltinKeys;
18 import org.simantics.browsing.ui.BuiltinKeys.ImagerKey;
19 import org.simantics.browsing.ui.NodeContext;
20 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
21 import org.simantics.browsing.ui.Tester;
22 import org.simantics.browsing.ui.common.ColumnKeys;
23 import org.simantics.browsing.ui.content.Contributor;
24 import org.simantics.browsing.ui.content.Imager;
25 import org.simantics.browsing.ui.content.ImagerFactory;
26 import org.simantics.browsing.ui.graph.impl.contribution.ImagerContributionImpl;
27 import org.simantics.db.ReadGraph;
28 import org.simantics.db.exception.DatabaseException;
29 import org.simantics.utils.ReflectionUtils;
30 import org.simantics.utils.datastructures.ArrayMap;
32 abstract public class ImagerContributorImpl<T> implements Contributor<ImagerFactory> {
34 abstract public ImageDescriptor getDescriptor(ReadGraph graph, T input) throws DatabaseException;
36 final private Class<?> clazz;
39 public String toString() {
40 return getClass().getName();
44 public Tester getNodeContextTester() {
48 public ImagerContributorImpl() {
49 clazz = ReflectionUtils.getSingleParameterType(getClass());
52 public ImagerContributorImpl(Class<?> clazz) {
57 public ImagerFactory getFactory() {
59 return new ImagerFactory() {
62 public String toString() {
63 return ImagerContributorImpl.this.toString();
66 @SuppressWarnings("unchecked")
68 public Imager create(final PrimitiveQueryUpdater updater, NodeContext context, final ImagerKey key) {
70 return new ImagerContributionImpl(updater, context, key) {
73 public Map<String, ImageDescriptor> getDescriptors(ReadGraph graph, NodeContext context) throws DatabaseException {
75 T input = (T)context.getConstant(BuiltinKeys.INPUT);
77 ImageDescriptor value = ImagerContributorImpl.this.getDescriptor(graph, input);
79 return new ArrayMap<String, ImageDescriptor>(ColumnKeys.KEYS_SINGLE,
80 new ImageDescriptor[] { value });
93 public Class<?> getInputClass() {