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.g2d.tooltip;
14 import org.simantics.g2d.diagram.IDiagram;
15 import org.simantics.g2d.diagram.IDiagram.CompositionListener;
16 import org.simantics.g2d.element.IElement;
17 import org.simantics.g2d.element.handler.Clickable.PressStatus;
18 import org.simantics.g2d.element.handler.impl.AbstractClickable;
19 import org.simantics.utils.datastructures.hints.IHintContext.Key;
20 import org.simantics.utils.datastructures.hints.IHintListener;
21 import org.simantics.utils.datastructures.hints.IHintObservable;
26 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
29 public class TooltipParticipant extends BaseTooltipParticipant implements CompositionListener {
31 private final ElementHoverListener listener = new ElementHoverListener();
33 public TooltipParticipant() {
37 protected void onDiagramSet(IDiagram newValue, IDiagram oldValue) {
38 if (oldValue == newValue)
40 if (oldValue != null) {
41 for (IElement e : oldValue.getElements()) {
44 oldValue.removeCompositionListener(this);
46 if (newValue != null) {
47 for (IElement e : newValue.getElements()) {
50 newValue.addCompositionListener(this);
55 public void onElementAdded(IDiagram d, IElement e) {
60 public void onElementRemoved(IDiagram d, IElement e) {
64 private void addElement(IElement e) {
65 e.addKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, listener);
68 private void removeElement(IElement e) {
69 e.removeKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, listener);
74 class ElementHoverListener implements IHintListener {
77 public void hintChanged(IHintObservable sender, Key key,
78 Object oldValue, Object newValue) {
79 IElement element = (IElement)sender;
80 PressStatus status = (PressStatus)newValue;
81 if (status == PressStatus.HOVER) {
82 showTooltipFor(element);
86 //System.out.println("ttp element changed " + element + " " + status);
90 public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {