Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Tooltip for multi-column TreeViewer
Tooltip for multi-column TreeViewer [message #543929] |
Thu, 01 July 2010 06:51 |
Yves Bontemps Messages: 14 Registered: March 2010 |
Junior Member |
|
|
Hello,
I would like my application to show tooltips in a TreeViewer that has multiple columns, using the 3.3 API. For some reason, tooltip stops working when the tree viewer contains columns but works fine with exactly the same setting as long as there are no TreeColumns added to the viewer.
I followed and modified Snippet015 (Custom tool tip in Tree) by :
* modifying the CellLabelProvider to implement ITableLabelProvider
* adding a few TreeViewerColumn to the TreeViewer
* giving each of them a label provider
See below:
public class Snippet015MultiColumn {
private static class MyContentProvider implements ITreeContentProvider {
private static final String ROOT = "Root";
public Object[] getElements(Object inputElement) {
return new Object[]{ROOT};
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public Object[] getChildren(Object parentElement) {
if(parentElement.equals(ROOT))
return new String[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
return new Object[0];
}
public Object getParent(Object element) {
return null;
}
public boolean hasChildren(Object element) {
return element.equals(ROOT);
}
}
static class MyCellLabelProvider extends CellLabelProvider implements ILabelProvider, ITableLabelProvider{
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipText(java.lang.Object)
*/
public String getToolTipText(Object element) {
return "Tooltip (" + element + ")";
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipShift(java.lang.Object)
*/
public Point getToolTipShift(Object object) {
return new Point(5,5);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipDisplayDelayTime(java.lang.Object)
*/
public int getToolTipDisplayDelayTime(Object object) {
return 200;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipTimeDisplayed(java.lang.Object)
*/
public int getToolTipTimeDisplayed(Object object) {
return 5000;
}
public void update(ViewerCell cell) {
cell.setText(cell.getElement().toString());
}
@Override
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
@Override
public String getColumnText(Object element, int columnIndex) {
return element + " @ "+columnIndex;
}
@Override
public Image getImage(Object element) {
return null;
}
@Override
public String getText(Object element) {
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());
TreeViewer v = new TreeViewer(shell,SWT.FULL_SELECTION);
v.getTree().setLinesVisible(true);
v.getTree().setHeaderVisible(true);
ColumnViewerToolTipSupport.enableFor(v);
v.setContentProvider(new MyContentProvider());
CellLabelProvider labelProvider = new MyCellLabelProvider();
/* --- Remove from here to disable multi-column */
String[] colids = new String[3];
for (int i = 0; i < 3 ; i++){
TreeViewerColumn column = new TreeViewerColumn(v, SWT.NONE);
column.setLabelProvider(labelProvider);
TreeColumn col = column.getColumn();
col.setResizable(true);
col.setWidth(150);
colids[i] = Integer.toString(i);
}
v.setColumnProperties(colids);
/* --- Remove to here to disable multi-column */
v.setLabelProvider(labelProvider);
v.setInput("");
shell.setSize(200,200);
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) {
display.sleep ();
}
}
display.dispose ();
}
}
If I understand it right, when a tooltip creation event is fired, the ColumnViewerTooltipSupport delegates to the label provider of the current viewer column.
This is the place where I expect my own custom sub-class of CellLabelProvider to be called to provide the tooltip text. However, it is always the TableColumnViewerLabelProvider that gets called and this one returns null.
I tracked it down to ColumnViewer.setLabelProvider that actually resets all the label providers of all the columns in the viewer by wrapping them in TableColumnViewerLabelProviders.
Am I doing something wrong ? Is there a workaround for this (preferably using the nice and easy 3.3 API for tooltip)?
Cheers,
Yves.
|
|
|
Re: Tooltip for multi-column TreeViewer [message #543957 is a reply to message #543929] |
Thu, 01 July 2010 07:56 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
You should NOT set a labelprovider on the viewer when you set one on the
columns already!
So please set a ColumnLabelProvider on all your columns.
Tom
Am 01.07.10 08:51, schrieb Yves Bontemps:
> Hello,
>
> I would like my application to show tooltips in a TreeViewer that has
> multiple columns, using the 3.3 API. For some reason, tooltip stops
> working when the tree viewer contains columns but works fine with
> exactly the same setting as long as there are no TreeColumns added to
> the viewer.
>
> I followed and modified
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet015CustomTooltipsForTree.java?view=markup
> (Custom tool tip in Tree) by :
> * modifying the CellLabelProvider to implement ITableLabelProvider
> * adding a few TreeViewerColumn to the TreeViewer
> * giving each of them a label provider
>
> See below:
> public class Snippet015MultiColumn {
>
>
> private static class MyContentProvider implements
> ITreeContentProvider {
>
> private static final String ROOT = "Root";
>
> public Object[] getElements(Object inputElement) {
> return new Object[]{ROOT};
> }
>
> public void dispose() {
>
> }
>
> public void inputChanged(Viewer viewer, Object oldInput,
> Object newInput) {
>
>
> }
>
> public Object[] getChildren(Object parentElement) {
> if(parentElement.equals(ROOT))
> return new String[] { "one", "two", "three", "four",
> "five", "six", "seven", "eight", "nine", "ten" };
> return new Object[0];
> }
>
> public Object getParent(Object element) {
> return null;
> }
>
> public boolean hasChildren(Object element) {
> return element.equals(ROOT);
> }
> }
>
> static class MyCellLabelProvider extends CellLabelProvider
> implements ILabelProvider, ITableLabelProvider{
> /* (non-Javadoc)
> * @see
> org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipText (java.lang.Object)
>
> */
> public String getToolTipText(Object element) {
> return "Tooltip (" + element + ")";
> }
>
> /* (non-Javadoc)
> * @see
> org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipShif t(java.lang.Object)
>
> */
> public Point getToolTipShift(Object object) {
> return new Point(5,5);
> }
>
>
> /* (non-Javadoc)
> * @see
> org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipDisp layDelayTime(java.lang.Object)
>
> */
> public int getToolTipDisplayDelayTime(Object object) {
> return 200;
> }
>
> /* (non-Javadoc)
> * @see
> org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipTime Displayed(java.lang.Object)
>
> */
> public int getToolTipTimeDisplayed(Object object) {
> return 5000;
> }
>
> public void update(ViewerCell cell) {
> cell.setText(cell.getElement().toString());
>
> }
>
> @Override
> public Image getColumnImage(Object element, int columnIndex) {
> return null;
> }
>
> @Override
> public String getColumnText(Object element, int columnIndex) {
> return element + " @ "+columnIndex;
> }
>
> @Override
> public Image getImage(Object element) {
> return null;
> }
>
> @Override
> public String getText(Object element) {
> 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());
> TreeViewer v = new
> TreeViewer(shell,SWT.FULL_SELECTION);
> v.getTree().setLinesVisible(true);
> v.getTree().setHeaderVisible(true);
> ColumnViewerToolTipSupport.enableFor(v);
> v.setContentProvider(new MyContentProvider());
> CellLabelProvider labelProvider = new
> MyCellLabelProvider();
> /* --- Remove from here to disable multi-column */
> String[] colids = new String[3];
> for (int i = 0; i < 3 ; i++){
> TreeViewerColumn column = new TreeViewerColumn(v,
> SWT.NONE);
> column.setLabelProvider(labelProvider);
> TreeColumn col = column.getColumn();
> col.setResizable(true);
> col.setWidth(150);
> colids[i] = Integer.toString(i);
> }
> v.setColumnProperties(colids);
> /* --- Remove to here to disable multi-column */
> v.setLabelProvider(labelProvider);
> v.setInput("");
> shell.setSize(200,200);
> shell.open ();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch ()) {
> display.sleep ();
> }
> }
> display.dispose ();
> }
>
> }
>
>
> If I understand it right, when a tooltip creation event is fired, the
> ColumnViewerTooltipSupport delegates to the label provider of the
> current viewer column.
> This is the place where I expect my own custom sub-class of
> CellLabelProvider to be called to provide the tooltip text. However, it
> is always the TableColumnViewerLabelProvider that gets called and this
> one returns null.
>
> I tracked it down to ColumnViewer.setLabelProvider that actually resets
> all the label providers of all the columns in the viewer by wrapping
> them in TableColumnViewerLabelProviders.
>
> Am I doing something wrong ? Is there a workaround for this (preferably
> using the nice and easy 3.3 API for tooltip)?
|
|
|
Re: Tooltip for multi-column TreeViewer [message #543958 is a reply to message #543957] |
Thu, 01 July 2010 07:58 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
You should NOT use a ITableLabelProvider anymore!
Tin
Am 01.07.10 09:56, schrieb Tom Schindl:
> You should NOT set a labelprovider on the viewer when you set one on the
> columns already!
>
> So please set a ColumnLabelProvider on all your columns.
>
> Tom
>
> Am 01.07.10 08:51, schrieb Yves Bontemps:
>> Hello,
>>
>> I would like my application to show tooltips in a TreeViewer that has
>> multiple columns, using the 3.3 API. For some reason, tooltip stops
>> working when the tree viewer contains columns but works fine with
>> exactly the same setting as long as there are no TreeColumns added to
>> the viewer.
>>
>> I followed and modified
>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet015CustomTooltipsForTree.java?view=markup
>> (Custom tool tip in Tree) by :
>> * modifying the CellLabelProvider to implement ITableLabelProvider
>> * adding a few TreeViewerColumn to the TreeViewer
>> * giving each of them a label provider
>>
>> See below:
>> public class Snippet015MultiColumn {
>>
>>
>> private static class MyContentProvider implements
>> ITreeContentProvider {
>>
>> private static final String ROOT = "Root";
>>
>> public Object[] getElements(Object inputElement) {
>> return new Object[]{ROOT};
>> }
>>
>> public void dispose() {
>>
>> }
>>
>> public void inputChanged(Viewer viewer, Object oldInput,
>> Object newInput) {
>>
>>
>> }
>>
>> public Object[] getChildren(Object parentElement) {
>> if(parentElement.equals(ROOT))
>> return new String[] { "one", "two", "three", "four",
>> "five", "six", "seven", "eight", "nine", "ten" };
>> return new Object[0];
>> }
>>
>> public Object getParent(Object element) {
>> return null;
>> }
>>
>> public boolean hasChildren(Object element) {
>> return element.equals(ROOT);
>> }
>> }
>>
>> static class MyCellLabelProvider extends CellLabelProvider
>> implements ILabelProvider, ITableLabelProvider{
>> /* (non-Javadoc)
>> * @see
>> org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipText (java.lang.Object)
>>
>> */
>> public String getToolTipText(Object element) {
>> return "Tooltip (" + element + ")";
>> }
>>
>> /* (non-Javadoc)
>> * @see
>> org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipShif t(java.lang.Object)
>>
>> */
>> public Point getToolTipShift(Object object) {
>> return new Point(5,5);
>> }
>>
>>
>> /* (non-Javadoc)
>> * @see
>> org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipDisp layDelayTime(java.lang.Object)
>>
>> */
>> public int getToolTipDisplayDelayTime(Object object) {
>> return 200;
>> }
>>
>> /* (non-Javadoc)
>> * @see
>> org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipTime Displayed(java.lang.Object)
>>
>> */
>> public int getToolTipTimeDisplayed(Object object) {
>> return 5000;
>> }
>>
>> public void update(ViewerCell cell) {
>> cell.setText(cell.getElement().toString());
>>
>> }
>>
>> @Override
>> public Image getColumnImage(Object element, int columnIndex) {
>> return null;
>> }
>>
>> @Override
>> public String getColumnText(Object element, int columnIndex) {
>> return element + " @ "+columnIndex;
>> }
>>
>> @Override
>> public Image getImage(Object element) {
>> return null;
>> }
>>
>> @Override
>> public String getText(Object element) {
>> 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());
>> TreeViewer v = new
>> TreeViewer(shell,SWT.FULL_SELECTION);
>> v.getTree().setLinesVisible(true);
>> v.getTree().setHeaderVisible(true);
>> ColumnViewerToolTipSupport.enableFor(v);
>> v.setContentProvider(new MyContentProvider());
>> CellLabelProvider labelProvider = new
>> MyCellLabelProvider();
>> /* --- Remove from here to disable multi-column */
>> String[] colids = new String[3];
>> for (int i = 0; i < 3 ; i++){
>> TreeViewerColumn column = new TreeViewerColumn(v,
>> SWT.NONE);
>> column.setLabelProvider(labelProvider);
>> TreeColumn col = column.getColumn();
>> col.setResizable(true);
>> col.setWidth(150);
>> colids[i] = Integer.toString(i);
>> }
>> v.setColumnProperties(colids);
>> /* --- Remove to here to disable multi-column */
>> v.setLabelProvider(labelProvider);
>> v.setInput("");
>> shell.setSize(200,200);
>> shell.open ();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch ()) {
>> display.sleep ();
>> }
>> }
>> display.dispose ();
>> }
>>
>> }
>>
>>
>> If I understand it right, when a tooltip creation event is fired, the
>> ColumnViewerTooltipSupport delegates to the label provider of the
>> current viewer column.
>> This is the place where I expect my own custom sub-class of
>> CellLabelProvider to be called to provide the tooltip text. However, it
>> is always the TableColumnViewerLabelProvider that gets called and this
>> one returns null.
>>
>> I tracked it down to ColumnViewer.setLabelProvider that actually resets
>> all the label providers of all the columns in the viewer by wrapping
>> them in TableColumnViewerLabelProviders.
>>
>> Am I doing something wrong ? Is there a workaround for this (preferably
>> using the nice and easy 3.3 API for tooltip)?
>
|
|
| | | | |
Goto Forum:
Current Time: Fri Apr 19 22:19:00 GMT 2024
Powered by FUDForum. Page generated in 0.03557 seconds
|