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;
16 import org.simantics.browsing.ui.BuiltinKeys;
17 import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;
18 import org.simantics.browsing.ui.NodeContext;
19 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
20 import org.simantics.browsing.ui.Tester;
21 import org.simantics.browsing.ui.content.Contributor;
22 import org.simantics.browsing.ui.content.Labeler;
23 import org.simantics.browsing.ui.content.Labeler.Modifier;
24 import org.simantics.browsing.ui.content.LabelerFactory;
25 import org.simantics.browsing.ui.graph.impl.contribution.LabelerContributionImpl;
26 import org.simantics.db.ReadGraph;
27 import org.simantics.db.UndoContext;
28 import org.simantics.db.exception.DatabaseException;
29 import org.simantics.utils.ReflectionUtils;
31 abstract public class ColumnLabelerContributorImpl<T> implements Contributor<LabelerFactory> {
33 abstract public Map<String, String> getLabel(ReadGraph graph, T input) throws DatabaseException;
35 public int getCategory(ReadGraph graph, T input) throws DatabaseException {
39 public Modifier getModifier(ReadGraph graph, UndoContext context, T input, String columnKey) throws DatabaseException {
43 final private Class<?> clazz;
46 public Tester getNodeContextTester() {
50 public ColumnLabelerContributorImpl() {
51 clazz = ReflectionUtils.getSingleParameterType(getClass());
54 public ColumnLabelerContributorImpl(Class<?> clazz) {
59 public LabelerFactory getFactory() {
61 return new LabelerFactory() {
64 public Labeler create(final PrimitiveQueryUpdater updater, NodeContext context, final LabelerKey key) {
66 return new LabelerContributionImpl(updater, context, key) {
68 @SuppressWarnings("unchecked")
70 public Map<String, String> labels(ReadGraph graph, NodeContext context) throws DatabaseException {
72 T input = (T)context.getConstant(BuiltinKeys.INPUT);
74 return ColumnLabelerContributorImpl.this.getLabel(graph, input);
78 @SuppressWarnings("unchecked")
80 public int category(ReadGraph graph, NodeContext context) throws DatabaseException {
82 T input = (T)context.getConstant(BuiltinKeys.INPUT);
84 return ColumnLabelerContributorImpl.this.getCategory(graph, input);
88 @SuppressWarnings("unchecked")
90 public Modifier getModifier(ReadGraph graph, UndoContext undoContext, NodeContext context, String columnKey) throws DatabaseException {
92 T input = (T)context.getConstant(BuiltinKeys.INPUT);
94 return ColumnLabelerContributorImpl.this.getModifier(graph, undoContext, input, columnKey);
99 public String toString() {
100 return ColumnLabelerContributorImpl.this.toString();
112 public Class<?> getInputClass() {