]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contributor/imager/ImageDecoratorContributorImpl.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / contributor / imager / ImageDecoratorContributorImpl.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.graph.impl.contributor.imager;
13
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;
26
27 /**
28  * @author Tuukka Lehtonen
29  *
30  * @param <T>
31  */
32 public abstract class ImageDecoratorContributorImpl<T> implements Contributor<ImageDecoratorFactory> {
33
34     abstract public ImageDecorator getDecorator(ReadGraph graph, T input) throws DatabaseException;
35
36     final private Class<?> clazz;
37
38     @Override
39     public Tester getNodeContextTester() {
40         return null;
41     }
42
43     public ImageDecoratorContributorImpl() {
44         clazz = ReflectionUtils.getSingleParameterType(getClass());
45     }
46
47     public ImageDecoratorContributorImpl(Class<?> clazz) {
48         this.clazz = clazz;
49     }
50
51     @Override
52     public ImageDecoratorFactory getFactory() {
53
54         return new ImageDecoratorFactory() {
55
56             @Override
57             public ImageDecorator create(final PrimitiveQueryUpdater updater, NodeContext context, ImageDecoratorKey key) {
58
59                 return new ImageDecoratorContributionImpl(updater, context, key) {
60
61                     @SuppressWarnings("unchecked")
62                     @Override
63                     public ImageDecorator getDecorator(ReadGraph graph, NodeContext context) throws DatabaseException {
64
65                         T input = (T)context.getConstant(BuiltinKeys.INPUT);
66
67                         return ImageDecoratorContributorImpl.this.getDecorator(graph, input);
68
69                     }
70
71                 };
72
73             }
74
75         };
76
77     }
78
79     @Override
80     public Class<?> getInputClass() {
81         return clazz;
82     }
83
84 }