Mercurial > projects > dwt-addons
annotate dwtx/jface/viewers/ColumnViewerToolTipSupport.d @ 43:ea8ff534f622
Fix override and super aliases
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 11 Apr 2008 01:24:25 +0200 |
parents | b6c35faf97c8 |
children | 46a6e0e6ccd4 |
rev | line source |
---|---|
10 | 1 /******************************************************************************* |
2 * Copyright (c) 2006, 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation | |
11 * Fredy Dobler <fredy@dobler.net> - bug 159600 | |
12 * Brock Janiczak <brockj@tpg.com.au> - bug 182443 | |
13 * Port to the D programming language: | |
14 * Frank Benoit <benoit@tionex.de> | |
15 *******************************************************************************/ | |
16 | |
17 module dwtx.jface.viewers.ColumnViewerToolTipSupport; | |
18 | |
19 import dwtx.jface.viewers.ColumnViewer; | |
20 import dwtx.jface.viewers.ViewerRow; | |
21 import dwtx.jface.viewers.ViewerColumn; | |
22 import dwtx.jface.viewers.CellLabelProvider; | |
23 import dwtx.jface.viewers.StructuredSelection; | |
24 | |
25 import dwt.DWT; | |
26 import dwt.graphics.Image; | |
27 import dwt.graphics.Point; | |
28 import dwt.widgets.Event; | |
29 import dwtx.jface.util.Policy; | |
30 import dwtx.jface.window.DefaultToolTip; | |
31 import dwtx.jface.window.ToolTip; | |
32 | |
33 import dwt.dwthelper.utils; | |
34 | |
35 /** | |
36 * The ColumnViewerTooltipSupport is the class that provides tool tips for ColumnViewers. | |
37 * | |
38 * @since 3.3 | |
39 * | |
40 */ | |
41 public class ColumnViewerToolTipSupport : DefaultToolTip { | |
42 private ColumnViewer viewer; | |
43 | |
44 private static const String LABEL_PROVIDER_KEY = Policy.JFACE | |
45 ~ "_LABEL_PROVIDER"; //$NON-NLS-1$ | |
46 | |
47 private static const String ELEMENT_KEY = Policy.JFACE ~ "_ELEMENT_KEY"; //$NON-NLS-1$ | |
48 | |
49 private static const int DEFAULT_SHIFT_X = 10; | |
50 | |
51 private static const int DEFAULT_SHIFT_Y = 0; | |
52 | |
53 /** | |
54 * Enable ToolTip support for the viewer by creating an instance from this | |
55 * class. To get all necessary informations this support class consults the | |
56 * {@link CellLabelProvider}. | |
57 * | |
58 * @param viewer | |
59 * the viewer the support is attached to | |
60 * @param style style passed to control tool tip behavior | |
61 * | |
62 * @param manualActivation | |
63 * <code>true</code> if the activation is done manually using | |
64 * {@link #show(Point)} | |
65 */ | |
66 protected this(ColumnViewer viewer, int style, bool manualActivation ) { | |
67 super(viewer.getControl(),style,manualActivation); | |
68 this.viewer = viewer; | |
69 } | |
70 | |
71 /** | |
72 * Enable ToolTip support for the viewer by creating an instance from this | |
73 * class. To get all necessary informations this support class consults the | |
74 * {@link CellLabelProvider}. | |
75 * | |
76 * @param viewer | |
77 * the viewer the support is attached to | |
78 */ | |
79 public static void enableFor(ColumnViewer viewer) { | |
80 new ColumnViewerToolTipSupport(viewer,ToolTip.NO_RECREATE,false); | |
81 } | |
82 | |
83 /** | |
84 * Enable ToolTip support for the viewer by creating an instance from this | |
85 * class. To get all necessary informations this support class consults the | |
86 * {@link CellLabelProvider}. | |
87 * | |
88 * @param viewer | |
89 * the viewer the support is attached to | |
90 * @param style style passed to control tool tip behavior | |
91 * | |
92 * @see ToolTip#RECREATE | |
93 * @see ToolTip#NO_RECREATE | |
94 */ | |
95 public static void enableFor(ColumnViewer viewer, int style) { | |
96 new ColumnViewerToolTipSupport(viewer,style,false); | |
97 } | |
98 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
99 protected override Object getToolTipArea(Event event) { |
10 | 100 return viewer.getCell(new Point(event.x,event.y)); |
101 } | |
102 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
103 protected override final bool shouldCreateToolTip(Event event) { |
10 | 104 if( ! super.shouldCreateToolTip(event) ) { |
105 return false; | |
106 } | |
107 | |
108 bool rv = false; | |
109 | |
110 ViewerRow row = viewer.getViewerRow_package(new Point(event.x, event.y)); | |
111 | |
112 viewer.getControl().setToolTipText(""); //$NON-NLS-1$ | |
113 Point point = new Point(event.x, event.y); | |
114 | |
115 if (row !is null) { | |
116 Object element = row.getItem().getData(); | |
117 | |
118 ViewerColumn viewPart = viewer.getViewerColumn(row | |
119 .getColumnIndex(point)); | |
120 | |
121 if (viewPart is null) { | |
122 return false; | |
123 } | |
124 | |
125 CellLabelProvider labelProvider = viewPart.getLabelProvider(); | |
126 bool useNative = labelProvider.useNativeToolTip(element); | |
127 | |
128 String text = labelProvider.getToolTipText(element); | |
129 Image img = null; | |
130 | |
131 if( ! useNative ) { | |
132 img = labelProvider.getToolTipImage(element); | |
133 } | |
134 | |
135 if( useNative || (text is null && img is null ) ) { | |
136 viewer.getControl().setToolTipText(text); | |
137 rv = false; | |
138 } else { | |
139 setPopupDelay(labelProvider.getToolTipDisplayDelayTime(element)); | |
140 setHideDelay(labelProvider.getToolTipTimeDisplayed(element)); | |
141 | |
142 Point shift = labelProvider.getToolTipShift(element); | |
143 | |
144 if (shift is null) { | |
145 setShift(new Point(DEFAULT_SHIFT_X, DEFAULT_SHIFT_Y)); | |
146 } else { | |
147 setShift(new Point(shift.x, shift.y)); | |
148 } | |
149 | |
150 setData(LABEL_PROVIDER_KEY, labelProvider); | |
151 setData(ELEMENT_KEY, element); | |
152 | |
153 setText(text); | |
154 setImage(img); | |
155 setStyle(labelProvider.getToolTipStyle(element)); | |
156 setForegroundColor(labelProvider.getToolTipForegroundColor(element)); | |
157 setBackgroundColor(labelProvider.getToolTipBackgroundColor(element)); | |
158 setFont(labelProvider.getToolTipFont(element)); | |
159 | |
160 // Check if at least one of the values is set | |
161 rv = getText(event) !is null || getImage(event) !is null; | |
162 } | |
163 } | |
164 | |
165 return rv; | |
166 } | |
167 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
168 protected override void afterHideToolTip(Event event) { |
10 | 169 if (event !is null && event.widget !is viewer.getControl()) { |
170 if (event.type is DWT.MouseDown) { | |
171 viewer.setSelection(new StructuredSelection()); | |
172 } else { | |
173 viewer.getControl().setFocus(); | |
174 } | |
175 } | |
176 } | |
177 } |