| 1 |
/*******************************************************************************
|
| 2 |
* Copyright (c) 2006, 2007 Tom Schindl 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 |
* Tom Schindl - initial API and implementation
|
| 10 |
* IBM - Improvement for Bug 159625 [Snippets] Update Snippet011CustomTooltips to reflect new API
|
| 11 |
*******************************************************************************/
|
| 12 |
|
| 13 |
package org.eclipse.jface.snippets.viewers;
|
| 14 |
|
| 15 |
import org.eclipse.jface.viewers.CellLabelProvider;
|
| 16 |
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
|
| 17 |
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
| 18 |
import org.eclipse.jface.viewers.TableViewer;
|
| 19 |
import org.eclipse.jface.viewers.TableViewerColumn;
|
| 20 |
import org.eclipse.jface.viewers.Viewer;
|
| 21 |
import org.eclipse.jface.viewers.ViewerCell;
|
| 22 |
import org.eclipse.jface.window.ToolTip;
|
| 23 |
import org.eclipse.swt.SWT;
|
| 24 |
import org.eclipse.swt.graphics.Point;
|
| 25 |
import org.eclipse.swt.layout.FillLayout;
|
| 26 |
import org.eclipse.swt.widgets.Display;
|
| 27 |
import org.eclipse.swt.widgets.Shell;
|
| 28 |
|
| 29 |
/**
|
| 30 |
* Explore New API: JFace custom tooltips drawing.
|
| 31 |
*
|
| 32 |
* @author Tom Schindl <tom.schindl@bestsolution.at>
|
| 33 |
* @since 3.3
|
| 34 |
*/
|
| 35 |
public class Snippet011CustomTooltips {
|
| 36 |
private static class MyContentProvider implements
|
| 37 |
IStructuredContentProvider {
|
| 38 |
|
| 39 |
public Object[] getElements(Object inputElement) {
|
| 40 |
return new String[] { "one", "two", "three", "four", "five", "six",
|
| 41 |
"seven", "eight", "nine", "ten" };
|
| 42 |
}
|
| 43 |
|
| 44 |
public void dispose() {
|
| 45 |
|
| 46 |
}
|
| 47 |
|
| 48 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
| 49 |
|
| 50 |
}
|
| 51 |
}
|
| 52 |
|
| 53 |
/**
|
| 54 |
* @param args
|
| 55 |
*/
|
| 56 |
public static void main(String[] args) {
|
| 57 |
final Display display = new Display();
|
| 58 |
Shell shell = new Shell(display);
|
| 59 |
shell.setLayout(new FillLayout());
|
| 60 |
|
| 61 |
TableViewer v = new TableViewer(shell, SWT.FULL_SELECTION);
|
| 62 |
v.getTable().setLinesVisible(true);
|
| 63 |
v.getTable().setHeaderVisible(true);
|
| 64 |
v.setContentProvider(new MyContentProvider());
|
| 65 |
ColumnViewerToolTipSupport.enableFor(v,ToolTip.NO_RECREATE);
|
| 66 |
|
| 67 |
CellLabelProvider labelProvider = new CellLabelProvider() {
|
| 68 |
|
| 69 |
public String getToolTipText(Object element) {
|
| 70 |
return "Tooltip (" + element + ")";
|
| 71 |
}
|
| 72 |
|
| 73 |
public Point getToolTipShift(Object object) {
|
| 74 |
return new Point(5, 5);
|
| 75 |
}
|
| 76 |
|
| 77 |
public int getToolTipDisplayDelayTime(Object object) {
|
| 78 |
return 2000;
|
| 79 |
}
|
| 80 |
|
| 81 |
public int getToolTipTimeDisplayed(Object object) {
|
| 82 |
return 5000;
|
| 83 |
}
|
| 84 |
|
| 85 |
public void update(ViewerCell cell) {
|
| 86 |
cell.setText(cell.getElement().toString());
|
| 87 |
|
| 88 |
}
|
| 89 |
};
|
| 90 |
|
| 91 |
TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
|
| 92 |
column.setLabelProvider(labelProvider);
|
| 93 |
column.getColumn().setText("Column 1");
|
| 94 |
column.getColumn().setWidth(100);
|
| 95 |
|
| 96 |
v.setInput("");
|
| 97 |
|
| 98 |
shell.setSize(200, 200);
|
| 99 |
shell.open();
|
| 100 |
|
| 101 |
while (!shell.isDisposed()) {
|
| 102 |
if (!display.readAndDispatch()) {
|
| 103 |
display.sleep();
|
| 104 |
}
|
| 105 |
}
|
| 106 |
|
| 107 |
display.dispose();
|
| 108 |
}
|
| 109 |
|
| 110 |
}
|