Search in sources :

Example 86 with SelectionListener

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

the class Test_org_eclipse_swt_widgets_Link method test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener.

@Test
public void test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener() {
    listenerCalled = false;
    SelectionListener listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            listenerCalled = true;
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    };
    try {
        link.addSelectionListener(null);
        fail("No exception thrown for addSelectionListener with null argument");
    } catch (IllegalArgumentException e) {
    }
    link.addSelectionListener(listener);
    link.notifyListeners(SWT.Selection, new Event());
    assertTrue(listenerCalled);
    try {
        link.removeSelectionListener(null);
        fail("No exception thrown for removeSelectionListener with null argument");
    } catch (IllegalArgumentException e) {
    }
    listenerCalled = false;
    link.removeSelectionListener(listener);
    link.notifyListeners(SWT.Selection, new Event());
    assertFalse(listenerCalled);
}
Also used : SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener) Test(org.junit.Test)

Example 87 with SelectionListener

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

the class Test_org_eclipse_swt_widgets_List method test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener.

@Test
public void test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener() {
    listenerCalled = false;
    boolean exceptionThrown = false;
    SelectionListener listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            listenerCalled = true;
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
        }
    };
    try {
        list.addSelectionListener(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue("Expected exception not thrown for listener == null", exceptionThrown);
    list.addSelectionListener(listener);
    list.select(0);
    assertFalse(":a:", listenerCalled);
    list.removeSelectionListener(listener);
    exceptionThrown = false;
    try {
        list.removeSelectionListener(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue("Expected exception not thrown for listener == null", exceptionThrown);
    // test single-selection list
    setSingleList();
    listenerCalled = false;
    exceptionThrown = false;
    try {
        list.addSelectionListener(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue("Expected exception not thrown for listener == null", exceptionThrown);
    list.addSelectionListener(listener);
    list.select(0);
    assertFalse(":a:", listenerCalled);
    list.removeSelectionListener(listener);
    exceptionThrown = false;
    try {
        list.removeSelectionListener(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue("Expected exception not thrown for listener == null", exceptionThrown);
}
Also used : SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener) Test(org.junit.Test)

Example 88 with SelectionListener

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

the class Test_org_eclipse_swt_widgets_MenuItem method test_addSelectionListenerWidgetSelectedAdapterLorg_eclipse_swt_events_SelectionListener.

@Test
public void test_addSelectionListenerWidgetSelectedAdapterLorg_eclipse_swt_events_SelectionListener() {
    listenerCalled = false;
    SelectionListener listener = SelectionListener.widgetSelectedAdapter(e -> listenerCalled = true);
    menuItem.addSelectionListener(listener);
    menuItem.notifyListeners(SWT.Selection, new Event());
    assertTrue(listenerCalled);
    listenerCalled = false;
    menuItem.removeSelectionListener(listener);
    menuItem.notifyListeners(SWT.Selection, new Event());
    assertFalse(listenerCalled);
}
Also used : Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener) Test(org.junit.Test)

Example 89 with SelectionListener

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

the class Test_org_eclipse_swt_widgets_ScrollBar method test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener.

@Test
public void test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener() {
    listenerCalled = false;
    boolean exceptionThrown = false;
    SelectionListener listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            listenerCalled = true;
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
        }
    };
    try {
        scrollBar.addSelectionListener(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue("Expected exception not thrown", exceptionThrown);
    exceptionThrown = false;
    scrollBar.addSelectionListener(listener);
    scrollBar.setSelection(100);
    assertTrue(":a:", listenerCalled == false);
    scrollBar.removeSelectionListener(listener);
    try {
        scrollBar.removeSelectionListener(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue("Expected exception not thrown", exceptionThrown);
}
Also used : SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener) Test(org.junit.Test)

Example 90 with SelectionListener

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

the class Test_org_eclipse_swt_widgets_Slider method test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener.

@Test
public void test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener() {
    listenerCalled = false;
    boolean exceptionThrown = false;
    SelectionListener listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            listenerCalled = true;
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
        }
    };
    try {
        slider.addSelectionListener(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue("Expected exception not thrown", exceptionThrown);
    exceptionThrown = false;
    slider.addSelectionListener(listener);
    slider.setSelection(0);
    assertFalse(":a:", listenerCalled);
    slider.removeSelectionListener(listener);
    try {
        slider.removeSelectionListener(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue("Expected exception not thrown", exceptionThrown);
}
Also used : SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener) Test(org.junit.Test)

Aggregations

SelectionListener (org.eclipse.swt.events.SelectionListener)711 SelectionEvent (org.eclipse.swt.events.SelectionEvent)665 GridData (org.eclipse.swt.layout.GridData)411 Button (org.eclipse.swt.widgets.Button)409 Composite (org.eclipse.swt.widgets.Composite)381 GridLayout (org.eclipse.swt.layout.GridLayout)374 Label (org.eclipse.swt.widgets.Label)256 Text (org.eclipse.swt.widgets.Text)152 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)140 Group (org.eclipse.swt.widgets.Group)137 ModifyListener (org.eclipse.swt.events.ModifyListener)113 ModifyEvent (org.eclipse.swt.events.ModifyEvent)112 Combo (org.eclipse.swt.widgets.Combo)101 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)69 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)69 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)69 FormData (org.eclipse.swt.layout.FormData)69 Event (org.eclipse.swt.widgets.Event)69 FormAttachment (org.eclipse.swt.layout.FormAttachment)68 ArrayList (java.util.ArrayList)57