Search in sources :

Example 11 with ControlAdapter

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

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

use of org.eclipse.swt.events.ControlAdapter in project translationstudio8 by heartsome.

the class QAResultViewPart method createTable.

public void createTable() {
    table = new KTable(parent, SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWTX.FILL_WITH_LASTCOL | SWT.WRAP);
    tableModel = new KtableModel();
    table.setModel(tableModel);
    table.setLayoutData(new GridData(GridData.FILL_BOTH));
    table.setColorRightBorder(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    table.setColorLeftBorder(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    table.setColorTopBorder(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    table.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            locationRow();
        }
    });
    table.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.keyCode == QAConstant.QA_CENTERKEY_1 || e.keyCode == QAConstant.QA_CENTERKEY_2) {
                locationRow();
            }
        }
    });
    table.addCellResizeListener(new KTableCellResizeListener() {

        public void rowResized(int arg0, int arg1) {
            tableModel.textRenderer.clearRowHeiMap();
            table.redraw();
        }

        public void columnResized(int arg0, int arg1) {
            tableModel.textRenderer.clearRowHeiMap();
            table.redraw();
        }
    });
    table.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            tableModel.textRenderer.clearRowHeiMap();
            table.redraw();
        }
    });
    table.addMouseWheelListener(new MouseWheelListener() {

        public void mouseScrolled(MouseEvent e) {
            tableModel.textRenderer.clearRowHeiMap();
            table.redraw();
        }
    });
    createPropMenu();
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) KTableCellResizeListener(de.kupzog.ktable.KTableCellResizeListener) ControlAdapter(org.eclipse.swt.events.ControlAdapter) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MouseWheelListener(org.eclipse.swt.events.MouseWheelListener) KTable(de.kupzog.ktable.KTable) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) GridData(org.eclipse.swt.layout.GridData) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 14 with ControlAdapter

use of org.eclipse.swt.events.ControlAdapter in project translationstudio8 by heartsome.

the class TerminologyViewPart method createPartControl.

/**
	 * 创建控件。
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    this.parent = parent;
    createAction();
    GridLayout parentGl = new GridLayout(1, false);
    parentGl.marginWidth = 0;
    parentGl.marginHeight = 0;
    parent.setLayout(parentGl);
    final Composite contentPanel = new Composite(parent, SWT.NONE);
    GridLayout secondPageCompositeGl = new GridLayout(1, false);
    secondPageCompositeGl.marginBottom = -1;
    secondPageCompositeGl.marginLeft = -1;
    secondPageCompositeGl.marginRight = -1;
    secondPageCompositeGl.marginTop = -1;
    secondPageCompositeGl.marginWidth = 0;
    secondPageCompositeGl.marginHeight = 0;
    contentPanel.setLayout(secondPageCompositeGl);
    contentPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    contentPanel.setLayout(secondPageCompositeGl);
    contentPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    // firstPageComposite = new Composite(contentPanel, SWT.NONE);
    // firstPageComposite.setLayout(new GridLayout(1, false));
    // secondPageComposite = new Composite(contentPanel, SWT.NONE);
    // GridLayout secondPageCompositeGl = new GridLayout(1, false);
    // secondPageCompositeGl.marginBottom = -1;
    // secondPageCompositeGl.marginLeft = -1;
    // secondPageCompositeGl.marginRight = -1;
    // secondPageCompositeGl.marginTop = -1;
    // secondPageCompositeGl.marginWidth = 0;
    // secondPageCompositeGl.marginHeight = 0;
    // secondPageComposite.setLayout(secondPageCompositeGl);
    // secondPageComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    gridTable = new Grid(contentPanel, SWT.BORDER | SWT.V_SCROLL);
    gridTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    gridTable.setHeaderVisible(true);
    gridTable.setAutoHeight(true);
    gridTable.setRowsResizeable(true);
    gridTable.setData("selectedBgColor", selectedBgColor);
    final GridColumn idItem = new GridColumn(gridTable, SWT.NONE);
    idItem.setText(Messages.getString("view.TerminologyViewPart.idItem"));
    idColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    idColumnCellRenderer.setVerticalAlignment(SWT.CENTER);
    idItem.setCellRenderer(idColumnCellRenderer);
    idItem.setWordWrap(true);
    srcTableColumn = new GridColumn(gridTable, SWT.NONE);
    srcTableColumn.setText(Messages.getString("view.TerminologyViewPart.srcTableColumn"));
    srcColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    srcTableColumn.setCellRenderer(srcColumnCellRenderer);
    srcTableColumn.setWordWrap(true);
    tgtTableColumn = new GridColumn(gridTable, SWT.NONE);
    tgtTableColumn.setText(Messages.getString("view.TerminologyViewPart.tgtTableColumn"));
    tgtColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    tgtTableColumn.setCellRenderer(tgtColumnCellRenderer);
    tgtTableColumn.setWordWrap(true);
    final GridColumn propertyColumn = new GridColumn(gridTable, SWT.NONE);
    propertyColumn.setText(Messages.getString("view.TerminologyViewPart.propertyColumn"));
    propColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    propertyColumn.setCellRenderer(propColumnCellRenderer);
    propertyColumn.setWordWrap(true);
    copyEnable = new GridCopyEnable(gridTable);
    srcColumnCellRenderer.setCopyEnable(copyEnable);
    tgtColumnCellRenderer.setCopyEnable(copyEnable);
    // 设置列宽按比例
    contentPanel.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            Rectangle area = contentPanel.getClientArea();
            Point preferredSize = gridTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            // - 2 * gridTable.getBorderWidth();
            int width = area.width;
            if (preferredSize.y > area.height + gridTable.getHeaderHeight()) {
                Point vBarSize = gridTable.getVerticalBar().getSize();
                width -= vBarSize.x;
            }
            gridTable.setSize(area.width, area.height);
            width -= 45;
            idItem.setWidth(45);
            srcTableColumn.setWidth((int) (width * 0.4));
            tgtTableColumn.setWidth((int) (width * 0.4));
            propertyColumn.setWidth((int) (width * 0.2));
        }
    });
    Composite statusComposite = new Composite(contentPanel, SWT.NONE);
    GridLayout statusComptGridLayout = new GridLayout(2, false);
    statusComptGridLayout.marginBottom = -1;
    statusComptGridLayout.marginLeft = -1;
    statusComptGridLayout.marginRight = -1;
    statusComptGridLayout.marginTop = -1;
    statusComptGridLayout.marginWidth = 0;
    statusComptGridLayout.marginHeight = 0;
    statusComposite.setLayout(statusComptGridLayout);
    statusComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    tipLabel = new CLabel(statusComposite, SWT.NONE);
    tipLabel.setAlignment(SWT.LEFT);
    CLabel label = new CLabel(statusComposite, SWT.None);
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd.heightHint = 20;
    label.setLayoutData(gd);
    gridTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectItem();
        }
    });
    gridTable.addListener(SWT.MouseDoubleClick, new Listener() {

        public void handleEvent(Event event) {
            firstAction.run();
        }
    });
    initHookMenu();
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) ISelectionListener(org.eclipse.ui.ISelectionListener) Listener(org.eclipse.swt.widgets.Listener) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) Grid(org.eclipse.nebula.widgets.grid.Grid) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GridCopyEnable(net.heartsome.cat.ts.ui.grid.GridCopyEnable) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 15 with ControlAdapter

use of org.eclipse.swt.events.ControlAdapter in project dbeaver by serge-rider.

the class ViewerColumnController method createVisibleColumns.

private void createVisibleColumns() {
    boolean hasLazyColumns = false;
    List<ColumnInfo> visibleColumns = getVisibleColumns();
    for (int i = 0; i < visibleColumns.size(); i++) {
        final ColumnInfo columnInfo = visibleColumns.get(i);
        columnInfo.order = i;
        final Item colItem;
        ViewerColumn viewerColumn;
        if (viewer instanceof TreeViewer) {
            final TreeViewerColumn item = new TreeViewerColumn((TreeViewer) viewer, columnInfo.style);
            viewerColumn = item;
            final TreeColumn column = item.getColumn();
            colItem = column;
            column.setText(columnInfo.name);
            column.setMoveable(true);
            column.setWidth(columnInfo.width);
            if (!CommonUtils.isEmpty(columnInfo.description)) {
                column.setToolTipText(columnInfo.description);
            }
            column.addControlListener(new ControlAdapter() {

                @Override
                public void controlResized(ControlEvent e) {
                    columnInfo.width = column.getWidth();
                    saveColumnConfig();
                }

                @Override
                public void controlMoved(ControlEvent e) {
                    if (!isInitializing && e.getSource() instanceof TreeColumn) {
                        updateColumnOrder(column, column.getParent().getColumnOrder());
                    }
                }
            });
            columnInfo.column = column;
        } else if (viewer instanceof TableViewer) {
            final TableViewerColumn item = new TableViewerColumn((TableViewer) viewer, columnInfo.style);
            viewerColumn = item;
            final TableColumn column = item.getColumn();
            colItem = column;
            column.setText(columnInfo.name);
            column.setMoveable(true);
            column.setWidth(columnInfo.width);
            if (!CommonUtils.isEmpty(columnInfo.description)) {
                column.setToolTipText(columnInfo.description);
            }
            column.addControlListener(new ControlAdapter() {

                @Override
                public void controlResized(ControlEvent e) {
                    columnInfo.width = column.getWidth();
                    saveColumnConfig();
                }

                @Override
                public void controlMoved(ControlEvent e) {
                    if (!isInitializing && e.getSource() instanceof TableColumn) {
                        updateColumnOrder(column, column.getParent().getColumnOrder());
                    }
                }
            });
            columnInfo.column = column;
        } else {
            continue;
        }
        viewerColumn.setLabelProvider(columnInfo.labelProvider);
        viewerColumn.setEditingSupport(columnInfo.editingSupport);
        colItem.setData(columnInfo);
        if (columnInfo.labelProvider instanceof ILazyLabelProvider) {
            hasLazyColumns = true;
        } else if (columnInfo.labelProvider instanceof ILabelProvider) {
            columnInfo.sortListener = new SortListener(columnInfo);
            columnInfo.column.addListener(SWT.Selection, columnInfo.sortListener);
        }
    }
    if (hasLazyColumns) {
        viewer.getControl().addListener(SWT.PaintItem, new Listener() {

            public void handleEvent(Event event) {
                if (viewer instanceof TreeViewer) {
                    TreeColumn column = ((TreeViewer) viewer).getTree().getColumn(event.index);
                    if (((ColumnInfo) column.getData()).labelProvider instanceof ILazyLabelProvider && CommonUtils.isEmpty(((TreeItem) event.item).getText(event.index))) {
                        final String lazyText = ((ILazyLabelProvider) ((ColumnInfo) column.getData()).labelProvider).getLazyText(event.item.getData());
                        if (!CommonUtils.isEmpty(lazyText)) {
                            ((TreeItem) event.item).setText(event.index, lazyText);
                        }
                    }
                } else {
                    TableColumn column = ((TableViewer) viewer).getTable().getColumn(event.index);
                    if (((ColumnInfo) column.getData()).labelProvider instanceof ILazyLabelProvider && CommonUtils.isEmpty(((TableItem) event.item).getText(event.index))) {
                        final String lazyText = ((ILazyLabelProvider) ((ColumnInfo) column.getData()).labelProvider).getLazyText(event.item.getData());
                        if (!CommonUtils.isEmpty(lazyText)) {
                            ((TableItem) event.item).setText(event.index, lazyText);
                        }
                    }
                }
            }
        });
    }
}
Also used : ILazyLabelProvider(org.jkiss.dbeaver.ui.ILazyLabelProvider) ControlAdapter(org.eclipse.swt.events.ControlAdapter) Point(org.eclipse.swt.graphics.Point) ControlEvent(org.eclipse.swt.events.ControlEvent) ControlEvent(org.eclipse.swt.events.ControlEvent)

Aggregations

ControlAdapter (org.eclipse.swt.events.ControlAdapter)28 ControlEvent (org.eclipse.swt.events.ControlEvent)28 Composite (org.eclipse.swt.widgets.Composite)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)12 GridLayout (org.eclipse.swt.layout.GridLayout)11 Point (org.eclipse.swt.graphics.Point)9 GridData (org.eclipse.swt.layout.GridData)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 Rectangle (org.eclipse.swt.graphics.Rectangle)7 TableColumn (org.eclipse.swt.widgets.TableColumn)7 ModifyEvent (org.eclipse.swt.events.ModifyEvent)6 Button (org.eclipse.swt.widgets.Button)6 ModifyListener (org.eclipse.swt.events.ModifyListener)5 FillLayout (org.eclipse.swt.layout.FillLayout)5 Label (org.eclipse.swt.widgets.Label)5 Table (org.eclipse.swt.widgets.Table)5 SashForm (org.eclipse.swt.custom.SashForm)4 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)4 Event (org.eclipse.swt.widgets.Event)4 Listener (org.eclipse.swt.widgets.Listener)4