Search in sources :

Example 31 with ControlEvent

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

Example 32 with ControlEvent

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

the class ViewerColumnController method recreateColumns.

private void recreateColumns(boolean pack) {
    final Control control = viewer.getControl();
    control.setRedraw(false);
    isInitializing = true;
    try {
        boolean needRefresh = false;
        for (ColumnInfo columnInfo : columns) {
            if (columnInfo.column != null) {
                columnInfo.column.dispose();
                columnInfo.column = null;
                needRefresh = true;
            }
        }
        createVisibleColumns();
        if (pack && !isAllSized()) {
            repackColumns();
            control.addControlListener(new ControlAdapter() {

                @Override
                public void controlResized(ControlEvent e) {
                    control.removeControlListener(this);
                    repackColumns();
                }
            });
        }
        if (needRefresh) {
            viewer.refresh();
            for (ColumnInfo columnInfo : getVisibleColumns()) {
                if (columnInfo.column instanceof TreeColumn) {
                    ((TreeColumn) columnInfo.column).pack();
                } else {
                    ((TableColumn) columnInfo.column).pack();
                }
            }
        }
    } finally {
        control.setRedraw(true);
        isInitializing = false;
    }
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 33 with ControlEvent

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

the class DataTransferPagePipes method createControl.

@Override
public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    consumersTable = new TableViewer(composite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    consumersTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    consumersTable.getTable().setLinesVisible(true);
    consumersTable.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void dispose() {
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof Collection) {
                return ((Collection<?>) inputElement).toArray();
            }
            return new Object[0];
        }
    });
    CellLabelProvider labelProvider = new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            TransferTarget element = (TransferTarget) cell.getElement();
            if (cell.getColumnIndex() == 0) {
                if (element.processor != null) {
                    cell.setImage(DBeaverIcons.getImage(element.processor.getIcon()));
                    cell.setText(element.processor.getName());
                } else {
                    cell.setImage(DBeaverIcons.getImage(element.consumer.getIcon()));
                    cell.setText(element.consumer.getName());
                }
            } else {
                if (element.processor != null) {
                    cell.setText(element.processor.getDescription());
                } else {
                    cell.setText(element.consumer.getDescription());
                }
            }
        }
    };
    {
        TableViewerColumn columnName = new TableViewerColumn(consumersTable, SWT.LEFT);
        columnName.setLabelProvider(labelProvider);
        columnName.getColumn().setText(CoreMessages.data_transfer_wizard_init_column_exported);
        TableViewerColumn columnDesc = new TableViewerColumn(consumersTable, SWT.LEFT);
        columnDesc.setLabelProvider(labelProvider);
        columnDesc.getColumn().setText(CoreMessages.data_transfer_wizard_init_column_description);
    }
    loadConsumers();
    consumersTable.getTable().addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final IStructuredSelection selection = (IStructuredSelection) consumersTable.getSelection();
            TransferTarget target;
            if (!selection.isEmpty()) {
                target = (TransferTarget) selection.getFirstElement();
            } else {
                target = null;
            }
            if (target == null) {
                getWizard().getSettings().selectConsumer(null, null);
            } else {
                getWizard().getSettings().selectConsumer(target.consumer, target.processor);
            }
            updatePageCompletion();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
            if (isPageComplete()) {
                getWizard().getContainer().showPage(getWizard().getNextPage(DataTransferPagePipes.this));
            }
        }
    });
    consumersTable.getTable().addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            UIUtils.packColumns(consumersTable.getTable());
            UIUtils.maxTableColumnsWidth(consumersTable.getTable());
            consumersTable.getTable().removeControlListener(this);
        }
    });
    setControl(composite);
    DataTransferNodeDescriptor consumer = getWizard().getSettings().getConsumer();
    DataTransferProcessorDescriptor processor = getWizard().getSettings().getProcessor();
    if (consumer != null) {
        Collection<TransferTarget> targets = (Collection<TransferTarget>) consumersTable.getInput();
        for (TransferTarget target : targets) {
            if (target.consumer == consumer && target.processor == processor) {
                consumersTable.setSelection(new StructuredSelection(target));
                break;
            }
        }
    }
    updatePageCompletion();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) DataTransferProcessorDescriptor(org.jkiss.dbeaver.registry.transfer.DataTransferProcessorDescriptor) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Collection(java.util.Collection) DataTransferNodeDescriptor(org.jkiss.dbeaver.registry.transfer.DataTransferNodeDescriptor) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 34 with ControlEvent

use of org.eclipse.swt.events.ControlEvent in project cubrid-manager by CUBRID.

the class ShardEnvStatusView method createPartControl.

/**
	 * Create the page content
	 * 
	 * @param parent
	 *            the parent composite
	 */
public void createPartControl(Composite parent) {
    composite = new Composite(parent, SWT.NONE);
    composite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    composite.setLayout(new FillLayout());
    createTable();
    // makeActions();
    composite.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent event) {
            updateTableLayout();
        }
    });
    new StatusUpdate().start();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 35 with ControlEvent

use of org.eclipse.swt.events.ControlEvent in project cubrid-manager by CUBRID.

the class BrokerEnvStatusView method createPartControl.

/**
	 * Create the page content
	 *
	 * @param parent the parent composite
	 */
public void createPartControl(Composite parent) {
    composite = new Composite(parent, SWT.NONE);
    composite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    composite.setLayout(new FillLayout());
    createTable();
    makeActions();
    composite.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent event) {
            updateTableLayout();
        }
    });
    new StatusUpdate().start();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) ControlEvent(org.eclipse.swt.events.ControlEvent)

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