Search in sources :

Example 81 with ControlListener

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

the class TableColumn_Test method testPackWithVirtual.

@Test
public void testPackWithVirtual() {
    final java.util.List<Widget> log = new ArrayList<Widget>();
    Listener setDataListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            log.add(event.item);
        }
    };
    ControlListener resizeListener = new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent event) {
            log.add(event.widget);
        }
    };
    // Must not try to access items if there aren't any
    log.clear();
    table = new Table(shell, SWT.VIRTUAL);
    column = new TableColumn(table, SWT.NONE);
    column.setWidth(200);
    column.addControlListener(resizeListener);
    column.pack();
    // ensure that pack() did something
    assertEquals(1, log.size());
    // Ensure that pack resolves only first virtual item
    log.clear();
    table = new Table(shell, SWT.VIRTUAL);
    column = new TableColumn(table, SWT.NONE);
    table.setSize(100, 50);
    table.setItemCount(100);
    table.addListener(SWT.SetData, setDataListener);
    column.pack();
    assertEquals(1, log.size());
}
Also used : ControlListener(org.eclipse.swt.events.ControlListener) SelectionListener(org.eclipse.swt.events.SelectionListener) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ArrayList(java.util.ArrayList) ControlEvent(org.eclipse.swt.events.ControlEvent) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) Test(org.junit.Test)

Example 82 with ControlListener

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

the class TableColumn_Test method testRemoveControlListener.

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

Example 83 with ControlListener

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

the class TableColumn_Test method testMoveEvent.

@Test
public void testMoveEvent() {
    final java.util.List<ControlEvent> log = new ArrayList<ControlEvent>();
    column.addControlListener(new ControlListener() {

        @Override
        public void controlMoved(ControlEvent event) {
            fail("unexpected event: controlMoved");
        }

        @Override
        public void controlResized(ControlEvent event) {
            log.add(event);
        }
    });
    final TableColumn column1 = new TableColumn(table, SWT.NONE);
    column1.addControlListener(new ControlListener() {

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

        @Override
        public void controlResized(ControlEvent event) {
            fail("unexpected event: controlResized");
        }
    });
    ControlEvent event;
    // Changing column width leads to resize event and move event of the next
    // columns
    log.clear();
    column.setWidth(column.getWidth() + 1);
    assertEquals(2, log.size());
    event = log.get(0);
    assertSame(column, event.getSource());
    event = log.get(1);
    assertSame(column1, event.getSource());
}
Also used : ArrayList(java.util.ArrayList) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) Test(org.junit.Test)

Example 84 with ControlListener

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

the class TableColumn_Test method testResizeEvent.

@Test
public void testResizeEvent() {
    final java.util.List<ControlEvent> log = new ArrayList<ControlEvent>();
    column.addControlListener(new ControlListener() {

        @Override
        public void controlMoved(ControlEvent event) {
            fail("unexpected event: controlMoved");
        }

        @Override
        public void controlResized(ControlEvent event) {
            log.add(event);
        }
    });
    ControlEvent event;
    // Changing column width leads to resize event
    log.clear();
    column.setWidth(column.getWidth() + 1);
    assertEquals(1, log.size());
    event = log.get(0);
    assertSame(column, event.getSource());
    // Setting the column width to the same value it already has as well leads
    // to resize event
    log.clear();
    column.setWidth(column.getWidth());
    assertEquals(1, log.size());
    event = log.get(0);
    assertEquals(column, event.getSource());
}
Also used : ArrayList(java.util.ArrayList) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) Test(org.junit.Test)

Example 85 with ControlListener

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

the class TreeColumn_Test method testRemoveControlListener.

@Test
public void testRemoveControlListener() {
    ControlListener listener = mock(ControlListener.class);
    column.addControlListener(listener);
    column.removeControlListener(listener);
    assertFalse(column.isListening(SWT.Move));
    assertFalse(column.isListening(SWT.Resize));
}
Also used : ControlListener(org.eclipse.swt.events.ControlListener) 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