Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] JFace Custom Tooltip not in sync with Viewer data

File a bug and CC me on it.

Tom

Rydzewski,Frank schrieb:
> 
> I'm using the custom tooltip logic for the JFace TableViewer in order to
> extend the amount of time a tooltip is being shown to a user.  A problem
> I have is that the Viewer's data may be reset by an asynchronous process
> while the tooltip is being displayed.  This results in the table's cell
> displaying vastly different information than what is described by the
> tooltip.
> 
> The desirable behavior would be for the Viewer to force any of the
> table's tooltips to close when it is in the process of re-populating the
> table's cells.  An alternative would be for the tooltip to be updated
> with the information for the new cell, but this would seem to be a more
> complex change.
> 
> Let me know if you believe this to be a defect in the current code
> (worthy of a bug being logged) or if there are any workarounds.
> 
> Snippet to recreate below (based on the JFace Snippet 011)
> 
> Hover over a cell and after 2 seconds, the cell's data will change,
> while the tooltip will remain populated with information from the
> previous data load.
> 
> Thanks for any advice on workarounds.
> 
> -Frank
> 
> ===================
> 
> import org.eclipse.jface.viewers.CellLabelProvider;
> import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
> import org.eclipse.jface.viewers.IStructuredContentProvider;
> import org.eclipse.jface.viewers.TableViewer;
> import org.eclipse.jface.viewers.TableViewerColumn;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.jface.viewers.ViewerCell;
> import org.eclipse.jface.window.ToolTip;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.MouseEvent;
> import org.eclipse.swt.events.MouseTrackAdapter;
> import org.eclipse.swt.graphics.Point;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> 
> /**
>  * (Modified to demonstrate tooltip synchronization issue)
>  *
>  * Explore New API: JFace custom tooltips drawing.
>  * @author Tom Schindl <tom.schindl@xxxxxxxxxxxxxxx>
>  * @since 3.3
>  */
> public class Snippet011CustomTooltips {
>     private static class MyContentProvider implements
> IStructuredContentProvider {
>         boolean transactionToggle;
>         public Object[] getElements(Object inputElement) {
>             transactionToggle = !transactionToggle;
>             if (transactionToggle) {
>                 return new String[] { "one", "two", "three", "four",
> "five", "six", "seven", "eight", "nine", "ten" };
>             }
>             return new String[] { "A", "B", "C", "D", "E", "F", "G",
> "H", "I", "J" };
>         }
>         public void dispose() {
>         }
>         public void inputChanged(Viewer viewer, Object oldInput, Object
> newInput) {
>         }
>     }
> 
>     /**
>      * @param args
>      */
>     public static void main(String[] args) {
>         final Display display = new Display();
>         Shell shell = new Shell(display);
>         shell.setLayout(new FillLayout());
> 
>         final 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 0;
>             }
>             public int getToolTipTimeDisplayed(Object object) {
>                 return 15000;
>             }
>             public void update(ViewerCell cell) {
>                 cell.setText(cell.getElement().toString());
>             }
>         };
> 
>         TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
>         column.setLabelProvider(labelProvider);
>         column.getColumn().setText("Column 1");
>         column.getColumn().setWidth(100);
> 
>         v.setInput("");
> 
>         v.getTable().addMouseTrackListener(new MouseTrackAdapter() {
>             /**
>              * {@inheritDoc}
>              */
>             @Override
>             public void mouseHover(MouseEvent e) {
>                 try {
>                     Thread.sleep(2000); // wait a couple seconds to
> allow user to see the change.
>                 }catch (Exception exception) {
>                 }
>                 v.setInput("");
>             }
>         });
> 
>         shell.setSize(200, 200);
>         shell.open();
> 
>         while (!shell.isDisposed()) {
>             if (!display.readAndDispatch()) {
>                 display.sleep();
>             }
>         }
>         display.dispose();
>     }
> }
> 
> ------------------------------------------------------------------------
> CONFIDENTIALITY NOTICE This message and any included attachments are
> from Cerner Corporation and are intended only for the addressee. The
> information contained in this message is confidential and may constitute
> inside or non-public information under international, federal, or state
> securities laws. Unauthorized forwarding, printing, copying,
> distribution, or use of such information is strictly prohibited and may
> be unlawful. If you are not the addressee, please promptly delete this
> message and notify the sender of the delivery error by e-mail or you may
> call Cerner's corporate offices in Kansas City, Missouri, U.S.A at (+1)
> (816)221-1024.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> platform-swt-dev mailing list
> platform-swt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev



Back to the top