comparison dwtx/jface/viewers/CellLabelProvider.d @ 10:b6c35faf97c8

Viewers
author Frank Benoit <benoit@tionex.de>
date Mon, 31 Mar 2008 00:47:19 +0200
parents
children a6683645b0d7
comparison
equal deleted inserted replaced
9:6c14e54dfc11 10:b6c35faf97c8
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 Shindl <tom.schindl@bestsolution.at> - initial API and implementation
11 * - bug fixes for 182443
12 * Port to the D programming language:
13 * Frank Benoit <benoit@tionex.de>
14 *******************************************************************************/
15
16 module dwtx.jface.viewers.CellLabelProvider;
17
18 import dwtx.jface.viewers.IBaseLabelProvider;
19 import dwtx.jface.viewers.BaseLabelProvider;
20 import dwtx.jface.viewers.ColumnViewer;
21 import dwtx.jface.viewers.ViewerCell;
22 import dwtx.jface.viewers.AbstractTreeViewer;
23 import dwtx.jface.viewers.ITableLabelProvider;
24 import dwtx.jface.viewers.ITableColorProvider;
25 import dwtx.jface.viewers.ITableFontProvider;
26 import dwtx.jface.viewers.TableColumnViewerLabelProvider;
27 import dwtx.jface.viewers.WrappedViewerLabelProvider;
28
29 import dwt.DWT;
30 import dwt.custom.CLabel;
31 import dwt.graphics.Color;
32 import dwt.graphics.Font;
33 import dwt.graphics.Image;
34 import dwt.graphics.Point;
35
36 import dwt.dwthelper.utils;
37
38 /**
39 * The CellLabelProvider is an abstract implementation of a label provider for
40 * structured viewers.
41 *
42 * <p><b>This class is intended to be subclassed</b></p>
43 *
44 * @since 3.3
45 * @see ColumnLabelProvider as a concrete implementation
46 */
47 public abstract class CellLabelProvider : BaseLabelProvider {
48
49 /**
50 * Create a new instance of the receiver.
51 */
52 public this() {
53 }
54
55 /**
56 * Create a ViewerLabelProvider for the column at index
57 *
58 * @param labelProvider
59 * The labelProvider to convert
60 * @return ViewerLabelProvider
61 */
62 /* package */static CellLabelProvider createViewerLabelProvider(
63 ColumnViewer viewer, IBaseLabelProvider labelProvider) {
64
65 bool noColumnTreeViewer = ( null !is cast(AbstractTreeViewer)viewer ) && viewer
66 .doGetColumnCount_package() is 0;
67
68 if (!noColumnTreeViewer
69 && (null !is cast(ITableLabelProvider) labelProvider
70 || null !is cast(ITableColorProvider) labelProvider || null !is cast(ITableFontProvider)labelProvider ))
71 return new TableColumnViewerLabelProvider(labelProvider);
72 if ( cast(CellLabelProvider)labelProvider )
73 return cast(CellLabelProvider) labelProvider;
74 return new WrappedViewerLabelProvider(labelProvider);
75
76 }
77
78 /**
79 * Get the image displayed in the tool tip for object.
80 *
81 * <p>
82 * <b>If {@link #getToolTipText(Object)} and
83 * {@link #getToolTipImage(Object)} both return <code>null</code> the
84 * control is set back to standard behavior</b>
85 * </p>
86 *
87 * @param object
88 * the element for which the tool tip is shown
89 * @return {@link Image} or <code>null</code> if there is not image.
90 */
91
92 public Image getToolTipImage(Object object) {
93 return null;
94 }
95
96 /**
97 * Get the text displayed in the tool tip for object.
98 *
99 * <p>
100 * <b>If {@link #getToolTipText(Object)} and
101 * {@link #getToolTipImage(Object)} both return <code>null</code> the
102 * control is set back to standard behavior</b>
103 * </p>
104 *
105 * @param element
106 * the element for which the tool tip is shown
107 * @return the {@link String} or <code>null</code> if there is not text to
108 * display
109 */
110 public String getToolTipText(Object element) {
111 return null;
112 }
113
114 /**
115 * Return the background color used for the tool tip
116 *
117 * @param object
118 * the {@link Object} for which the tool tip is shown
119 *
120 * @return the {@link Color} used or <code>null</code> if you want to use
121 * the default color {@link DWT#COLOR_INFO_BACKGROUND}
122 * @see DWT#COLOR_INFO_BACKGROUND
123 */
124 public Color getToolTipBackgroundColor(Object object) {
125 return null;
126 }
127
128 /**
129 * The foreground color used to display the the text in the tool tip
130 *
131 * @param object
132 * the {@link Object} for which the tool tip is shown
133 * @return the {@link Color} used or <code>null</code> if you want to use
134 * the default color {@link DWT#COLOR_INFO_FOREGROUND}
135 * @see DWT#COLOR_INFO_FOREGROUND
136 */
137 public Color getToolTipForegroundColor(Object object) {
138 return null;
139 }
140
141 /**
142 * Get the {@link Font} used to display the tool tip
143 *
144 * @param object
145 * the element for which the tool tip is shown
146 * @return {@link Font} or <code>null</code> if the default font is to be
147 * used.
148 */
149 public Font getToolTipFont(Object object) {
150 return null;
151 }
152
153 /**
154 * Return the amount of pixels in x and y direction you want the tool tip to
155 * pop up from the mouse pointer. The default shift is 10px right and 0px
156 * below your mouse cursor. Be aware of the fact that you should at least
157 * position the tool tip 1px right to your mouse cursor else click events
158 * may not get propagated properly.
159 *
160 * @param object
161 * the element for which the tool tip is shown
162 * @return {@link Point} to shift of the tool tip or <code>null</code> if the
163 * default shift should be used.
164 */
165 public Point getToolTipShift(Object object) {
166 return null;
167 }
168
169 /**
170 * Return whether or not to use the native tool tip. If you switch to native
171 * tool tips only the value from {@link #getToolTipText(Object)} is used all
172 * other features from custom tool tips are not supported.
173 *
174 * <p>
175 * To reset the control to native behavior you should return
176 * <code>true</code> from this method and <code>null</code> from
177 * {@link #getToolTipText(Object)} or <code>null</code> from
178 * {@link #getToolTipText(Object)} and {@link #getToolTipImage(Object)} at
179 * the same time
180 * </p>
181 *
182 * @param object
183 * the {@link Object} for which the tool tip is shown
184 * @return <code>true</code> if native tool tips should be used
185 */
186 public bool useNativeToolTip(Object object) {
187 return false;
188 }
189
190 /**
191 * The time in milliseconds the tool tip is shown for.
192 *
193 * @param object
194 * the {@link Object} for which the tool tip is shown
195 * @return time in milliseconds the tool tip is shown for
196 */
197 public int getToolTipTimeDisplayed(Object object) {
198 return 0;
199 }
200
201 /**
202 * The time in milliseconds until the tool tip is displayed.
203 *
204 * @param object
205 * the {@link Object} for which the tool tip is shown
206 * @return time in milliseconds until the tool tip is displayed
207 */
208 public int getToolTipDisplayDelayTime(Object object) {
209 return 0;
210 }
211
212 /**
213 * The {@link DWT} style used to create the {@link CLabel} (see there for
214 * supported styles). By default {@link DWT#SHADOW_NONE} is used.
215 *
216 * @param object
217 * the element for which the tool tip is shown
218 * @return the style used to create the label
219 * @see CLabel
220 */
221 public int getToolTipStyle(Object object) {
222 return DWT.SHADOW_NONE;
223 }
224
225 /**
226 * Update the label for cell.
227 *
228 * @param cell
229 * {@link ViewerCell}
230 */
231 public abstract void update(ViewerCell cell);
232
233 }