Search in sources :

Example 1 with LazyLabelProvider

use of org.jkiss.dbeaver.ui.LazyLabelProvider 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.addColumn("Name", "Resource name", SWT.LEFT, true, true, new TreeColumnViewerLabelProvider(new LabelProvider() {

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

        @Override
        public Image getImage(Object element) {
            return mainLabelProvider.getImage(element);
        }
    }));
    columnController.addColumn("DataSource", "Datasource(s) associated with resource", SWT.LEFT, true, false, new TreeColumnViewerLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            DBNNode node = (DBNNode) element;
            if (node instanceof DBNDatabaseNode) {
                return ((DBNDatabaseNode) node).getDataSourceContainer().getName();
            } else if (node instanceof DBNResource) {
                Collection<DBPDataSourceContainer> containers = ((DBNResource) node).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;
        }
    }));
    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, new TreeColumnViewerLabelProvider(new LabelProvider() {

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

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

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

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

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 Date (java.util.Date)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IResource (org.eclipse.core.resources.IResource)1 Color (org.eclipse.swt.graphics.Color)1 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)1 LazyLabelProvider (org.jkiss.dbeaver.ui.LazyLabelProvider)1 ProgramInfo (org.jkiss.dbeaver.ui.ProgramInfo)1 ViewerColumnController (org.jkiss.dbeaver.ui.controls.ViewerColumnController)1