Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Yves Bontemps is currently offline Yves BontempsFriend
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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
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)?
>
Re: Tooltip for multi-column TreeViewer [message #544077 is a reply to message #543929] Thu, 01 July 2010 14:26 Go to previous messageGo to next message
Yves Bontemps is currently offline Yves BontempsFriend
Messages: 14
Registered: March 2010
Junior Member
Thank you, Tom.

It works fine, now !


Cheers,

Yves.
Re: Tooltip for multi-column TreeViewer [message #544335 is a reply to message #543958] Fri, 02 July 2010 12:09 Go to previous messageGo to next message
Alexey Romanov is currently offline Alexey RomanovFriend
Messages: 263
Registered: May 2010
Senior Member
> You should NOT use a ITableLabelProvider anymore!

Why? What is the preferred alternative?
Re: Tooltip for multi-column TreeViewer [message #544346 is a reply to message #544335] Fri, 02 July 2010 12:36 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
You set a ColumnLabelProvider on all your TableViewerColumn/TreeViewerColumn

Tom

Am 02.07.10 14:09, schrieb Alexey Romanov:
>> You should NOT use a ITableLabelProvider anymore!
>
> Why? What is the preferred alternative?
Re: Tooltip for multi-column TreeViewer [message #544354 is a reply to message #544346] Fri, 02 July 2010 13:05 Go to previous message
Alexey Romanov is currently offline Alexey RomanovFriend
Messages: 263
Registered: May 2010
Senior Member
Thanks!
Previous Topic:Position of checkbox and tree control in tree table
Next Topic:Setting a child of SashForm to a desired size
Goto Forum:
  


Current Time: Fri Dec 19 12:23:02 GMT 2014

Powered by FUDForum. Page generated in 0.02444 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software