001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: * Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
011: * - bug fixes for 182443
012: *******************************************************************************/package org.eclipse.jface.viewers;
013:
014: import org.eclipse.swt.SWT;
015: import org.eclipse.swt.custom.CLabel;
016: import org.eclipse.swt.graphics.Color;
017: import org.eclipse.swt.graphics.Font;
018: import org.eclipse.swt.graphics.Image;
019: import org.eclipse.swt.graphics.Point;
020:
021: /**
022: * The CellLabelProvider is an abstract implementation of a label provider for
023: * structured viewers.
024: *
025: * <p><b>This class is intended to be subclassed</b></p>
026: *
027: * @since 3.3
028: * @see ColumnLabelProvider as a concrete implementation
029: */
030: public abstract class CellLabelProvider extends BaseLabelProvider {
031:
032: /**
033: * Create a new instance of the receiver.
034: */
035: public CellLabelProvider() {
036: super ();
037: }
038:
039: /**
040: * Create a ViewerLabelProvider for the column at index
041: *
042: * @param labelProvider
043: * The labelProvider to convert
044: * @return ViewerLabelProvider
045: */
046: /* package */static CellLabelProvider createViewerLabelProvider(
047: ColumnViewer viewer, IBaseLabelProvider labelProvider) {
048:
049: boolean noColumnTreeViewer = viewer instanceof AbstractTreeViewer
050: && viewer.doGetColumnCount() == 0;
051:
052: if (!noColumnTreeViewer
053: && (labelProvider instanceof ITableLabelProvider
054: || labelProvider instanceof ITableColorProvider || labelProvider instanceof ITableFontProvider))
055: return new TableColumnViewerLabelProvider(labelProvider);
056: if (labelProvider instanceof CellLabelProvider)
057: return (CellLabelProvider) labelProvider;
058: return new WrappedViewerLabelProvider(labelProvider);
059:
060: }
061:
062: /**
063: * Get the image displayed in the tool tip for object.
064: *
065: * <p>
066: * <b>If {@link #getToolTipText(Object)} and
067: * {@link #getToolTipImage(Object)} both return <code>null</code> the
068: * control is set back to standard behavior</b>
069: * </p>
070: *
071: * @param object
072: * the element for which the tool tip is shown
073: * @return {@link Image} or <code>null</code> if there is not image.
074: */
075:
076: public Image getToolTipImage(Object object) {
077: return null;
078: }
079:
080: /**
081: * Get the text displayed in the tool tip for object.
082: *
083: * <p>
084: * <b>If {@link #getToolTipText(Object)} and
085: * {@link #getToolTipImage(Object)} both return <code>null</code> the
086: * control is set back to standard behavior</b>
087: * </p>
088: *
089: * @param element
090: * the element for which the tool tip is shown
091: * @return the {@link String} or <code>null</code> if there is not text to
092: * display
093: */
094: public String getToolTipText(Object element) {
095: return null;
096: }
097:
098: /**
099: * Return the background color used for the tool tip
100: *
101: * @param object
102: * the {@link Object} for which the tool tip is shown
103: *
104: * @return the {@link Color} used or <code>null</code> if you want to use
105: * the default color {@link SWT#COLOR_INFO_BACKGROUND}
106: * @see SWT#COLOR_INFO_BACKGROUND
107: */
108: public Color getToolTipBackgroundColor(Object object) {
109: return null;
110: }
111:
112: /**
113: * The foreground color used to display the the text in the tool tip
114: *
115: * @param object
116: * the {@link Object} for which the tool tip is shown
117: * @return the {@link Color} used or <code>null</code> if you want to use
118: * the default color {@link SWT#COLOR_INFO_FOREGROUND}
119: * @see SWT#COLOR_INFO_FOREGROUND
120: */
121: public Color getToolTipForegroundColor(Object object) {
122: return null;
123: }
124:
125: /**
126: * Get the {@link Font} used to display the tool tip
127: *
128: * @param object
129: * the element for which the tool tip is shown
130: * @return {@link Font} or <code>null</code> if the default font is to be
131: * used.
132: */
133: public Font getToolTipFont(Object object) {
134: return null;
135: }
136:
137: /**
138: * Return the amount of pixels in x and y direction you want the tool tip to
139: * pop up from the mouse pointer. The default shift is 10px right and 0px
140: * below your mouse cursor. Be aware of the fact that you should at least
141: * position the tool tip 1px right to your mouse cursor else click events
142: * may not get propagated properly.
143: *
144: * @param object
145: * the element for which the tool tip is shown
146: * @return {@link Point} to shift of the tool tip or <code>null</code> if the
147: * default shift should be used.
148: */
149: public Point getToolTipShift(Object object) {
150: return null;
151: }
152:
153: /**
154: * Return whether or not to use the native tool tip. If you switch to native
155: * tool tips only the value from {@link #getToolTipText(Object)} is used all
156: * other features from custom tool tips are not supported.
157: *
158: * <p>
159: * To reset the control to native behavior you should return
160: * <code>true</code> from this method and <code>null</code> from
161: * {@link #getToolTipText(Object)} or <code>null</code> from
162: * {@link #getToolTipText(Object)} and {@link #getToolTipImage(Object)} at
163: * the same time
164: * </p>
165: *
166: * @param object
167: * the {@link Object} for which the tool tip is shown
168: * @return <code>true</code> if native tool tips should be used
169: */
170: public boolean useNativeToolTip(Object object) {
171: return false;
172: }
173:
174: /**
175: * The time in milliseconds the tool tip is shown for.
176: *
177: * @param object
178: * the {@link Object} for which the tool tip is shown
179: * @return time in milliseconds the tool tip is shown for
180: */
181: public int getToolTipTimeDisplayed(Object object) {
182: return 0;
183: }
184:
185: /**
186: * The time in milliseconds until the tool tip is displayed.
187: *
188: * @param object
189: * the {@link Object} for which the tool tip is shown
190: * @return time in milliseconds until the tool tip is displayed
191: */
192: public int getToolTipDisplayDelayTime(Object object) {
193: return 0;
194: }
195:
196: /**
197: * The {@link SWT} style used to create the {@link CLabel} (see there for
198: * supported styles). By default {@link SWT#SHADOW_NONE} is used.
199: *
200: * @param object
201: * the element for which the tool tip is shown
202: * @return the style used to create the label
203: * @see CLabel
204: */
205: public int getToolTipStyle(Object object) {
206: return SWT.SHADOW_NONE;
207: }
208:
209: /**
210: * Update the label for cell.
211: *
212: * @param cell
213: * {@link ViewerCell}
214: */
215: public abstract void update(ViewerCell cell);
216:
217: }
|