Mercurial > projects > dwt-addons
annotate dwtx/jface/viewers/CellLabelProvider.d @ 71:4878bef4a38e
Some fixing
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 22 May 2008 04:03:58 +0200 |
parents | 46a6e0e6ccd4 |
children | 5df4896124c7 |
rev | line source |
---|---|
10 | 1 /******************************************************************************* |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
2 * Copyright (c) 2006, 2008 IBM Corporation and others. |
10 | 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; | |
71 | 27 import dwtx.jface.viewers.ViewerColumn; |
10 | 28 import dwtx.jface.viewers.WrappedViewerLabelProvider; |
29 | |
30 import dwt.DWT; | |
31 import dwt.custom.CLabel; | |
32 import dwt.graphics.Color; | |
33 import dwt.graphics.Font; | |
34 import dwt.graphics.Image; | |
35 import dwt.graphics.Point; | |
36 | |
37 import dwt.dwthelper.utils; | |
38 | |
39 /** | |
40 * The CellLabelProvider is an abstract implementation of a label provider for | |
41 * structured viewers. | |
42 * | |
43 * <p><b>This class is intended to be subclassed</b></p> | |
44 * | |
45 * @since 3.3 | |
46 * @see ColumnLabelProvider as a concrete implementation | |
47 */ | |
48 public abstract class CellLabelProvider : BaseLabelProvider { | |
49 | |
50 /** | |
51 * Create a new instance of the receiver. | |
52 */ | |
53 public this() { | |
54 } | |
55 | |
56 /** | |
57 * Create a ViewerLabelProvider for the column at index | |
58 * | |
59 * @param labelProvider | |
60 * The labelProvider to convert | |
61 * @return ViewerLabelProvider | |
62 */ | |
63 /* package */static CellLabelProvider createViewerLabelProvider( | |
64 ColumnViewer viewer, IBaseLabelProvider labelProvider) { | |
65 | |
66 bool noColumnTreeViewer = ( null !is cast(AbstractTreeViewer)viewer ) && viewer | |
67 .doGetColumnCount_package() is 0; | |
68 | |
54
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
69 if (!noColumnTreeViewer && |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
70 ( null !is cast(ITableLabelProvider) labelProvider |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
71 || null !is cast(ITableColorProvider) labelProvider |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
72 || null !is cast(ITableFontProvider)labelProvider )){ |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
73 auto res = new TableColumnViewerLabelProvider(labelProvider); |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
74 return res; |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
75 } |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
76 if ( cast(CellLabelProvider)labelProvider ){ |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
77 auto res = cast(CellLabelProvider) labelProvider; |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
78 return res; |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
79 } |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
80 |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
81 auto res = new WrappedViewerLabelProvider(labelProvider); |
a6683645b0d7
Fix ignored labelprovider for TreeViewer (See WrapperViewerLabelProvider.d), removed the debugging prints
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
82 return res; |
10 | 83 |
84 } | |
85 | |
86 /** | |
87 * Get the image displayed in the tool tip for object. | |
88 * | |
89 * <p> | |
90 * <b>If {@link #getToolTipText(Object)} and | |
91 * {@link #getToolTipImage(Object)} both return <code>null</code> the | |
92 * control is set back to standard behavior</b> | |
93 * </p> | |
94 * | |
95 * @param object | |
96 * the element for which the tool tip is shown | |
97 * @return {@link Image} or <code>null</code> if there is not image. | |
98 */ | |
99 | |
100 public Image getToolTipImage(Object object) { | |
101 return null; | |
102 } | |
103 | |
104 /** | |
105 * Get the text displayed in the tool tip for object. | |
106 * | |
107 * <p> | |
108 * <b>If {@link #getToolTipText(Object)} and | |
109 * {@link #getToolTipImage(Object)} both return <code>null</code> the | |
110 * control is set back to standard behavior</b> | |
111 * </p> | |
112 * | |
113 * @param element | |
114 * the element for which the tool tip is shown | |
115 * @return the {@link String} or <code>null</code> if there is not text to | |
116 * display | |
117 */ | |
118 public String getToolTipText(Object element) { | |
119 return null; | |
120 } | |
121 | |
122 /** | |
123 * Return the background color used for the tool tip | |
124 * | |
125 * @param object | |
126 * the {@link Object} for which the tool tip is shown | |
127 * | |
128 * @return the {@link Color} used or <code>null</code> if you want to use | |
129 * the default color {@link DWT#COLOR_INFO_BACKGROUND} | |
130 * @see DWT#COLOR_INFO_BACKGROUND | |
131 */ | |
132 public Color getToolTipBackgroundColor(Object object) { | |
133 return null; | |
134 } | |
135 | |
136 /** | |
137 * The foreground color used to display the the text in the tool tip | |
138 * | |
139 * @param object | |
140 * the {@link Object} for which the tool tip is shown | |
141 * @return the {@link Color} used or <code>null</code> if you want to use | |
142 * the default color {@link DWT#COLOR_INFO_FOREGROUND} | |
143 * @see DWT#COLOR_INFO_FOREGROUND | |
144 */ | |
145 public Color getToolTipForegroundColor(Object object) { | |
146 return null; | |
147 } | |
148 | |
149 /** | |
150 * Get the {@link Font} used to display the tool tip | |
151 * | |
152 * @param object | |
153 * the element for which the tool tip is shown | |
154 * @return {@link Font} or <code>null</code> if the default font is to be | |
155 * used. | |
156 */ | |
157 public Font getToolTipFont(Object object) { | |
158 return null; | |
159 } | |
160 | |
161 /** | |
162 * Return the amount of pixels in x and y direction you want the tool tip to | |
163 * pop up from the mouse pointer. The default shift is 10px right and 0px | |
164 * below your mouse cursor. Be aware of the fact that you should at least | |
165 * position the tool tip 1px right to your mouse cursor else click events | |
166 * may not get propagated properly. | |
167 * | |
168 * @param object | |
169 * the element for which the tool tip is shown | |
170 * @return {@link Point} to shift of the tool tip or <code>null</code> if the | |
171 * default shift should be used. | |
172 */ | |
173 public Point getToolTipShift(Object object) { | |
174 return null; | |
175 } | |
176 | |
177 /** | |
178 * Return whether or not to use the native tool tip. If you switch to native | |
179 * tool tips only the value from {@link #getToolTipText(Object)} is used all | |
180 * other features from custom tool tips are not supported. | |
181 * | |
182 * <p> | |
183 * To reset the control to native behavior you should return | |
184 * <code>true</code> from this method and <code>null</code> from | |
185 * {@link #getToolTipText(Object)} or <code>null</code> from | |
186 * {@link #getToolTipText(Object)} and {@link #getToolTipImage(Object)} at | |
187 * the same time | |
188 * </p> | |
189 * | |
190 * @param object | |
191 * the {@link Object} for which the tool tip is shown | |
192 * @return <code>true</code> if native tool tips should be used | |
193 */ | |
194 public bool useNativeToolTip(Object object) { | |
195 return false; | |
196 } | |
197 | |
198 /** | |
199 * The time in milliseconds the tool tip is shown for. | |
200 * | |
201 * @param object | |
202 * the {@link Object} for which the tool tip is shown | |
203 * @return time in milliseconds the tool tip is shown for | |
204 */ | |
205 public int getToolTipTimeDisplayed(Object object) { | |
206 return 0; | |
207 } | |
208 | |
209 /** | |
210 * The time in milliseconds until the tool tip is displayed. | |
211 * | |
212 * @param object | |
213 * the {@link Object} for which the tool tip is shown | |
214 * @return time in milliseconds until the tool tip is displayed | |
215 */ | |
216 public int getToolTipDisplayDelayTime(Object object) { | |
217 return 0; | |
218 } | |
219 | |
220 /** | |
221 * The {@link DWT} style used to create the {@link CLabel} (see there for | |
222 * supported styles). By default {@link DWT#SHADOW_NONE} is used. | |
223 * | |
224 * @param object | |
225 * the element for which the tool tip is shown | |
226 * @return the style used to create the label | |
227 * @see CLabel | |
228 */ | |
229 public int getToolTipStyle(Object object) { | |
230 return DWT.SHADOW_NONE; | |
231 } | |
232 | |
233 /** | |
234 * Update the label for cell. | |
235 * | |
236 * @param cell | |
237 * {@link ViewerCell} | |
238 */ | |
239 public abstract void update(ViewerCell cell); | |
71 | 240 |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
241 /** |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
242 * Initialize this label provider for use with the given column viewer for |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
243 * the given column. Subclasses may extend but should call the super |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
244 * implementation (which at this time is empty but may be changed in the |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
245 * future). |
71 | 246 * |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
247 * @param viewer |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
248 * the viewer |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
249 * @param column |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
250 * the column, or <code>null</code> if a column is not |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
251 * available. |
71 | 252 * |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
253 * @since 3.4 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
254 */ |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
255 protected void initialize(ColumnViewer viewer, ViewerColumn column) { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
256 } |
10 | 257 |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
258 /** |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
259 * Dispose of this label provider which was used with the given column |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
260 * viewer and column. Subclasses may extend but should call the super |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
261 * implementation (which calls {@link #dispose()}). |
71 | 262 * |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
263 * @param viewer |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
264 * the viewer |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
265 * @param column |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
266 * the column, or <code>null</code> if a column is not |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
267 * available. |
71 | 268 * |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
269 * @since 3.4 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
270 */ |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
271 public void dispose(ColumnViewer viewer, ViewerColumn column) { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
272 dispose(); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
273 } |
71 | 274 |
10 | 275 } |