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;
15 import java.util.HashMap;
18 import org.simantics.browsing.ui.BuiltinKeys;
19 import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;
20 import org.simantics.browsing.ui.NodeContext;
21 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
22 import org.simantics.browsing.ui.Tester;
23 import org.simantics.browsing.ui.content.Contributor;
24 import org.simantics.browsing.ui.content.Labeler;
25 import org.simantics.browsing.ui.content.Labeler.Modifier;
26 import org.simantics.browsing.ui.content.LabelerFactory;
27 import org.simantics.browsing.ui.graph.impl.contribution.LabelerContributionImpl;
28 import org.simantics.db.ReadGraph;
29 import org.simantics.db.UndoContext;
30 import org.simantics.db.exception.DatabaseException;
31 import org.simantics.utils.ReflectionUtils;
33 abstract public class ColumnLabelerContributorImpl<T> implements Contributor<LabelerFactory> {
35 abstract public Map<String, String> getLabel(ReadGraph graph, T input) throws DatabaseException;
37 public int getCategory(ReadGraph graph, T input) throws DatabaseException {
41 public Modifier getModifier(ReadGraph graph, UndoContext context, T input, String columnKey) throws DatabaseException {
45 final private Class<?> clazz;
48 public Tester getNodeContextTester() {
52 public ColumnLabelerContributorImpl() {
53 clazz = ReflectionUtils.getSingleParameterType(getClass());
56 public ColumnLabelerContributorImpl(Class<?> clazz) {
60 public boolean shouldCreateToolTip(Object event, T input, Map<Object, Object> auxiliary) {
64 public Object createToolTipContentArea(Object event, Object parent, T input, Map<Object, Object> auxiliary) {
69 public LabelerFactory getFactory() {
71 return new LabelerFactory() {
74 public Labeler create(final PrimitiveQueryUpdater updater, NodeContext context, final LabelerKey key) {
76 return new LabelerContributionImpl(updater, context, key) {
78 @SuppressWarnings("unchecked")
80 public Map<String, String> labels(ReadGraph graph, NodeContext context) throws DatabaseException {
82 T input = (T)context.getConstant(BuiltinKeys.INPUT);
84 return ColumnLabelerContributorImpl.this.getLabel(graph, input);
88 @SuppressWarnings("unchecked")
90 public int category(ReadGraph graph, NodeContext context) throws DatabaseException {
92 T input = (T)context.getConstant(BuiltinKeys.INPUT);
94 return ColumnLabelerContributorImpl.this.getCategory(graph, input);
98 @SuppressWarnings("unchecked")
100 public Modifier getModifier(ReadGraph graph, UndoContext undoContext, NodeContext context, String columnKey) throws DatabaseException {
102 T input = (T)context.getConstant(BuiltinKeys.INPUT);
104 return ColumnLabelerContributorImpl.this.getModifier(graph, undoContext, input, columnKey);
109 public String toString() {
110 return ColumnLabelerContributorImpl.this.toString();
113 private Map<Object, Object> auxiliary = new HashMap<>();
116 public boolean createToolTip(Object event, NodeContext nodeContext) {
117 T input = (T)context.getConstant(BuiltinKeys.INPUT);
118 return ColumnLabelerContributorImpl.this.shouldCreateToolTip(event, input, auxiliary);
122 public Object createToolTipContent(Object event, Object parent, NodeContext nodeContext) {
123 T input = (T)context.getConstant(BuiltinKeys.INPUT);
125 return ColumnLabelerContributorImpl.this.createToolTipContentArea(event, parent, input, auxiliary);
140 public Class<?> getInputClass() {