]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contributor/labeler/LabelDecoratorContributorImpl.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 / labeler / LabelDecoratorContributorImpl.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.labeler;
13
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;
26
27 abstract public class LabelDecoratorContributorImpl<T> implements Contributor<LabelDecoratorFactory> {
28
29     abstract public LabelDecorator getDecorator(ReadGraph graph, T input) throws DatabaseException;
30
31     final private Class<?> clazz;
32
33     @Override
34     public Tester getNodeContextTester() {
35         return null;
36     }
37
38     public LabelDecoratorContributorImpl() {
39         clazz = ReflectionUtils.getSingleParameterType(getClass());
40     }
41
42     public LabelDecoratorContributorImpl(Class<?> clazz) {
43         this.clazz = clazz;
44     }
45
46     @Override
47     public LabelDecoratorFactory getFactory() {
48
49         return new LabelDecoratorFactory() {
50
51             @Override
52             public LabelDecorator create(final PrimitiveQueryUpdater updater, NodeContext context, LabelDecoratorKey key) {
53
54                 return new LabelDecoratorContributionImpl(updater, context, key) {
55
56                     @SuppressWarnings("unchecked")
57                     @Override
58                     public LabelDecorator getDecorator(ReadGraph graph, NodeContext context) throws DatabaseException {
59
60                         T input = (T)context.getConstant(BuiltinKeys.INPUT);
61
62                         return LabelDecoratorContributorImpl.this.getDecorator(graph, input);
63
64                     }
65
66                 };
67
68             }
69
70         };
71
72     }
73
74     @Override
75     public Class<?> getInputClass() {
76         return clazz;
77     }
78
79 }