Search in sources :

Example 41 with ControlListener

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

the class DataLinkTableViewer method addFixedColumns.

private void addFixedColumns(TableColumnLayout tcl) {
    TableViewerColumn nameColumn = new TableViewerColumn(this, SWT.LEFT);
    nameColumn.getColumn().setText(COL_NAME);
    tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(18));
    TableViewerColumn typeColumn = new TableViewerColumn(this, SWT.LEFT);
    typeColumn.getColumn().setText(COL_TYPE);
    tcl.setColumnData(typeColumn.getColumn(), new ColumnWeightData(18));
    TableViewerColumn specColumn = new TableViewerColumn(this, SWT.LEFT);
    specColumn.getColumn().setText(COL_SPEC);
    tcl.setColumnData(specColumn.getColumn(), new ColumnWeightData(18));
    TableViewerColumn streamColumn = new TableViewerColumn(this, SWT.LEFT);
    streamColumn.getColumn().setText(COL_STREAM);
    tcl.setColumnData(streamColumn.getColumn(), new ColumnWeightData(18));
    TableViewerColumn statusColumn = new TableViewerColumn(this, SWT.CENTER);
    statusColumn.getColumn().setText(COL_STATUS);
    tcl.setColumnData(statusColumn.getColumn(), new ColumnWeightData(18));
    TableViewerColumn datacount = new TableViewerColumn(this, SWT.RIGHT);
    datacount.getColumn().setText(COL_DATACOUNT);
    tcl.setColumnData(datacount.getColumn(), new ColumnWeightData(10));
    // Common properties to all columns
    List<TableViewerColumn> columns = new ArrayList<>();
    columns.add(nameColumn);
    columns.add(typeColumn);
    columns.add(specColumn);
    columns.add(streamColumn);
    columns.add(statusColumn);
    columns.add(datacount);
    for (TableViewerColumn column : columns) {
        // prevent resize to 0
        column.getColumn().addControlListener(new ControlListener() {

            @Override
            public void controlMoved(ControlEvent e) {
            }

            @Override
            public void controlResized(ControlEvent e) {
                if (column.getColumn().getWidth() < 5)
                    column.getColumn().setWidth(5);
            }
        });
    }
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ArrayList(java.util.ArrayList) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 42 with ControlListener

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

the class Test_org_eclipse_swt_widgets_Control method test_addControlListenerLorg_eclipse_swt_events_ControlListener.

@Test
public void test_addControlListenerLorg_eclipse_swt_events_ControlListener() {
    ControlListener listener = new ControlListener() {

        @Override
        public void controlMoved(ControlEvent e) {
            eventOccurred = true;
        }

        @Override
        public void controlResized(ControlEvent e) {
            eventOccurred = true;
        }
    };
    control.addControlListener(listener);
    eventOccurred = false;
    control.notifyListeners(SWT.Move, new Event());
    assertTrue(eventOccurred);
    eventOccurred = false;
    control.notifyListeners(SWT.Resize, new Event());
    assertTrue(eventOccurred);
    control.removeControlListener(listener);
}
Also used : ControlListener(org.eclipse.swt.events.ControlListener) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) Test(org.junit.Test)

Example 43 with ControlListener

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

the class Test_org_eclipse_swt_widgets_Control method test_addControlListenerControlMovedAdapterLorg_eclipse_swt_events_ControlListener.

@Test
public void test_addControlListenerControlMovedAdapterLorg_eclipse_swt_events_ControlListener() {
    ControlListener listener = ControlListener.controlMovedAdapter(e -> eventOccurred = true);
    control.addControlListener(listener);
    eventOccurred = false;
    control.notifyListeners(SWT.Move, new Event());
    assertTrue(eventOccurred);
    eventOccurred = false;
    control.notifyListeners(SWT.Resize, new Event());
    assertFalse(eventOccurred);
    control.removeControlListener(listener);
    eventOccurred = false;
    control.notifyListeners(SWT.Move, new Event());
    assertFalse(eventOccurred);
    control.notifyListeners(SWT.Resize, new Event());
    assertFalse(eventOccurred);
}
Also used : ControlListener(org.eclipse.swt.events.ControlListener) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Test(org.junit.Test)

Example 44 with ControlListener

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

the class Bug497705_setBoundsAfterSetVisible method fails_unecessaryEvents.

@Test
public void fails_unecessaryEvents() {
    // Breaks on Gtk3.8 & onwards
    testControl.setVisible(false);
    AtomicInteger resizeCount = new AtomicInteger(0);
    AtomicInteger moveCount = new AtomicInteger(0);
    testControl.addControlListener(new ControlListener() {

        @Override
        public void controlResized(ControlEvent e) {
            resizeCount.incrementAndGet();
        }

        @Override
        public void controlMoved(ControlEvent e) {
            moveCount.incrementAndGet();
        }
    });
    for (int i = 0; i < 10; i++) {
        // Once bounds set, calling same bounds shouldn't trigger SWT.MOVE events.
        testControl.setBounds(x, y, width, height);
    }
    if (resizeCount.get() != 1 || moveCount.get() != 1) {
        passed = false;
        log.append("\nERROR:\nExpected only one Resize and one Move event.\nActually received R/M:" + resizeCount.get() + "/" + moveCount.get());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) Test(org.junit.Test)

Example 45 with ControlListener

use of org.eclipse.swt.events.ControlListener in project tmdm-studio-se by Talend.

the class XObjectBrowser method createToolbar.

protected void createToolbar(final Composite parent) {
    toolBar = new TdEditorToolBar(parent);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    toolBar.getToolbarControl().setLayoutData(data);
    toolBar.addResizeListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
        }

        public void controlResized(ControlEvent e) {
            parent.getParent().layout(true);
            parent.layout(true);
        }
    });
}
Also used : FormData(org.eclipse.swt.layout.FormData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

ControlEvent (org.eclipse.swt.events.ControlEvent)54 ControlListener (org.eclipse.swt.events.ControlListener)54 GridData (org.eclipse.swt.layout.GridData)21 FocusEvent (org.eclipse.swt.events.FocusEvent)14 Control (org.eclipse.swt.widgets.Control)12 FocusListener (org.eclipse.swt.events.FocusListener)11 MouseEvent (org.eclipse.swt.events.MouseEvent)11 GridLayout (org.eclipse.swt.layout.GridLayout)11 Composite (org.eclipse.swt.widgets.Composite)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 ArrayList (java.util.ArrayList)9 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)9 DisposeEvent (org.eclipse.swt.events.DisposeEvent)9 DisposeListener (org.eclipse.swt.events.DisposeListener)9 KeyEvent (org.eclipse.swt.events.KeyEvent)9 Point (org.eclipse.swt.graphics.Point)9 Event (org.eclipse.swt.widgets.Event)8 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)6 Listener (org.eclipse.swt.widgets.Listener)6 Table (org.eclipse.swt.widgets.Table)6