Search in sources :

Example 51 with DisposeListener

use of org.eclipse.swt.events.DisposeListener in project eclipse.platform.text by eclipse.

the class AbstractInformationControlManager method getInformationControl.

/**
 * Returns the information control. If the information control has not been created yet,
 * it is automatically created.
 *
 * @return the information control
 */
protected IInformationControl getInformationControl() {
    if (fDisposed)
        return fInformationControl;
    IInformationControlCreator creator = null;
    if (fCustomInformationControlCreator == null) {
        creator = fInformationControlCreator;
        if (fIsCustomInformationControl && fInformationControl != null) {
            if (fInformationControl instanceof IInformationControlExtension5)
                fSizeConstraints = null;
            fInformationControl.dispose();
            fInformationControl = null;
        }
        fIsCustomInformationControl = false;
    } else {
        creator = fCustomInformationControlCreator;
        if (creator instanceof IInformationControlCreatorExtension) {
            IInformationControlCreatorExtension extension = (IInformationControlCreatorExtension) creator;
            if (fInformationControl != null && extension.canReuse(fInformationControl))
                return fInformationControl;
        }
        if (fInformationControl != null) {
            if (fInformationControl instanceof IInformationControlExtension5)
                fSizeConstraints = null;
            fInformationControl.dispose();
            fInformationControl = null;
        }
        fIsCustomInformationControl = true;
    }
    if (fInformationControl == null) {
        fInformationControl = creator.createInformationControl(fSubjectControl.getShell());
        fInformationControl.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                handleInformationControlDisposed();
            }
        });
        if (fInformationControlCloser != null)
            fInformationControlCloser.setInformationControl(fInformationControl);
    }
    return fInformationControl;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 52 with DisposeListener

use of org.eclipse.swt.events.DisposeListener in project eclipse.platform.text by eclipse.

the class AnnotationRulerColumn method createControl.

@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
    fParentRuler = parentRuler;
    fCachedTextViewer = parentRuler.getTextViewer();
    fCachedTextWidget = fCachedTextViewer.getTextWidget();
    fHitDetectionCursor = parentControl.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
    fCanvas = createCanvas(parentControl);
    fCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent event) {
            if (fCachedTextViewer != null)
                doubleBufferPaint(event.gc);
        }
    });
    fCanvas.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            handleDispose();
            fCachedTextViewer = null;
            fCachedTextWidget = null;
        }
    });
    fMouseListener = new MouseListener() {

        @Override
        public void mouseUp(MouseEvent event) {
            int lineNumber;
            if (isPropagatingMouseListener()) {
                fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
                lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
            } else
                lineNumber = fParentRuler.toDocumentLineNumber(event.y);
            if (1 == event.button)
                mouseClicked(lineNumber);
        }

        @Override
        public void mouseDown(MouseEvent event) {
            int lineNumber;
            if (isPropagatingMouseListener()) {
                fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
                lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
            } else
                lineNumber = fParentRuler.toDocumentLineNumber(event.y);
            if (1 == event.button)
                AnnotationRulerColumn.this.mouseDown(lineNumber);
        }

        @Override
        public void mouseDoubleClick(MouseEvent event) {
            int lineNumber;
            if (isPropagatingMouseListener()) {
                fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
                lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
            } else
                lineNumber = fParentRuler.toDocumentLineNumber(event.y);
            if (1 == event.button)
                mouseDoubleClicked(lineNumber);
        }
    };
    fCanvas.addMouseListener(fMouseListener);
    fCanvas.addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent e) {
            handleMouseMove(e);
        }
    });
    fCanvas.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseScrolled(MouseEvent e) {
            handleMouseScrolled(e);
        }
    });
    if (fCachedTextViewer != null) {
        VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
        fCachedTextViewer.addTextListener(fLineListener);
        // on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the ruler
        fCachedTextWidget.addControlListener(new ControlAdapter() {

            @Override
            public void controlResized(ControlEvent e) {
                if (fCachedTextWidget != null && fCachedTextWidget.getWordWrap()) {
                    redraw();
                }
            }
        });
    }
    return fCanvas;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) ControlAdapter(org.eclipse.swt.events.ControlAdapter) PaintListener(org.eclipse.swt.events.PaintListener) MouseWheelListener(org.eclipse.swt.events.MouseWheelListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 53 with DisposeListener

use of org.eclipse.swt.events.DisposeListener in project eclipse.platform.text by eclipse.

the class LineNumberRulerColumn method createControl.

@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
    fParentRuler = parentRuler;
    fCachedTextViewer = parentRuler.getTextViewer();
    fCachedTextWidget = fCachedTextViewer.getTextWidget();
    // on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the line ruler
    fCachedTextWidget.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            if (fCachedTextWidget != null && fCachedTextWidget.getWordWrap()) {
                postRedraw();
            }
        }
    });
    // track when StyledText is redrawn to check if some line height changed. In this case, the ruler must be redrawn
    // to draw line number with well height.
    VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
    fCanvas = new Canvas(parentControl, SWT.NO_FOCUS) {

        @Override
        public void addMouseListener(MouseListener listener) {
            // see bug 40889, bug 230073 and AnnotationRulerColumn#isPropagatingMouseListener()
            if (listener == fMouseHandler)
                super.addMouseListener(listener);
            else {
                TypedListener typedListener = null;
                if (listener != null)
                    typedListener = new TypedListener(listener);
                addListener(SWT.MouseDoubleClick, typedListener);
            }
        }
    };
    fCanvas.setBackground(getBackground(fCanvas.getDisplay()));
    fCanvas.setForeground(fForeground);
    fCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent event) {
            if (fCachedTextViewer != null)
                doubleBufferPaint(event.gc);
        }
    });
    fCanvas.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            handleDispose();
            fCachedTextViewer = null;
            fCachedTextWidget = null;
        }
    });
    fMouseHandler = new MouseHandler();
    fCanvas.addMouseListener(fMouseHandler);
    fCanvas.addMouseMoveListener(fMouseHandler);
    fCanvas.addMouseWheelListener(fMouseHandler);
    if (fCachedTextViewer != null) {
        VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
        fCachedTextViewer.addTextListener(fInternalListener);
        if (fFont == null) {
            if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed())
                fFont = fCachedTextWidget.getFont();
        }
    }
    if (fFont != null)
        fCanvas.setFont(fFont);
    updateNumberOfDigits();
    computeIndentations();
    return fCanvas;
}
Also used : TypedListener(org.eclipse.swt.widgets.TypedListener) DisposeListener(org.eclipse.swt.events.DisposeListener) MouseListener(org.eclipse.swt.events.MouseListener) PaintEvent(org.eclipse.swt.events.PaintEvent) ControlAdapter(org.eclipse.swt.events.ControlAdapter) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) ControlEvent(org.eclipse.swt.events.ControlEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 54 with DisposeListener

use of org.eclipse.swt.events.DisposeListener in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method createControl.

/**
 * {@inheritDoc}
 */
@Override
public void createControl(final Composite parent) {
    TabFolder tabs = new TabFolder(parent, SWT.BORDER);
    TabItem usageTab = new TabItem(tabs, SWT.NONE);
    usageTab.setText("Node Usage");
    m_nodeUsageComposite = new NodeUsageComposite(tabs, m_viewNodes, m_subNodeContainer);
    usageTab.setControl(m_nodeUsageComposite);
    usageTab.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(final DisposeEvent e) {
            m_nodeUsageComposite = null;
        }
    });
    TabItem basicTab = new TabItem(tabs, SWT.NONE);
    basicTab.setText("Basic Layout");
    basicTab.setControl(createBasicComposite(tabs));
    TabItem jsonTab = new TabItem(tabs, SWT.NONE);
    jsonTab.setText("Advanced Layout");
    jsonTab.setControl(createJSONEditorComposite(tabs));
    setControl(tabs);
}
Also used : TabItem(org.eclipse.swt.widgets.TabItem) DisposeListener(org.eclipse.swt.events.DisposeListener) TabFolder(org.eclipse.swt.widgets.TabFolder) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 55 with DisposeListener

use of org.eclipse.swt.events.DisposeListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Widget method test_addDisposeListenerLorg_eclipse_swt_events_DisposeListener.

@Test
public void test_addDisposeListenerLorg_eclipse_swt_events_DisposeListener() {
    DisposeListener listener = e -> {
    };
    widget.addDisposeListener(listener);
    widget.removeDisposeListener(listener);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Assert.assertNotNull(org.junit.Assert.assertNotNull) DisposeListener(org.eclipse.swt.events.DisposeListener) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) GC(org.eclipse.swt.graphics.GC) Event(org.eclipse.swt.widgets.Event) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Listener(org.eclipse.swt.widgets.Listener) TestName(org.junit.rules.TestName) SWT(org.eclipse.swt.SWT) After(org.junit.After) Assert.fail(org.junit.Assert.fail) Widget(org.eclipse.swt.widgets.Widget) Assert.assertEquals(org.junit.Assert.assertEquals) Control(org.eclipse.swt.widgets.Control) Before(org.junit.Before) DisposeListener(org.eclipse.swt.events.DisposeListener) Test(org.junit.Test)

Aggregations

DisposeListener (org.eclipse.swt.events.DisposeListener)118 DisposeEvent (org.eclipse.swt.events.DisposeEvent)117 SelectionEvent (org.eclipse.swt.events.SelectionEvent)41 GridData (org.eclipse.swt.layout.GridData)38 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)33 Image (org.eclipse.swt.graphics.Image)29 Cursor (org.eclipse.swt.graphics.Cursor)26 ToolBar (org.eclipse.swt.widgets.ToolBar)25 ToolItem (org.eclipse.swt.widgets.ToolItem)23 Composite (org.eclipse.swt.widgets.Composite)19 Color (org.eclipse.swt.graphics.Color)17 GridLayout (org.eclipse.swt.layout.GridLayout)17 Point (org.eclipse.swt.graphics.Point)16 ControlEvent (org.eclipse.swt.events.ControlEvent)11 SelectionListener (org.eclipse.swt.events.SelectionListener)10 Control (org.eclipse.swt.widgets.Control)10 TextLayout (org.eclipse.swt.graphics.TextLayout)9 Listener (org.eclipse.swt.widgets.Listener)9 ControlListener (org.eclipse.swt.events.ControlListener)8 MouseEvent (org.eclipse.swt.events.MouseEvent)8