KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > viewers > CellLabelProvider


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  *******************************************************************************/

13
14 package org.eclipse.jface.viewers;
15
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.custom.CLabel;
18 import org.eclipse.swt.graphics.Color;
19 import org.eclipse.swt.graphics.Font;
20 import org.eclipse.swt.graphics.Image;
21 import org.eclipse.swt.graphics.Point;
22
23 /**
24  * The CellLabelProvider is an abstract implementation of a label provider for
25  * structured viewers.
26  *
27  * <p><b>This class is intended to be subclassed</b></p>
28  *
29  * @since 3.3
30  * @see ColumnLabelProvider as a concrete implementation
31  */

32 public abstract class CellLabelProvider extends BaseLabelProvider {
33
34     /**
35      * Create a new instance of the receiver.
36      */

37     public CellLabelProvider() {
38         super();
39     }
40
41     /**
42      * Create a ViewerLabelProvider for the column at index
43      *
44      * @param labelProvider
45      * The labelProvider to convert
46      * @return ViewerLabelProvider
47      */

48     /* package */static CellLabelProvider createViewerLabelProvider(
49             ColumnViewer viewer, IBaseLabelProvider labelProvider) {
50
51         boolean noColumnTreeViewer = viewer instanceof AbstractTreeViewer && viewer
52                 .doGetColumnCount() == 0;
53
54         if (!noColumnTreeViewer
55                 && (labelProvider instanceof ITableLabelProvider
56                         || labelProvider instanceof ITableColorProvider || labelProvider instanceof ITableFontProvider))
57             return new TableColumnViewerLabelProvider(labelProvider);
58         if (labelProvider instanceof CellLabelProvider)
59             return (CellLabelProvider) labelProvider;
60         return new WrappedViewerLabelProvider(labelProvider);
61
62     }
63
64     /**
65      * Get the image displayed in the tool tip for object.
66      *
67      * <p>
68      * <b>If {@link #getToolTipText(Object)} and
69      * {@link #getToolTipImage(Object)} both return <code>null</code> the
70      * control is set back to standard behavior</b>
71      * </p>
72      *
73      * @param object
74      * the element for which the tool tip is shown
75      * @return {@link Image} or <code>null</code> if there is not image.
76      */

77
78     public Image getToolTipImage(Object JavaDoc object) {
79         return null;
80     }
81
82     /**
83      * Get the text displayed in the tool tip for object.
84      *
85      * <p>
86      * <b>If {@link #getToolTipText(Object)} and
87      * {@link #getToolTipImage(Object)} both return <code>null</code> the
88      * control is set back to standard behavior</b>
89      * </p>
90      *
91      * @param element
92      * the element for which the tool tip is shown
93      * @return the {@link String} or <code>null</code> if there is not text to
94      * display
95      */

96     public String JavaDoc getToolTipText(Object JavaDoc element) {
97         return null;
98     }
99
100     /**
101      * Return the background color used for the tool tip
102      *
103      * @param object
104      * the {@link Object} for which the tool tip is shown
105      *
106      * @return the {@link Color} used or <code>null</code> if you want to use
107      * the default color {@link SWT#COLOR_INFO_BACKGROUND}
108      * @see SWT#COLOR_INFO_BACKGROUND
109      */

110     public Color getToolTipBackgroundColor(Object JavaDoc object) {
111         return null;
112     }
113
114     /**
115      * The foreground color used to display the the text in the tool tip
116      *
117      * @param object
118      * the {@link Object} for which the tool tip is shown
119      * @return the {@link Color} used or <code>null</code> if you want to use
120      * the default color {@link SWT#COLOR_INFO_FOREGROUND}
121      * @see SWT#COLOR_INFO_FOREGROUND
122      */

123     public Color getToolTipForegroundColor(Object JavaDoc object) {
124         return null;
125     }
126
127     /**
128      * Get the {@link Font} used to display the tool tip
129      *
130      * @param object
131      * the element for which the tool tip is shown
132      * @return {@link Font} or <code>null</code> if the default font is to be
133      * used.
134      */

135     public Font getToolTipFont(Object JavaDoc object) {
136         return null;
137     }
138
139     /**
140      * Return the amount of pixels in x and y direction you want the tool tip to
141      * pop up from the mouse pointer. The default shift is 10px right and 0px
142      * below your mouse cursor. Be aware of the fact that you should at least
143      * position the tool tip 1px right to your mouse cursor else click events
144      * may not get propagated properly.
145      *
146      * @param object
147      * the element for which the tool tip is shown
148      * @return {@link Point} to shift of the tool tip or <code>null</code> if the
149      * default shift should be used.
150      */

151     public Point getToolTipShift(Object JavaDoc object) {
152         return null;
153     }
154
155     /**
156      * Return whether or not to use the native tool tip. If you switch to native
157      * tool tips only the value from {@link #getToolTipText(Object)} is used all
158      * other features from custom tool tips are not supported.
159      *
160      * <p>
161      * To reset the control to native behavior you should return
162      * <code>true</code> from this method and <code>null</code> from
163      * {@link #getToolTipText(Object)} or <code>null</code> from
164      * {@link #getToolTipText(Object)} and {@link #getToolTipImage(Object)} at
165      * the same time
166      * </p>
167      *
168      * @param object
169      * the {@link Object} for which the tool tip is shown
170      * @return <code>true</code> if native tool tips should be used
171      */

172     public boolean useNativeToolTip(Object JavaDoc object) {
173         return false;
174     }
175
176     /**
177      * The time in milliseconds the tool tip is shown for.
178      *
179      * @param object
180      * the {@link Object} for which the tool tip is shown
181      * @return time in milliseconds the tool tip is shown for
182      */

183     public int getToolTipTimeDisplayed(Object JavaDoc object) {
184         return 0;
185     }
186
187     /**
188      * The time in milliseconds until the tool tip is displayed.
189      *
190      * @param object
191      * the {@link Object} for which the tool tip is shown
192      * @return time in milliseconds until the tool tip is displayed
193      */

194     public int getToolTipDisplayDelayTime(Object JavaDoc object) {
195         return 0;
196     }
197
198     /**
199      * The {@link SWT} style used to create the {@link CLabel} (see there for
200      * supported styles). By default {@link SWT#SHADOW_NONE} is used.
201      *
202      * @param object
203      * the element for which the tool tip is shown
204      * @return the style used to create the label
205      * @see CLabel
206      */

207     public int getToolTipStyle(Object JavaDoc object) {
208         return SWT.SHADOW_NONE;
209     }
210
211     /**
212      * Update the label for cell.
213      *
214      * @param cell
215      * {@link ViewerCell}
216      */

217     public abstract void update(ViewerCell cell);
218
219 }
220
Popular Tags