blob: 1c3d4fec5744b4b0c9244ce14616e0a501e8b1fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Google, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.internal.core.model.property.table;
import org.eclipse.wb.internal.core.model.property.Property;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
/**
* Provider for tooltip controls.
*
* @author scheglov_ke
* @coverage core.model.property.table
*/
public abstract class PropertyTooltipProvider {
/**
* Show tooltip directly on property row.
*/
public static final int ON = 0;
/**
* Show tooltip below property row.
*/
public static final int BELOW = 1;
////////////////////////////////////////////////////////////////////////////
//
// PropertyTooltipProvider
//
////////////////////////////////////////////////////////////////////////////
/**
* Create tooltip control.
*/
public abstract Control createTooltipControl(Property property,
Composite parent,
int availableWidth,
IPropertyTooltipSite site);
/**
* Shows tooltip {@link Shell}.
*/
public void show(Shell shell) {
shell.setVisible(true);
}
/**
* Returns position for tooltip control. Usually we should show directly on same row, because we
* use tooltip to show just longer (full) text of property. But for "class" property we show
* hierarchy, so it is better show it below and allow user see also property row.
*/
public int getTooltipPosition() {
return ON;
}
////////////////////////////////////////////////////////////////////////////
//
// Tooltip listener
//
////////////////////////////////////////////////////////////////////////////
/**
* {@link Listener} that hides tooltip on mouse exit or click.
*/
protected static final class HideListener implements Listener {
private final IPropertyTooltipSite m_site;
////////////////////////////////////////////////////////////////////////////
//
// Constructor
//
////////////////////////////////////////////////////////////////////////////
public HideListener(IPropertyTooltipSite site) {
m_site = site;
}
////////////////////////////////////////////////////////////////////////////
//
// Listener
//
////////////////////////////////////////////////////////////////////////////
public void handleEvent(Event event) {
Control tooltipControl = (Control) event.widget;
switch (event.type) {
case SWT.MouseDown : {
PropertyTable table = m_site.getTable();
// convert location from tooltip to table
Point p = new Point(event.x, event.y);
p = tooltipControl.toDisplay(p);
p = table.toControl(p);
// send MouseDown to table
Event newEvent = new Event();
newEvent.x = p.x;
newEvent.y = p.y;
table.notifyListeners(SWT.MouseDown, newEvent);
// hide tooltip
m_site.hideTooltip();
break;
}
case SWT.MouseExit :
m_site.hideTooltip();
break;
}
}
}
}
|