How to get ToolTip in a ListViewer in JFace?
Asked Answered
A

1

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.

Anachronistic answered 24/9, 2015 at 12:49 Comment(3)
ColumnViewerToolTipSupport is the usual way but I don't see that here.Trichology
Could there be any other method, by which they could be doing it?Anachronistic
On some platforms the native tree control will show the whole of a long string as a tooltip automatically.Trichology
K
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.

Kayceekaye answered 24/9, 2015 at 13:5 Comment(3)
but what we have used on the left hand side is a TreeViewer. How does it has an inherent property of windows?Anachronistic
documentation of tree viewer mentions nothing about thisAnachronistic
@SarasArya This is a feature of the native tree control that SWT uses and varies between platforms (the Mac tree control also does this).Trichology

© 2022 - 2024 — McMap. All rights reserved.