Search in sources :

Example 1 with ILazyLabelProvider

use of org.jkiss.dbeaver.ui.ILazyLabelProvider 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)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 Point (org.eclipse.swt.graphics.Point)1 ILazyLabelProvider (org.jkiss.dbeaver.ui.ILazyLabelProvider)1