Search in sources :

Example 16 with ViewerColumnController

use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.

the class NavigatorUtils method createContextMenu.

public static MenuManager createContextMenu(final IWorkbenchSite workbenchSite, final Viewer viewer, final ISelectionProvider selectionProvider, final IMenuListener menuListener) {
    final Control control = viewer.getControl();
    final MenuManager menuMgr = new MenuManager();
    Menu menu = menuMgr.createContextMenu(control);
    menu.addMenuListener(new MenuListener() {

        @Override
        public void menuHidden(MenuEvent e) {
        }

        @Override
        public void menuShown(MenuEvent e) {
            Menu m = (Menu) e.widget;
            DBNNode node = getSelectedNode(viewer.getSelection());
            if (node != null && !node.isLocked() && node.allowsOpen()) {
                String commandID = NavigatorUtils.getNodeActionCommand(DBXTreeNodeHandler.Action.open, node, NavigatorCommands.CMD_OBJECT_OPEN);
                // Get contribution item from menu item and check it's ID
                try {
                    for (MenuItem item : m.getItems()) {
                        Object itemData = item.getData();
                        if (itemData instanceof IContributionItem) {
                            String contribId = ((IContributionItem) itemData).getId();
                            if (contribId != null && contribId.equals(commandID)) {
                                m.setDefaultItem(item);
                            }
                        }
                    }
                } catch (Exception ex) {
                    log.debug(ex);
                }
            }
        }
    });
    menuMgr.addMenuListener(manager -> {
        ViewerColumnController columnController = ViewerColumnController.getFromControl(control);
        if (columnController != null && columnController.isClickOnHeader()) {
            columnController.fillConfigMenu(manager);
            manager.add(new Separator());
            return;
        }
        manager.add(new Separator());
        addStandardMenuItem(workbenchSite, manager, selectionProvider);
        if (menuListener != null) {
            menuListener.menuAboutToShow(manager);
        }
    });
    menuMgr.setRemoveAllWhenShown(true);
    control.setMenu(menu);
    return menuMgr;
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) MenuListener(org.eclipse.swt.events.MenuListener) DBCException(org.jkiss.dbeaver.model.exec.DBCException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 17 with ViewerColumnController

use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.

the class DatabaseTasksView method createTaskRunTable.

private void createTaskRunTable(Composite parent) {
    taskRunViewer = DialogUtils.createFilteredTree(parent, SWT.SINGLE | SWT.FULL_SELECTION, new NamedObjectPatternFilter(), TaskUIMessages.db_tasks_view_filtered_tree_text_error_message);
    Tree taskrunTree = taskRunViewer.getTree();
    taskrunTree.setHeaderVisible(true);
    taskrunTree.setLayoutData(new GridData(GridData.FILL_BOTH));
    taskRunColumnController = new ViewerColumnController("taskruns", taskRunViewer);
    taskRunColumnController.addColumn(TaskUIMessages.db_tasks_view_column_controller_add_name_time, TaskUIMessages.db_tasks_view_column_controller_add_descr_start_time, SWT.LEFT, true, true, new TaskRunLabelProvider() {

        @Override
        protected void update(ViewerCell cell, DBTTaskRun taskRun) {
            cell.setText(tasksTree.getDateFormat().format(taskRun.getStartTime()));
        }
    });
    taskRunColumnController.addColumn(TaskUIMessages.db_tasks_view_column_controller_add_name_duration, TaskUIMessages.db_tasks_view_column_controller_add_descr_task_duration, SWT.LEFT, true, false, true, null, new TaskRunLabelProviderEx() {

        @Override
        public String getText(Object element, boolean forUI) {
            DBTTaskRun taskRun = (DBTTaskRun) element;
            return forUI ? RuntimeUtils.formatExecutionTime(taskRun.getRunDuration()) : String.valueOf(taskRun.getRunDuration());
        }

        @Override
        protected void update(ViewerCell cell, DBTTaskRun taskRun) {
            cell.setText(RuntimeUtils.formatExecutionTime(taskRun.getRunDuration()));
        }
    }, null);
    taskRunColumnController.addColumn(TaskUIMessages.db_tasks_view_column_controller_add_name_result, TaskUIMessages.db_tasks_view_column_controller_add_descr_task_result, SWT.LEFT, true, false, new TaskRunLabelProvider() {

        @Override
        protected void update(ViewerCell cell, DBTTaskRun taskRun) {
            if (taskRun.isRunSuccess()) {
                cell.setText(TaskUIMessages.db_tasks_view_cell_text_success);
            } else {
                cell.setText(CommonUtils.notEmpty(taskRun.getErrorMessage()));
            }
        }
    });
    taskRunColumnController.setForceAutoSize(true);
    taskRunColumnController.createColumns(true);
    taskRunViewer.setContentProvider(new TreeRunContentProvider());
    MenuManager menuMgr = createTaskRunContextMenu(taskRunViewer);
    getSite().registerContextMenu(menuMgr, taskRunViewer);
    taskRunViewer.addDoubleClickListener(event -> new ViewRunLogAction().run());
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) Tree(org.eclipse.swt.widgets.Tree)

Example 18 with ViewerColumnController

use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.

the class ObjectListControl method setListData.

protected void setListData(Collection<OBJECT_TYPE> items, boolean append) {
    final Control itemsControl = itemsViewer.getControl();
    if (itemsControl.isDisposed()) {
        return;
    }
    itemsControl.setRedraw(false);
    try {
        final boolean reload = !append && (CommonUtils.isEmpty(objectList)) || (columnController == null);
        {
            // Collect list of items' classes
            final List<Class<?>> classList = new ArrayList<>();
            Class<?>[] baseTypes = getListBaseTypes(items);
            if (!ArrayUtils.isEmpty(baseTypes)) {
                Collections.addAll(classList, baseTypes);
            }
            if (!CommonUtils.isEmpty(items)) {
                for (OBJECT_TYPE item : items) {
                    Object object = getObjectValue(item);
                    if (object != null && !classList.contains(object.getClass())) {
                        // and we need to show "Name" instead of particular name props
                        for (int i = 0; i < classList.size(); i++) {
                            Class<?> c = classList.get(i);
                            if (!c.isInterface() && c.isAssignableFrom(object.getClass())) {
                                classList.remove(i);
                            } else {
                                i++;
                            }
                        }
                        classList.add(object.getClass());
                    }
                    if (renderer.isTree()) {
                        Map<OBJECT_TYPE, Boolean> collectedSet = new IdentityHashMap<>();
                        collectItemClasses(item, classList, collectedSet);
                    }
                }
            }
            IPropertyFilter propertyFilter = new DataSourcePropertyFilter(ObjectListControl.this instanceof IDataSourceContainerProvider ? ((IDataSourceContainerProvider) ObjectListControl.this).getDataSourceContainer() : null);
            // Collect all properties
            PropertySourceAbstract propertySource = getListPropertySource();
            List<ObjectPropertyDescriptor> allProps = ObjectAttributeDescriptor.extractAnnotations(propertySource, classList, propertyFilter);
            if (!CommonUtils.isEmpty(items)) {
                // Remove hidden properties (we need to check them against all items)
                try {
                    allProps.removeIf(p -> {
                        for (OBJECT_TYPE item : items) {
                            Object objectValue = getObjectValue(item);
                            if (p.isPropertyVisible(objectValue, objectValue)) {
                                return false;
                            }
                        }
                        return true;
                    });
                } catch (Throwable e) {
                    log.debug(e);
                }
            }
            if (reload) {
                clearListData();
                columnController = new ViewerColumnController<>(getListConfigId(classList), getItemsViewer());
            }
            // Create columns from classes' annotations
            for (ObjectPropertyDescriptor prop : allProps) {
                if (!propertySource.hasProperty(prop)) {
                    if (prop.isOptional()) {
                        // Check whether at least one itme has this property
                        boolean propHasValue = false;
                        if (!CommonUtils.isEmpty(items)) {
                            for (OBJECT_TYPE item : items) {
                                try {
                                    Object propValue = prop.readValue(getObjectValue(item), null, true);
                                    if (propValue != null) {
                                        propHasValue = true;
                                        break;
                                    }
                                } catch (Throwable e) {
                                // Just ignore this
                                }
                            }
                        }
                        if (!propHasValue) {
                            continue;
                        }
                    }
                    propertySource.addProperty(prop);
                    createColumn(prop);
                }
            }
        }
        if (itemsControl.isDisposed()) {
            return;
        }
        if (reload) {
            columnController.createColumns(false);
        }
        if (reload || objectList.isEmpty()) {
            // Set viewer content
            objectList = CommonUtils.isEmpty(items) ? new ArrayList<>() : new ArrayList<>(items);
            // Pack columns
            sampleItems = true;
            try {
                List<OBJECT_TYPE> sampleList;
                if (objectList.size() > 200) {
                    sampleList = objectList.subList(0, 100);
                } else {
                    sampleList = objectList;
                }
                itemsViewer.setInput(sampleList);
                if (renderer.isTree()) {
                    ((TreeViewer) itemsViewer).expandToLevel(4);
                }
                if (reload) {
                    columnController.repackColumns();
                }
            } finally {
                sampleItems = false;
            }
            // Set real content
            itemsViewer.setInput(objectList);
        } else if (items != null) {
            if (append) {
                // Simply append new list to the tail
                for (OBJECT_TYPE newObject : items) {
                    if (!objectList.contains(newObject)) {
                        objectList.add(newObject);
                    }
                }
            } else {
                // Update object list
                if (!objectList.equals(items)) {
                    int newListSize = items.size();
                    int itemIndex = 0;
                    for (OBJECT_TYPE newObject : items) {
                        if (itemIndex >= objectList.size()) {
                            // Add to tail
                            objectList.add(itemIndex, newObject);
                        } else {
                            OBJECT_TYPE oldObject = objectList.get(itemIndex);
                            if (!CommonUtils.equalObjects(oldObject, newObject)) {
                                // Replace old object
                                objectList.set(itemIndex, newObject);
                            }
                        }
                        itemIndex++;
                    }
                    while (objectList.size() > newListSize) {
                        objectList.remove(objectList.size() - 1);
                    }
                }
            }
            itemsViewer.refresh();
        }
    } finally {
        itemsControl.setRedraw(true);
    }
    setInfo(getItemsLoadMessage(objectList.size()));
    if (IS_MACOS_BIG_SUR) {
        // [#10162]
        itemsControl.redraw();
    }
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) java.util(java.util) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) Image(org.eclipse.swt.graphics.Image) org.jkiss.dbeaver.runtime.properties(org.jkiss.dbeaver.runtime.properties) Nullable(org.jkiss.code.Nullable) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBPImage(org.jkiss.dbeaver.model.DBPImage) ProgressPageControl(org.jkiss.dbeaver.ui.controls.ProgressPageControl) NotNull(org.jkiss.code.NotNull) IStatus(org.eclipse.core.runtime.IStatus) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) DBDDisplayFormat(org.jkiss.dbeaver.model.data.DBDDisplayFormat) ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) GridData(org.eclipse.swt.layout.GridData) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) GeneralUtils(org.jkiss.dbeaver.utils.GeneralUtils) CommonUtils(org.jkiss.utils.CommonUtils) PatternSyntaxException(java.util.regex.PatternSyntaxException) Job(org.eclipse.core.runtime.jobs.Job) NLS(org.eclipse.osgi.util.NLS) DBValueFormatting(org.jkiss.dbeaver.model.DBValueFormatting) IContributionManager(org.eclipse.jface.action.IContributionManager) org.eclipse.swt.widgets(org.eclipse.swt.widgets) Status(org.eclipse.core.runtime.Status) NavigatorPreferences(org.jkiss.dbeaver.ui.navigator.NavigatorPreferences) Action(org.eclipse.jface.action.Action) TraverseListener(org.eclipse.swt.events.TraverseListener) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) ArrayUtils(org.jkiss.utils.ArrayUtils) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) org.eclipse.jface.viewers(org.eclipse.jface.viewers) UINavigatorMessages(org.jkiss.dbeaver.ui.internal.UINavigatorMessages) InvocationTargetException(java.lang.reflect.InvocationTargetException) MouseEvent(org.eclipse.swt.events.MouseEvent) List(java.util.List) Color(org.eclipse.swt.graphics.Color) SWT(org.eclipse.swt.SWT) SQLUtils(org.jkiss.dbeaver.model.sql.SQLUtils) Pattern(java.util.regex.Pattern) ObjectViewerRenderer(org.jkiss.dbeaver.ui.controls.ObjectViewerRenderer) MouseAdapter(org.eclipse.swt.events.MouseAdapter) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) ProgressPageControl(org.jkiss.dbeaver.ui.controls.ProgressPageControl) List(java.util.List) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject)

Example 19 with ViewerColumnController

use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.

the class ProjectExplorerView method createColumns.

private void createColumns(final TreeViewer viewer) {
    final Color shadowColor = viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
    final ILabelProvider mainLabelProvider = (ILabelProvider) viewer.getLabelProvider();
    columnController = new ViewerColumnController("projectExplorer", viewer);
    columnController.setForceAutoSize(true);
    columnController.addColumn("Name", "Resource name", SWT.LEFT, true, true, new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return mainLabelProvider.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            Image image = mainLabelProvider.getImage(element);
            if (element instanceof DBNResource) {
                image = labelDecorator.decorateImage(image, element);
            }
            return image;
        }

        @Override
        public String getToolTipText(Object element) {
            if (mainLabelProvider instanceof IToolTipProvider) {
                return ((IToolTipProvider) mainLabelProvider).getToolTipText(element);
            }
            return null;
        }
    });
    columnController.addColumn("DataSource", "Datasource(s) associated with resource", SWT.LEFT, true, false, new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof DBNDatabaseNode) {
                return ((DBNDatabaseNode) element).getDataSourceContainer().getName();
            } else if (element instanceof DBNResource) {
                Collection<DBPDataSourceContainer> containers = ((DBNResource) element).getAssociatedDataSources();
                if (!CommonUtils.isEmpty(containers)) {
                    StringBuilder text = new StringBuilder();
                    for (DBPDataSourceContainer container : containers) {
                        if (text.length() > 0) {
                            text.append(", ");
                        }
                        text.append(container.getName());
                    }
                    return text.toString();
                }
            }
            return "";
        }

        @Override
        public Image getImage(Object element) {
            /*
                DBNNode node = (DBNNode) element;
                if (node instanceof DBNDatabaseNode) {
                    return DBeaverIcons.getImage(((DBNDatabaseNode) node).getDataSourceContainer().getDriver().getIcon());
                } else if (node instanceof DBNResource) {
                    Collection<DBPDataSourceContainer> containers = ((DBNResource) node).getAssociatedDataSources();
                    if (containers != null && containers.size() == 1) {
                        return DBeaverIcons.getImage((containers.iterator().next().getDriver().getIcon()));
                    }
                }
*/
            return null;
        }

        @Override
        public String getToolTipText(Object element) {
            if (element instanceof DBNResource) {
                Collection<DBPDataSourceContainer> containers = ((DBNResource) element).getAssociatedDataSources();
                if (!CommonUtils.isEmpty(containers)) {
                    StringBuilder text = new StringBuilder();
                    for (DBPDataSourceContainer container : containers) {
                        String description = container.getDescription();
                        if (CommonUtils.isEmpty(description)) {
                            description = container.getName();
                        }
                        if (!CommonUtils.isEmpty(description)) {
                            if (text.length() > 0) {
                                text.append(", ");
                            }
                            text.append(description);
                        }
                    }
                    return text.toString();
                }
            }
            return null;
        }
    });
    columnController.addColumn("Preview", "Script content preview", SWT.LEFT, false, false, new LazyLabelProvider(shadowColor) {

        @Override
        public String getLazyText(Object element) {
            if (element instanceof DBNNode) {
                return ((DBNNode) element).getNodeDescription();
            } else {
                return null;
            }
        }
    });
    columnController.addColumn("Size", "File size", SWT.LEFT, false, false, true, null, new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof DBNResource) {
                IResource resource = ((DBNResource) element).getResource();
                if (resource instanceof IFile) {
                    return String.valueOf(resource.getLocation().toFile().length());
                }
            }
            return "";
        }
    }, null);
    columnController.addColumn("Modified", "Time the file was last modified", SWT.LEFT, false, false, new ColumnLabelProvider() {

        private SimpleDateFormat sdf = new SimpleDateFormat(DBConstants.DEFAULT_TIMESTAMP_FORMAT);

        @Override
        public String getText(Object element) {
            if (element instanceof DBNResource) {
                IResource resource = ((DBNResource) element).getResource();
                if (resource instanceof IFile || resource instanceof IFolder) {
                    long lastModified = resource.getLocation().toFile().lastModified();
                    if (lastModified <= 0) {
                        return "";
                    }
                    return sdf.format(new Date(lastModified));
                }
            }
            return "";
        }
    });
    columnController.addColumn("Type", "Resource type", SWT.LEFT, false, false, new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof DBNResource) {
                IResource resource = ((DBNResource) element).getResource();
                ProgramInfo program = ProgramInfo.getProgram(resource);
                if (program != null) {
                    return program.getProgram().getName();
                }
            }
            return "";
        }
    });
    UIUtils.asyncExec(() -> columnController.createColumns(true));
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) IFile(org.eclipse.core.resources.IFile) Color(org.eclipse.swt.graphics.Color) Image(org.eclipse.swt.graphics.Image) Date(java.util.Date) Collection(java.util.Collection) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) SimpleDateFormat(java.text.SimpleDateFormat) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 20 with ViewerColumnController

use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.

the class FilterValueEditDialog method createMultiValueSelector.

private void createMultiValueSelector(Composite composite) {
    GridData layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.widthHint = 400;
    layoutData.heightHint = 300;
    handler.setupTable(composite, SWT.BORDER | SWT.MULTI | SWT.CHECK | SWT.FULL_SELECTION, true, true, layoutData);
    ViewerColumnController columnController = new ViewerColumnController(getClass().getName(), handler.getTableViewer());
    columnController.addColumn("Value", "Value", SWT.LEFT, true, true, new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return handler.getAttribute().getValueHandler().getValueDisplayString(handler.getAttribute(), ((DBDLabelValuePair) element).getValue(), DBDDisplayFormat.UI);
        }
    });
    columnController.addColumn("Description", "Row description (composed from dictionary columns)", SWT.LEFT, true, true, new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((DBDLabelValuePair) element).getLabel();
        }
    });
    columnController.createColumns(true);
    Action[] elements = new Action[] { new Action("Select &All") {

        @Override
        public void run() {
            for (TableItem item : handler.getTableViewer().getTable().getItems()) {
                item.setChecked(true);
            }
        }
    }, new Action("Select &None") {

        @Override
        public void run() {
            for (TableItem item : handler.getTableViewer().getTable().getItems()) {
                item.setChecked(false);
            }
        }
    } };
    handler.addContextMenu(elements);
    handler.addFilterTextbox(composite);
    handler.setFilterPattern(null);
    handler.loadValues(null);
    columnController.createColumns(true);
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Action(org.eclipse.jface.action.Action) TableItem(org.eclipse.swt.widgets.TableItem) GridData(org.eclipse.swt.layout.GridData) DBDLabelValuePair(org.jkiss.dbeaver.model.data.DBDLabelValuePair)

Aggregations

ViewerColumnController (org.jkiss.dbeaver.ui.controls.ViewerColumnController)28 GridData (org.eclipse.swt.layout.GridData)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 List (java.util.List)8 Image (org.eclipse.swt.graphics.Image)7 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)7 ListContentProvider (org.jkiss.dbeaver.ui.controls.ListContentProvider)7 Collection (java.util.Collection)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 DBException (org.jkiss.dbeaver.DBException)6 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)6 DBDLabelValuePair (org.jkiss.dbeaver.model.data.DBDLabelValuePair)6 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)6 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)5 Pattern (java.util.regex.Pattern)4 IStatus (org.eclipse.core.runtime.IStatus)4 Composite (org.eclipse.swt.widgets.Composite)4 Table (org.eclipse.swt.widgets.Table)4 OracleSourceObject (org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)4 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)4