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;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.KeyAdapter;
17 import org.eclipse.swt.events.KeyEvent;
18 import org.eclipse.swt.layout.FillLayout;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Display;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.swt.widgets.Text;
24 import org.simantics.g2d.element.IElement;
26 public abstract class EditableTextTooltipProvider2 implements FocusableTooltipProvider {
32 public void showTooltip(final IElement element, final int x, final int y) {
33 Display.getDefault().asyncExec(new Runnable() {
40 shell = new Shell(Display.getCurrent().getActiveShell(),SWT.NO_TRIM);
41 shell.setLayout(new FillLayout());
42 Composite composite = new Composite(shell, SWT.BORDER);
43 composite.setLayout(new FillLayout(SWT.VERTICAL));
44 Label label = new Label(composite,SWT.NONE);
45 label.setText("Press 'F9' to focus");
46 text = new Text(composite, SWT.SINGLE);
47 text.setText(getTooltipText(element));
48 text.addKeyListener(new KeyAdapter() {
50 public void keyReleased(KeyEvent e) {
51 if (e.keyCode == SWT.CR) {
52 setText(element, text.getText());
59 shell.setVisible(true);
60 shell.setLocation(x, y-32);
68 public void hideTooltip(IElement element) {
71 Display.getDefault().asyncExec(new Runnable() {
82 Display.getDefault().asyncExec(new Runnable() {
85 if (!shell.isDisposed())
90 boolean has_focus = false;
93 public boolean hasFocus() {
95 Display.getDefault().syncExec(new Runnable() {
99 if(shell != null && !shell.isDisposed())
100 has_focus = shell.isFocusControl() || text.isFocusControl();
110 public abstract String getTooltipText(IElement element);
112 public abstract void setText(IElement element, String text);