]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contributor/labeler/ColumnLabelerContributorImpl.java
Passing data between tooltip check and content creation.
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / contributor / labeler / ColumnLabelerContributorImpl.java
index d1dab0fb97adc521097769b14d88e115f15be79f..51963dce2d669bd8b9a3e1cb24c659db058829d2 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2018 Association for Decentralized Information Management
  * in Industry THTH ry.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -8,9 +8,11 @@
  *
  * Contributors:
  *     VTT Technical Research Centre of Finland - initial API and implementation
+ *     Semantum Oy - gitlab #146 - tooltip support
  *******************************************************************************/
 package org.simantics.browsing.ui.graph.impl.contributor.labeler;
 
+import java.util.HashMap;
 import java.util.Map;
 
 import org.simantics.browsing.ui.BuiltinKeys;
@@ -55,6 +57,14 @@ abstract public class ColumnLabelerContributorImpl<T> implements Contributor<Lab
         this.clazz = clazz;
     }
 
+    public boolean shouldCreateToolTip(Object event, T input, Map<Object, Object> auxiliary) {
+        return false;
+    }
+
+    public Object createToolTipContentArea(Object event, Object parent, T input, Map<Object, Object> auxiliary) {
+        return null;
+    }
+
     @Override
     public LabelerFactory getFactory() {
 
@@ -99,6 +109,24 @@ abstract public class ColumnLabelerContributorImpl<T> implements Contributor<Lab
                     public String toString() {
                         return ColumnLabelerContributorImpl.this.toString();
                     }
+                    
+                    private Map<Object, Object> auxiliary = new HashMap<>();
+
+                    @Override
+                    public boolean createToolTip(Object event, NodeContext nodeContext) {
+                        T input = (T)context.getConstant(BuiltinKeys.INPUT);
+                        return ColumnLabelerContributorImpl.this.shouldCreateToolTip(event, input, auxiliary);
+                    }
+
+                    @Override
+                    public Object createToolTipContent(Object event, Object parent, NodeContext nodeContext) {
+                        T input = (T)context.getConstant(BuiltinKeys.INPUT);
+                        try {
+                            return ColumnLabelerContributorImpl.this.createToolTipContentArea(event, parent, input, auxiliary);
+                        } finally {
+                            auxiliary.clear();
+                        }
+                    }
 
                 };