[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: TableViewer and CellLabelProviders
|
>From playing around, I discovered that the order in which you set things
matters. If you set the column cell label provider, then the viewer label
provider, tooltips don't work. If you set the viewer label provider, then
the column cell label provider, they work as I'd assumed they would. Is that
expected?
I wasn't aware that there's an old and new API. None of the methods I'm
using is deprecated, and I didn't see anything in the javadoc. Can you point
me at the documentation for the old vs. new API?
Here's a snippet in which tooltips don't work. All I did was change your
snippet to set a label provider:
/**
* Explore New API: JFace custom tooltips drawing.
*
* @author Tom Schindl <tom.schindl@xxxxxxxxxxxxxxx>
* @since 3.3
*/
public class CustomTooltips {
private static class MyContentProvider implements
IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
return new String[] { "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten" };
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}
private static class MyLabelProvider extends LabelProvider implements
ITableLabelProvider {
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
public String getColumnText(Object element, int columnIndex) {
return element.toString();
}
}
/**
* @param args
*/
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
TableViewer v = new TableViewer(shell, SWT.FULL_SELECTION);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
v.setContentProvider(new MyContentProvider());
ColumnViewerToolTipSupport.enableFor(v,ToolTip.NO_RECREATE);
CellLabelProvider labelProvider = new CellLabelProvider() {
public String getToolTipText(Object element) {
return "Tooltip (" + element + ")";
}
public Point getToolTipShift(Object object) {
return new Point(5, 5);
}
public int getToolTipDisplayDelayTime(Object object) {
return 500;
}
public int getToolTipTimeDisplayed(Object object) {
return 5000;
}
public void update(ViewerCell cell) {
cell.setText(cell.getElement().toString());
}
};
TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
// This doesn't work. Flip the following two lines and
// then tooltips will work.
column.setLabelProvider(labelProvider);
v.setLabelProvider(new MyLabelProvider());
column.getColumn().setText("Column 1");
column.getColumn().setWidth(100);
v.setInput("");
shell.setSize(200, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
"Tom Schindl" <tom.schindl@xxxxxxxxxxxxxxx> wrote in message
news:fv4tqp$tfq$1@xxxxxxxxxxxxxxxxxxxx
> Could you please provide a snippet for me to test? I thought it works just
> the way you describ it if there's not LabelProvider provider attached to a
> Column the the JFace-Code ensures to generate one from the label provider
> attached to the viewer.
>
> All in all mixing the old and the new API is always a dangerous thing.
>
> Tom
>
> Sarah Ettritch schrieb:
>> I have a table viewer with ten columns. I'd like to provide cell tooltips
>> for two of those columns only. The rest don't require tooltips. I
>> followed the code in Snippet011CustomTooltips, but I wasn't seeing my
>> tooltips. I didn't noticed that a label provider hadn't been set on the
>> table viewer in the snippet. It appears that if a label provider is set
>> on the viewer, any column CellLabelProviders are ignored.
>>
>> I had assumed that the viewer would use its label provider unless a
>> CellLabelProvider exists for a column, in which case it would use the
>> CellLabelProvider. Is there a way to make that happen, so I don't have to
>> set ten CellLabelProviders to get tooltips in two columns?
>
>
> --
> B e s t S o l u t i o n . at
> --------------------------------------------------------------------
> Tom Schindl JFace-Committer
> --------------------------------------------------------------------