1

enter image description here

This is a gridLayout in which the Available side is a Tree Viewer and The Selected side is a ListViewer. Now I have to get a toolTip on the right hand side. Which I am unable to get. I am working on a existing code base , so I am unable to figure out on which line did they add a tooltip + I did not find any keywords like tooltip or mouse Hover. Still how is this implemented. I am mentioning some code. I believe the answer should be somewhere here only.

 availableViewer = new TreeViewer(resultsComposite, SWT.BORDER | this.getStyle());
        availableViewer.setContentProvider(new ResAndResGroupTreeContentProvider());
        availableViewer.setLabelProvider(SelectionItemLabelProvider.getInstance());
        Tree availableResults = availableViewer.getTree();
        GridData availableResultsGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
        availableResultsGridData.widthHint = LIST_WIDTH_HINT;
        availableResultsGridData.heightHint = LIST_HEIGHT_HINT;
        availableResults.setLayoutData(availableResultsGridData);
        availableViewer.getTree().addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetDefaultSelected(SelectionEvent e)
            {
                moveAvailableItemsToSelected();
            }
        });

This is the selectionViewer content.

  selectedViewer = new ListViewer(resultsComposite, SWT.V_SCROLL | SWT.H_SCROLL| SWT.BORDER
            | this.getStyle());
    selectedViewer.setContentProvider(new ResAndResGroupTreeContentProvider());
    selectedViewer.setLabelProvider(new SelectionItemLabelProvider());
    org.eclipse.swt.widgets.List selectedResults = selectedViewer.getList();
    GridData selectedResultsGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    selectedResultsGridData.widthHint = LIST_WIDTH_HINT;
    selectedResultsGridData.heightHint = LIST_HEIGHT_HINT;
    selectedResults.setLayoutData(selectedResultsGridData);
    selectedViewer.addDoubleClickListener(new IDoubleClickListener()
    {
        @Override
        public void doubleClick(DoubleClickEvent event)
        {
            moveSelectedItemsToAvailable();
        }
    });
    selectedViewer.getList().addKeyListener(new KeyAdapter()
    {
        @Override
        public void keyPressed(KeyEvent e)
        {
            if (e.character == SWT.CR)
            {
                moveSelectedItemsToAvailable();
            }
        }
    });
    selectedViewer.addSelectionChangedListener(new ISelectionChangedListener()
    {
        @Override
        public void selectionChanged(SelectionChangedEvent event)
        {
            updateButtonsEnabled();
        }
    });

Thanks.

Saras Arya
  • 3,022
  • 8
  • 41
  • 71

1 Answers1

2

The ListViewers underlying List widget cannot show different tooltips for each item. You can assign a tooltip for the entire list like so

listViewer.getList().setTooltipText( "..." );

But if you want a differnt tooltip per item you'll have to use a TableViewer.

What you see on the left side is the native Windows tooltip that appears if an item exceeds the horizontal space. The Table (on Windows) has the same behavior, thus you don't need to explicitly provide tooltips.

For a control that has a default tool tip, such as the Tree on Windows, setting the tooltip to null replaces the default, causing no tooltip to be shown.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
  • but what we have used on the left hand side is a TreeViewer. How does it has an inherent property of windows? – Saras Arya Sep 24 '15 at 13:11
  • [documentation](http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjface%2Fviewers%2FTreeViewer.html) of tree viewer mentions nothing about this – Saras Arya Sep 24 '15 at 13:24
  • @SarasArya This is a feature of the native tree control that SWT uses and varies between platforms (the Mac tree control also does this). – greg-449 Sep 24 '15 at 14:02