Search in sources :

Example 76 with ControlListener

use of org.eclipse.swt.events.ControlListener in project eclipse.jdt.ui by eclipse-jdt.

the class ResizableDialog method getInitialSize.

@Override
protected Point getInitialSize() {
    int width = 0;
    int height = 0;
    final Shell s = getShell();
    if (s != null) {
        s.addControlListener(new ControlListener() {

            @Override
            public void controlMoved(ControlEvent arg0) {
                fNewBounds = s.getBounds();
            }

            @Override
            public void controlResized(ControlEvent arg0) {
                fNewBounds = s.getBounds();
            }
        });
    }
    IDialogSettings bounds = fSettings.getSection(DIALOG_BOUNDS_KEY);
    if (bounds == null) {
        if (fBundle != null) {
            width = JavaCompareUtilities.getInteger(fBundle, WIDTH, 0);
            height = JavaCompareUtilities.getInteger(fBundle, HEIGHT, 0);
            Shell shell = getParentShell();
            if (shell != null) {
                Point parentSize = shell.getSize();
                if (width <= 0)
                    width = parentSize.x - 300;
                if (height <= 0)
                    height = parentSize.y - 200;
            }
        } else {
            Shell shell = getParentShell();
            if (shell != null) {
                Point parentSize = shell.getSize();
                width = parentSize.x - 100;
                height = parentSize.y - 100;
            }
        }
        if (width < 700)
            width = 700;
        if (height < 500)
            height = 500;
    } else {
        try {
            width = bounds.getInt(WIDTH);
        } catch (NumberFormatException e) {
            width = 700;
        }
        try {
            height = bounds.getInt(HEIGHT);
        } catch (NumberFormatException e) {
            height = 500;
        }
    }
    return new Point(width, height);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) ControlListener(org.eclipse.swt.events.ControlListener) Point(org.eclipse.swt.graphics.Point) ControlEvent(org.eclipse.swt.events.ControlEvent) Point(org.eclipse.swt.graphics.Point)

Example 77 with ControlListener

use of org.eclipse.swt.events.ControlListener in project eclipse.jdt.ui by eclipse-jdt.

the class BreadcrumbItemDropDown method installCloser.

/**
 * The closer closes the given shell when the focus is lost.
 *
 * @param shell the shell to install the closer to
 */
private void installCloser(final Shell shell) {
    final Listener focusListener = event -> {
        Widget focusElement = event.widget;
        boolean isFocusBreadcrumbTreeFocusWidget = focusElement == shell || focusElement instanceof Tree && ((Tree) focusElement).getShell() == shell;
        boolean isFocusWidgetParentShell = focusElement instanceof Control && ((Control) focusElement).getShell().getParent() == shell;
        switch(event.type) {
            case SWT.FocusIn:
                if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
                    // $NON-NLS-1$
                    System.out.println("focusIn - is breadcrumb tree: " + isFocusBreadcrumbTreeFocusWidget);
                if (!isFocusBreadcrumbTreeFocusWidget && !isFocusWidgetParentShell) {
                    if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
                        // $NON-NLS-1$
                        System.out.println("==> closing shell since focus in other widget");
                    shell.close();
                }
                break;
            case SWT.FocusOut:
                if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
                    // $NON-NLS-1$
                    System.out.println("focusOut - is breadcrumb tree: " + isFocusBreadcrumbTreeFocusWidget);
                if (event.display.getActiveShell() == null) {
                    if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
                        // $NON-NLS-1$
                        System.out.println("==> closing shell since event.display.getActiveShell() == null");
                    shell.close();
                }
                break;
            default:
                Assert.isTrue(false);
        }
    };
    final Display display = shell.getDisplay();
    display.addFilter(SWT.FocusIn, focusListener);
    display.addFilter(SWT.FocusOut, focusListener);
    final ControlListener controlListener = new ControlListener() {

        @Override
        public void controlMoved(ControlEvent e) {
            shell.close();
        }

        @Override
        public void controlResized(ControlEvent e) {
            shell.close();
        }
    };
    fToolBar.getShell().addControlListener(controlListener);
    shell.addDisposeListener(e -> {
        if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
            // $NON-NLS-1$
            System.out.println("==> shell disposed");
        display.removeFilter(SWT.FocusIn, focusListener);
        display.removeFilter(SWT.FocusOut, focusListener);
        if (!fToolBar.isDisposed()) {
            fToolBar.getShell().removeControlListener(controlListener);
        }
    });
    shell.addShellListener(new ShellListener() {

        @Override
        public void shellActivated(ShellEvent e) {
        }

        @Override
        public void shellClosed(ShellEvent e) {
            if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
                // $NON-NLS-1$
                System.out.println("==> shellClosed");
            if (!fMenuIsShown)
                return;
            fMenuIsShown = false;
            fDropDownViewer = null;
        }

        @Override
        public void shellDeactivated(ShellEvent e) {
        }

        @Override
        public void shellDeiconified(ShellEvent e) {
        }

        @Override
        public void shellIconified(ShellEvent e) {
        }
    });
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) ToolBar(org.eclipse.swt.widgets.ToolBar) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) ImageDataProvider(org.eclipse.swt.graphics.ImageDataProvider) Composite(org.eclipse.swt.widgets.Composite) KeyEvent(org.eclipse.swt.events.KeyEvent) FormColors(org.eclipse.ui.forms.FormColors) Widget(org.eclipse.swt.widgets.Widget) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) JavaPlugin(org.eclipse.jdt.internal.ui.JavaPlugin) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) Assert(org.eclipse.core.runtime.Assert) Display(org.eclipse.swt.widgets.Display) ProblemTreeViewer(org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer) Util(org.eclipse.jface.util.Util) OpenStrategy(org.eclipse.jface.util.OpenStrategy) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseListener(org.eclipse.swt.events.MouseListener) Item(org.eclipse.swt.widgets.Item) Tree(org.eclipse.swt.widgets.Tree) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) ControlListener(org.eclipse.swt.events.ControlListener) ImageData(org.eclipse.swt.graphics.ImageData) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ControlEvent(org.eclipse.swt.events.ControlEvent) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent) Listener(org.eclipse.swt.widgets.Listener) SWTUtil(org.eclipse.jdt.internal.ui.util.SWTUtil) RGB(org.eclipse.swt.graphics.RGB) IFile(org.eclipse.core.resources.IFile) GridData(org.eclipse.swt.layout.GridData) Shell(org.eclipse.swt.widgets.Shell) ShellEvent(org.eclipse.swt.events.ShellEvent) Action(org.eclipse.jface.action.Action) CompositeImageDescriptor(org.eclipse.jface.resource.CompositeImageDescriptor) TreeItem(org.eclipse.swt.widgets.TreeItem) ShellListener(org.eclipse.swt.events.ShellListener) IJavaElement(org.eclipse.jdt.core.IJavaElement) Color(org.eclipse.swt.graphics.Color) IJarEntryResource(org.eclipse.jdt.core.IJarEntryResource) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ToolBarManager(org.eclipse.jface.action.ToolBarManager) KeyListener(org.eclipse.swt.events.KeyListener) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) MouseListener(org.eclipse.swt.events.MouseListener) ControlListener(org.eclipse.swt.events.ControlListener) Listener(org.eclipse.swt.widgets.Listener) ShellListener(org.eclipse.swt.events.ShellListener) KeyListener(org.eclipse.swt.events.KeyListener) ShellListener(org.eclipse.swt.events.ShellListener) Widget(org.eclipse.swt.widgets.Widget) Tree(org.eclipse.swt.widgets.Tree) ControlListener(org.eclipse.swt.events.ControlListener) ShellEvent(org.eclipse.swt.events.ShellEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) Display(org.eclipse.swt.widgets.Display)

Example 78 with ControlListener

use of org.eclipse.swt.events.ControlListener in project org.eclipse.rap by eclipse-rap.

the class WBWRenderer method hookControllerLogic.

@Override
public void hookControllerLogic(MUIElement me) {
    super.hookControllerLogic(me);
    Widget widget = (Widget) me.getWidget();
    if (widget instanceof Shell && me instanceof MWindow) {
        final Shell shell = (Shell) widget;
        final MWindow w = (MWindow) me;
        shell.addControlListener(new ControlListener() {

            /**
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void controlResized(ControlEvent e) {
                // Don't store the maximized size in the model
                if (shell.getMaximized())
                    return;
                try {
                    ignoreSizeChanges = true;
                    w.setWidth(shell.getSize().x);
                    w.setHeight(shell.getSize().y);
                } finally {
                    ignoreSizeChanges = false;
                }
            }

            @Override
            public void controlMoved(ControlEvent e) {
                // Don't store the maximized size in the model
                if (shell.getMaximized())
                    return;
                try {
                    ignoreSizeChanges = true;
                    w.setX(shell.getLocation().x);
                    w.setY(shell.getLocation().y);
                } finally {
                    ignoreSizeChanges = false;
                }
            }
        });
        shell.addShellListener(new ShellAdapter() {

            /**
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void shellClosed(ShellEvent e) {
                // override the shell close event
                e.doit = false;
                MWindow window = (MWindow) e.widget.getData(OWNING_ME);
                IWindowCloseHandler closeHandler = window.getContext().get(IWindowCloseHandler.class);
                // request, clean-up as necessary
                if (closeHandler == null || closeHandler.close(window)) {
                    cleanUp(window);
                }
            }
        });
        shell.addListener(SWT.Activate, new Listener() {

            /**
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void handleEvent(org.eclipse.swt.widgets.Event event) {
                MUIElement parentME = w.getParent();
                if (parentME instanceof MApplication) {
                    MApplication app = (MApplication) parentME;
                    app.setSelectedElement(w);
                    w.getContext().activate();
                } else if (parentME == null) {
                    parentME = (MUIElement) ((EObject) w).eContainer();
                    if (parentME instanceof MContext) {
                        w.getContext().activate();
                    }
                }
                updateNonFocusState(SWT.Activate, w);
            }
        });
        shell.addListener(SWT.Deactivate, new Listener() {

            /**
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void handleEvent(org.eclipse.swt.widgets.Event event) {
                updateNonFocusState(SWT.Deactivate, w);
            }
        });
    }
}
Also used : ShellAdapter(org.eclipse.swt.events.ShellAdapter) DisposeListener(org.eclipse.swt.events.DisposeListener) TraverseListener(org.eclipse.swt.events.TraverseListener) ControlListener(org.eclipse.swt.events.ControlListener) Listener(org.eclipse.swt.widgets.Listener) Widget(org.eclipse.swt.widgets.Widget) MContext(org.eclipse.e4.ui.model.application.ui.MContext) ShellEvent(org.eclipse.swt.events.ShellEvent) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) Shell(org.eclipse.swt.widgets.Shell) EObject(org.eclipse.emf.ecore.EObject) ControlListener(org.eclipse.swt.events.ControlListener) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) ControlEvent(org.eclipse.swt.events.ControlEvent) IWindowCloseHandler(org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler) MApplication(org.eclipse.e4.ui.model.application.MApplication)

Example 79 with ControlListener

use of org.eclipse.swt.events.ControlListener in project org.eclipse.rap by eclipse-rap.

the class GridColumn_Test method testAddRemoveControlListener.

@Test
public void testAddRemoveControlListener() {
    ControlListener listener = new ControlAdapter() {
    };
    assertFalse(column.isListening(SWT.Move));
    assertFalse(column.isListening(SWT.Resize));
    column.addControlListener(listener);
    assertTrue(column.isListening(SWT.Move));
    assertTrue(column.isListening(SWT.Resize));
    column.removeControlListener(listener);
    assertFalse(column.isListening(SWT.Move));
    assertFalse(column.isListening(SWT.Resize));
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) ControlListener(org.eclipse.swt.events.ControlListener) Test(org.junit.Test)

Example 80 with ControlListener

use of org.eclipse.swt.events.ControlListener in project org.eclipse.rap by eclipse-rap.

the class Shell_Test method testFullScreen.

@Test
public void testFullScreen() {
    final java.util.List<String> log = new ArrayList<String>();
    Rectangle displayBounds = new Rectangle(0, 0, 800, 600);
    getDisplayAdapter(display).setBounds(displayBounds);
    Rectangle shellBounds = new Rectangle(10, 10, 100, 100);
    shell.setBounds(shellBounds);
    shell.addControlListener(new ControlListener() {

        @Override
        public void controlMoved(ControlEvent event) {
            log.add("controlMoved");
        }

        @Override
        public void controlResized(ControlEvent event) {
            log.add("controlResized");
        }
    });
    shell.open();
    assertFalse(shell.getFullScreen());
    assertFalse(shell.getMaximized());
    assertFalse(shell.getMinimized());
    log.clear();
    shell.setMaximized(true);
    assertFalse(shell.getFullScreen());
    assertTrue(shell.getMaximized());
    assertFalse(shell.getMinimized());
    assertEquals(2, log.size());
    assertEquals("controlMoved", log.get(0));
    assertEquals("controlResized", log.get(1));
    assertEquals(displayBounds, shell.getBounds());
    shell.setMinimized(true);
    assertFalse(shell.getFullScreen());
    assertFalse(shell.getMaximized());
    assertTrue(shell.getMinimized());
    shell.setMinimized(false);
    assertFalse(shell.getFullScreen());
    assertTrue(shell.getMaximized());
    assertFalse(shell.getMinimized());
    log.clear();
    shell.setFullScreen(true);
    assertTrue(shell.getFullScreen());
    assertFalse(shell.getMaximized());
    assertFalse(shell.getMinimized());
    assertEquals(0, log.size());
    assertEquals(displayBounds, shell.getBounds());
    log.clear();
    shell.setMaximized(true);
    assertTrue(shell.getFullScreen());
    assertFalse(shell.getMaximized());
    assertFalse(shell.getMinimized());
    assertEquals(0, log.size());
    assertEquals(displayBounds, shell.getBounds());
    log.clear();
    shell.setMaximized(false);
    assertTrue(shell.getFullScreen());
    assertFalse(shell.getMaximized());
    assertFalse(shell.getMinimized());
    assertEquals(0, log.size());
    assertEquals(displayBounds, shell.getBounds());
    log.clear();
    shell.setMinimized(true);
    assertTrue(shell.getFullScreen());
    assertFalse(shell.getMaximized());
    assertTrue(shell.getMinimized());
    assertEquals(0, log.size());
    log.clear();
    shell.setMinimized(false);
    assertTrue(shell.getFullScreen());
    assertFalse(shell.getMaximized());
    assertFalse(shell.getMinimized());
    assertEquals(0, log.size());
    log.clear();
    shell.setFullScreen(false);
    assertFalse(shell.getFullScreen());
    assertTrue(shell.getMaximized());
    assertFalse(shell.getMinimized());
    assertEquals(0, log.size());
    assertEquals(displayBounds, shell.getBounds());
    shell.setMaximized(false);
    shell.setMinimized(true);
    log.clear();
    shell.setFullScreen(true);
    assertTrue(shell.getFullScreen());
    assertFalse(shell.getMaximized());
    assertFalse(shell.getMinimized());
    assertEquals(2, log.size());
    assertEquals("controlMoved", log.get(0));
    assertEquals("controlResized", log.get(1));
    assertEquals(displayBounds, shell.getBounds());
    log.clear();
    shell.setFullScreen(false);
    assertFalse(shell.getFullScreen());
    assertFalse(shell.getMaximized());
    assertFalse(shell.getMinimized());
    assertEquals(2, log.size());
    assertEquals("controlMoved", log.get(0));
    assertEquals("controlResized", log.get(1));
    assertEquals(shellBounds, shell.getBounds());
    shell.setFullScreen(true);
    log.clear();
    shell.setBounds(20, 20, 200, 200);
    assertFalse(shell.getFullScreen());
    assertFalse(shell.getMaximized());
    assertFalse(shell.getMinimized());
    assertEquals(2, log.size());
    assertEquals("controlMoved", log.get(0));
    assertEquals("controlResized", log.get(1));
}
Also used : ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) Test(org.junit.Test)

Aggregations

ControlListener (org.eclipse.swt.events.ControlListener)87 ControlEvent (org.eclipse.swt.events.ControlEvent)82 GridData (org.eclipse.swt.layout.GridData)31 FocusEvent (org.eclipse.swt.events.FocusEvent)19 Composite (org.eclipse.swt.widgets.Composite)19 Test (org.junit.Test)19 MouseEvent (org.eclipse.swt.events.MouseEvent)18 Point (org.eclipse.swt.graphics.Point)17 GridLayout (org.eclipse.swt.layout.GridLayout)17 KeyEvent (org.eclipse.swt.events.KeyEvent)16 ArrayList (java.util.ArrayList)14 SelectionEvent (org.eclipse.swt.events.SelectionEvent)14 DisposeEvent (org.eclipse.swt.events.DisposeEvent)13 Control (org.eclipse.swt.widgets.Control)13 Event (org.eclipse.swt.widgets.Event)13 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)11 DisposeListener (org.eclipse.swt.events.DisposeListener)11 FocusListener (org.eclipse.swt.events.FocusListener)11 Listener (org.eclipse.swt.widgets.Listener)10 ModifyEvent (org.eclipse.swt.events.ModifyEvent)9