1 /*******************************************************************************
2 * Copyright (c) 2007, 2018 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 * Semantum Oy - gitlab #146 - tooltip support
12 *******************************************************************************/
13 package org.simantics.browsing.ui.graph.impl.contributor.labeler;
17 import org.simantics.browsing.ui.BuiltinKeys;
18 import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;
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.content.Contributor;
23 import org.simantics.browsing.ui.content.Labeler;
24 import org.simantics.browsing.ui.content.Labeler.Modifier;
25 import org.simantics.browsing.ui.content.LabelerFactory;
26 import org.simantics.browsing.ui.graph.impl.contribution.LabelerContributionImpl;
27 import org.simantics.db.ReadGraph;
28 import org.simantics.db.UndoContext;
29 import org.simantics.db.exception.DatabaseException;
30 import org.simantics.utils.ReflectionUtils;
32 abstract public class ColumnLabelerContributorImpl<T> implements Contributor<LabelerFactory> {
34 abstract public Map<String, String> getLabel(ReadGraph graph, T input) throws DatabaseException;
36 public int getCategory(ReadGraph graph, T input) throws DatabaseException {
40 public Modifier getModifier(ReadGraph graph, UndoContext context, T input, String columnKey) throws DatabaseException {
44 final private Class<?> clazz;
47 public Tester getNodeContextTester() {
51 public ColumnLabelerContributorImpl() {
52 clazz = ReflectionUtils.getSingleParameterType(getClass());
55 public ColumnLabelerContributorImpl(Class<?> clazz) {
59 public boolean shouldCreateToolTip(Object event, T input) {
63 public Object createToolTipContentArea(Object event, Object parent, T input) {
68 public LabelerFactory getFactory() {
70 return new LabelerFactory() {
73 public Labeler create(final PrimitiveQueryUpdater updater, NodeContext context, final LabelerKey key) {
75 return new LabelerContributionImpl(updater, context, key) {
77 @SuppressWarnings("unchecked")
79 public Map<String, String> labels(ReadGraph graph, NodeContext context) throws DatabaseException {
81 T input = (T)context.getConstant(BuiltinKeys.INPUT);
83 return ColumnLabelerContributorImpl.this.getLabel(graph, input);
87 @SuppressWarnings("unchecked")
89 public int category(ReadGraph graph, NodeContext context) throws DatabaseException {
91 T input = (T)context.getConstant(BuiltinKeys.INPUT);
93 return ColumnLabelerContributorImpl.this.getCategory(graph, input);
97 @SuppressWarnings("unchecked")
99 public Modifier getModifier(ReadGraph graph, UndoContext undoContext, NodeContext context, String columnKey) throws DatabaseException {
101 T input = (T)context.getConstant(BuiltinKeys.INPUT);
103 return ColumnLabelerContributorImpl.this.getModifier(graph, undoContext, input, columnKey);
108 public String toString() {
109 return ColumnLabelerContributorImpl.this.toString();
113 public boolean createToolTip(Object event, NodeContext nodeContext) {
114 T input = (T)context.getConstant(BuiltinKeys.INPUT);
115 return ColumnLabelerContributorImpl.this.shouldCreateToolTip(event, input);
119 public Object createToolTipContent(Object event, Object parent, NodeContext nodeContext) {
120 T input = (T)context.getConstant(BuiltinKeys.INPUT);
121 return ColumnLabelerContributorImpl.this.createToolTipContentArea(event, parent, input);
133 public Class<?> getInputClass() {