Search in sources :

Example 21 with ControlEvent

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

the class AbstractTemplatesPage method createTemplateTree.

/**
 * Create the tree to display templates.
 *
 * @param parent the parent composite
 */
private void createTemplateTree(Composite parent) {
    Composite treeComposite = new Composite(parent, SWT.NONE);
    GridData data = new GridData(GridData.FILL_BOTH);
    treeComposite.setLayoutData(data);
    TreeColumnLayout columnLayout = new TreeColumnLayout();
    treeComposite.setLayout(columnLayout);
    fTemplatesTree = new Tree(treeComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    fTemplatesTree.setHeaderVisible(true);
    fTemplatesTree.setLinesVisible(true);
    PixelConverter pixelConverter = new PixelConverter(fTemplatesTree);
    TreeColumn columnName = new TreeColumn(fTemplatesTree, SWT.NONE);
    columnName.setText(TemplatesMessages.TemplatesPage_column_name);
    int minWidth = fPreferenceStore.getInt(COLUMN_NAME_WIDTH_PREF_ID);
    if (minWidth == 0) {
        minWidth = pixelConverter.convertWidthInCharsToPixels(30);
    }
    columnLayout.setColumnData(columnName, new ColumnPixelData(minWidth, true));
    columnName.addControlListener(new ControlListener() {

        @Override
        public void controlMoved(ControlEvent e) {
        }

        @Override
        public void controlResized(ControlEvent e) {
            int nameWidth = ((TreeColumn) e.getSource()).getWidth();
            fPreferenceStore.setValue(COLUMN_NAME_WIDTH_PREF_ID, nameWidth);
        }
    });
    TreeColumn columnDescription = new TreeColumn(fTemplatesTree, SWT.NONE);
    columnDescription.setText(TemplatesMessages.TemplatesPage_column_description);
    minWidth = fPreferenceStore.getInt(COLUMN_DESCRIPTION_WIDTH_PREF_ID);
    if (minWidth == 0) {
        minWidth = pixelConverter.convertWidthInCharsToPixels(45);
    }
    columnLayout.setColumnData(columnDescription, new ColumnPixelData(minWidth, false));
    columnDescription.addControlListener(new ControlListener() {

        @Override
        public void controlMoved(ControlEvent e) {
        }

        @Override
        public void controlResized(ControlEvent e) {
            int descriptionWidth = ((TreeColumn) e.getSource()).getWidth();
            fPreferenceStore.setValue(COLUMN_DESCRIPTION_WIDTH_PREF_ID, descriptionWidth);
        }
    });
    createTreeViewer(fTemplatesTree);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeColumn(org.eclipse.swt.widgets.TreeColumn) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Tree(org.eclipse.swt.widgets.Tree) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) Point(org.eclipse.swt.graphics.Point)

Example 22 with ControlEvent

use of org.eclipse.swt.events.ControlEvent 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 23 with ControlEvent

use of org.eclipse.swt.events.ControlEvent 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 24 with ControlEvent

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

the class MJ_Table method cout_visible_items_Snippet253.

@Test
public void cout_visible_items_Snippet253() {
    final Shell shell = mkShell("Ensure correct item count is displayed in count. Try resizing shell to show 15 items, it should show 15. Gtk3 issues");
    knownToBeBrokenGtk3("On gtk3, the measure is off, see bug 531884");
    FillLayout layout = new FillLayout(SWT.VERTICAL);
    shell.setLayout(layout);
    final Table table = new Table(shell, SWT.NONE);
    for (int i = 0; i < 32; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("Item " + (i + 1) + " is quite long");
    }
    final Button button = new Button(shell, SWT.PUSH);
    Runnable fixCount = () -> {
        Rectangle rect = table.getClientArea();
        int itemHeight = table.getItemHeight();
        int headerHeight = table.getHeaderHeight();
        int visibleCount = (rect.height - headerHeight + itemHeight - 1) / itemHeight;
        button.setText("Visible Items [" + visibleCount + "]");
    };
    button.setText("Visible Items []");
    button.addListener(SWT.Selection, e -> {
        fixCount.run();
    });
    shell.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            fixCount.run();
        }
    });
    shell.addShellListener(new ShellAdapter() {

        @Override
        public void shellActivated(ShellEvent e) {
            fixCount.run();
        }
    });
    // setSize(..)_ affects bug/snippet behaviour.
    // 820 => ~15 items or so, depending on your theme.
    shell.setSize(1160, 820);
    shell.open();
    mainLoop(shell);
}
Also used : ShellAdapter(org.eclipse.swt.events.ShellAdapter) Table(org.eclipse.swt.widgets.Table) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) ShellEvent(org.eclipse.swt.events.ShellEvent) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) ControlEvent(org.eclipse.swt.events.ControlEvent) Test(org.junit.Test)

Example 25 with ControlEvent

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

the class ClientsTableViewer method addFixedColumns.

private void addFixedColumns() {
    TableViewerColumn idColumn = new TableViewerColumn(this, SWT.CENTER);
    idColumn.getColumn().setText(COL_ID);
    idColumn.getColumn().setWidth(30);
    idColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ClientInfo client = (ClientInfo) element;
            return String.valueOf(client.getId());
        }
    });
    TableViewerColumn userColumn = new TableViewerColumn(this, SWT.LEFT);
    userColumn.getColumn().setText(COL_USER);
    userColumn.getColumn().setWidth(100);
    userColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ClientInfo client = (ClientInfo) element;
            return String.valueOf(client.getUsername());
        }
    });
    TableViewerColumn applicationColumn = new TableViewerColumn(this, SWT.LEFT);
    applicationColumn.getColumn().setText(COL_APPLICATION);
    applicationColumn.getColumn().setWidth(100);
    applicationColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ClientInfo client = (ClientInfo) element;
            return client.getApplicationName();
        }
    });
    TableViewerColumn instanceColumn = new TableViewerColumn(this, SWT.LEFT);
    instanceColumn.getColumn().setText(COL_INSTANCE);
    instanceColumn.getColumn().setWidth(100);
    instanceColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ClientInfo client = (ClientInfo) element;
            return client.getInstance();
        }
    });
    TableViewerColumn processorColumn = new TableViewerColumn(this, SWT.LEFT);
    processorColumn.getColumn().setText(COL_PROCESSOR);
    processorColumn.getColumn().setWidth(100);
    processorColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ClientInfo client = (ClientInfo) element;
            return client.getProcessorName();
        }
    });
    // prevent resize to 0
    for (TableColumn column : getTable().getColumns()) {
        column.addControlListener(new ControlListener() {

            @Override
            public void controlMoved(ControlEvent e) {
            }

            @Override
            public void controlResized(ControlEvent e) {
                if (column.getWidth() < 5) {
                    column.setWidth(5);
                }
            }
        });
    }
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ControlListener(org.eclipse.swt.events.ControlListener) ClientInfo(org.yamcs.protobuf.YamcsManagement.ClientInfo) ControlEvent(org.eclipse.swt.events.ControlEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

ControlEvent (org.eclipse.swt.events.ControlEvent)62 ControlListener (org.eclipse.swt.events.ControlListener)34 ControlAdapter (org.eclipse.swt.events.ControlAdapter)28 SelectionEvent (org.eclipse.swt.events.SelectionEvent)20 GridData (org.eclipse.swt.layout.GridData)20 Composite (org.eclipse.swt.widgets.Composite)20 GridLayout (org.eclipse.swt.layout.GridLayout)15 Point (org.eclipse.swt.graphics.Point)14 DisposeEvent (org.eclipse.swt.events.DisposeEvent)11 FocusEvent (org.eclipse.swt.events.FocusEvent)11 Control (org.eclipse.swt.widgets.Control)11 Event (org.eclipse.swt.widgets.Event)11 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)10 DisposeListener (org.eclipse.swt.events.DisposeListener)10 ModifyEvent (org.eclipse.swt.events.ModifyEvent)10 MouseEvent (org.eclipse.swt.events.MouseEvent)10 Listener (org.eclipse.swt.widgets.Listener)10 Shell (org.eclipse.swt.widgets.Shell)10 TableColumn (org.eclipse.swt.widgets.TableColumn)10 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)9