Search in sources :

Example 16 with MouseTrackAdapter

use of org.eclipse.swt.events.MouseTrackAdapter in project archi by archimatetool.

the class EditPartTipHelper method hookShellListeners.

@Override
protected void hookShellListeners() {
    /*
         * If the cursor leaves the tip window, hide the tooltip and dispose of
         * its shell
         */
    getShell().addMouseTrackListener(new MouseTrackAdapter() {

        @Override
        public void mouseExit(MouseEvent e) {
            getShell().setCapture(false);
            dispose();
        }
    });
    /*
         * If the mouseExit listener does not get called, dispose of the shell
         * if the cursor is no longer in the tooltip. This occurs in the rare
         * case that a mouseEnter is not received on the tooltip when it
         * appears.
         */
    getShell().addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent e) {
            Point eventPoint = getShell().toDisplay(new Point(e.x, e.y));
            if (!getShell().getBounds().contains(eventPoint)) {
                if (isShowing())
                    getShell().setCapture(false);
                dispose();
            }
        }
    });
    // window.
    if (shellListener == null) {
        shellListener = new ShellAdapter() {

            @Override
            public void shellDeactivated(ShellEvent event) {
                Display.getCurrent().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        Shell active = Display.getCurrent().getActiveShell();
                        if (getShell() == active || control.getShell() == active || getShell().isDisposed())
                            return;
                        if (isShowing())
                            getShell().setCapture(false);
                        dispose();
                    }
                });
            }
        };
        control.getShell().addShellListener(shellListener);
        getShell().addShellListener(shellListener);
    }
    /*
         * Workaround for GTK Bug - Control.setCapture(boolean) not implemented:
         * If the cursor is not over the shell when it is first painted, hide
         * the tooltip and dispose of the shell.
         */
    if (SWT.getPlatform().equals("gtk")) {
        // $NON-NLS-1$
        getShell().addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent event) {
                Point cursorLoc = Display.getCurrent().getCursorLocation();
                if (!getShell().getBounds().contains(cursorLoc)) {
                    // This must be run asynchronously. If not, other paint
                    // listeners may attempt to paint on a disposed control.
                    Display.getCurrent().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (isShowing())
                                getShell().setCapture(false);
                            dispose();
                        }
                    });
                }
            }
        });
    }
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Shell(org.eclipse.swt.widgets.Shell) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) ShellEvent(org.eclipse.swt.events.ShellEvent) Point(org.eclipse.swt.graphics.Point)

Aggregations

MouseTrackAdapter (org.eclipse.swt.events.MouseTrackAdapter)16 MouseEvent (org.eclipse.swt.events.MouseEvent)15 Point (org.eclipse.swt.graphics.Point)9 MouseAdapter (org.eclipse.swt.events.MouseAdapter)7 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)6 Shell (org.eclipse.swt.widgets.Shell)5 PaintEvent (org.eclipse.swt.events.PaintEvent)4 PaintListener (org.eclipse.swt.events.PaintListener)4 GridData (org.eclipse.swt.layout.GridData)4 KeyEvent (org.eclipse.swt.events.KeyEvent)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Label (org.eclipse.swt.widgets.Label)3 MenuManager (org.eclipse.jface.action.MenuManager)2 ControlAdapter (org.eclipse.swt.events.ControlAdapter)2 ControlEvent (org.eclipse.swt.events.ControlEvent)2 Control (org.eclipse.swt.widgets.Control)2 Text (org.eclipse.swt.widgets.Text)2 XpathSelectDialog (com.amalto.workbench.dialogs.XpathSelectDialog)1 SortFieldSelectionFilter (com.amalto.workbench.dialogs.filter.SortFieldSelectionFilter)1