Search in sources :

Example 1 with ViewerColumnController

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

the class FilterValueEditDialog method createMultiValueSelector.

private void createMultiValueSelector(Composite composite) {
    table = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.MULTI | SWT.CHECK | SWT.FULL_SELECTION);
    table.getTable().setLinesVisible(true);
    table.getTable().setHeaderVisible(true);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    gd.heightHint = 300;
    table.getTable().setLayoutData(gd);
    table.setContentProvider(new ListContentProvider());
    ViewerColumnController columnController = new ViewerColumnController(getClass().getName(), table);
    columnController.addColumn("Value", "Value", SWT.LEFT, true, true, new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return attr.getValueHandler().getValueDisplayString(attr, ((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();
    MenuManager menuMgr = new MenuManager();
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            UIUtils.fillDefaultTableContextMenu(manager, table.getTable());
            manager.add(new Separator());
            manager.add(new Action("Select &All") {

                @Override
                public void run() {
                    for (DBDLabelValuePair row : getMultiValues()) {
                        table.setChecked(row, true);
                    }
                }
            });
            manager.add(new Action("Select &None") {

                @Override
                public void run() {
                    for (DBDLabelValuePair row : getMultiValues()) {
                        table.setChecked(row, false);
                    }
                }
            });
        }
    });
    menuMgr.setRemoveAllWhenShown(true);
    table.getTable().setMenu(menuMgr.createContextMenu(table.getTable()));
    if (attr.getDataKind() == DBPDataKind.STRING) {
        // Create filter text
        final Text valueFilterText = new Text(composite, SWT.BORDER);
        valueFilterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        valueFilterText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                filterPattern = valueFilterText.getText();
                if (filterPattern.isEmpty()) {
                    filterPattern = null;
                }
                loadValues();
            }
        });
    }
    filterPattern = null;
    loadValues();
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) ModifyListener(org.eclipse.swt.events.ModifyListener) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) DBDLabelValuePair(org.jkiss.dbeaver.model.data.DBDLabelValuePair)

Example 2 with ViewerColumnController

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

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 && (objectList == null) || (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())) {
                        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
            List<ObjectPropertyDescriptor> allProps = ObjectAttributeDescriptor.extractAnnotations(getListPropertySource(), classList, propertyFilter);
            if (reload) {
                clearListData();
                columnController = new ViewerColumnController(getListConfigId(classList), getItemsViewer());
            }
            // Create columns from classes' annotations
            for (ObjectPropertyDescriptor prop : allProps) {
                if (!getListPropertySource().hasProperty(prop)) {
                    getListPropertySource().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<OBJECT_TYPE>() : 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()));
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) ProgressPageControl(org.jkiss.dbeaver.ui.controls.ProgressPageControl) List(java.util.List)

Example 3 with ViewerColumnController

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

the class OracleCompilerDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    GridData gd;
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    {
        Composite unitsGroup = new Composite(composite, SWT.NONE);
        gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = 250;
        gd.heightHint = 200;
        gd.verticalIndent = 0;
        gd.horizontalIndent = 0;
        unitsGroup.setLayoutData(gd);
        unitsGroup.setLayout(new GridLayout(1, false));
        unitTable = new TableViewer(unitsGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
        {
            final Table table = unitTable.getTable();
            table.setLayoutData(new GridData(GridData.FILL_BOTH));
            table.setLinesVisible(true);
            table.setHeaderVisible(true);
        }
        ViewerColumnController columnController = new ViewerColumnController("OracleCompilerDialog", unitTable);
        columnController.addColumn(OracleMessages.views_oracle_compiler_dialog_column_name, null, SWT.NONE, true, true, new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DBSObject unit = (DBSObject) cell.getElement();
                final DBNDatabaseNode node = DBeaverCore.getInstance().getNavigatorModel().getNodeByObject(unit);
                if (node != null) {
                    cell.setText(node.getNodeName());
                    cell.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
                } else {
                    cell.setText(unit.toString());
                }
            }
        });
        columnController.addColumn(OracleMessages.views_oracle_compiler_dialog_column_type, null, SWT.NONE, true, true, new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DBSObject unit = (DBSObject) cell.getElement();
                final DBNDatabaseNode node = DBeaverCore.getInstance().getNavigatorModel().getNodeByObject(unit);
                if (node != null) {
                    cell.setText(node.getNodeType());
                } else {
                    //$NON-NLS-1$
                    cell.setText("???");
                }
            }
        });
        columnController.createColumns();
        unitTable.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                getButton(COMPILE_ID).setEnabled(!selection.isEmpty());
            }
        });
        unitTable.addDoubleClickListener(new IDoubleClickListener() {

            @Override
            public void doubleClick(DoubleClickEvent event) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                if (!selection.isEmpty()) {
                    OracleSourceObject unit = (OracleSourceObject) selection.getFirstElement();
                    NavigatorHandlerObjectOpen.openEntityEditor(unit);
                }
            }
        });
        unitTable.setContentProvider(new ListContentProvider());
        unitTable.setInput(compileUnits);
    }
    {
        Composite infoGroup = new Composite(composite, SWT.NONE);
        gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = 400;
        gd.heightHint = 200;
        gd.verticalIndent = 0;
        gd.horizontalIndent = 0;
        infoGroup.setLayoutData(gd);
        infoGroup.setLayout(new GridLayout(1, false));
        compileLog = new ObjectCompilerLogViewer(infoGroup, true);
    }
    return composite;
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) GridLayout(org.eclipse.swt.layout.GridLayout) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) GridData(org.eclipse.swt.layout.GridData) ObjectCompilerLogViewer(org.jkiss.dbeaver.ui.controls.ObjectCompilerLogViewer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)

Example 4 with ViewerColumnController

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

the class OracleCompilerDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    GridData gd;
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    {
        Composite unitsGroup = new Composite(composite, SWT.NONE);
        gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = 250;
        gd.heightHint = 200;
        gd.verticalIndent = 0;
        gd.horizontalIndent = 0;
        unitsGroup.setLayoutData(gd);
        unitsGroup.setLayout(new GridLayout(1, false));
        unitTable = new TableViewer(unitsGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
        {
            final Table table = unitTable.getTable();
            table.setLayoutData(new GridData(GridData.FILL_BOTH));
            table.setLinesVisible(true);
            table.setHeaderVisible(true);
        }
        ViewerColumnController columnController = new ViewerColumnController("OracleCompilerDialog", unitTable);
        columnController.addColumn(OracleMessages.views_oracle_compiler_dialog_column_name, null, SWT.NONE, true, true, new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DBSObject unit = (DBSObject) cell.getElement();
                final DBNDatabaseNode node = NavigatorUtils.getNodeByObject(unit);
                if (node != null) {
                    cell.setText(node.getNodeName());
                    cell.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
                } else {
                    cell.setText(unit.toString());
                }
            }
        });
        columnController.addColumn(OracleMessages.views_oracle_compiler_dialog_column_type, null, SWT.NONE, true, true, new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DBSObject unit = (DBSObject) cell.getElement();
                final DBNDatabaseNode node = NavigatorUtils.getNodeByObject(unit);
                if (node != null) {
                    cell.setText(node.getNodeType());
                } else {
                    // $NON-NLS-1$
                    cell.setText("???");
                }
            }
        });
        columnController.createColumns();
        unitTable.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                getButton(COMPILE_ID).setEnabled(!selection.isEmpty());
            }
        });
        unitTable.addDoubleClickListener(new IDoubleClickListener() {

            @Override
            public void doubleClick(DoubleClickEvent event) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                if (!selection.isEmpty()) {
                    OracleSourceObject unit = (OracleSourceObject) selection.getFirstElement();
                    NavigatorHandlerObjectOpen.openEntityEditor(unit);
                }
            }
        });
        unitTable.setContentProvider(new ListContentProvider());
        unitTable.setInput(compileUnits);
    }
    {
        Composite infoGroup = new Composite(composite, SWT.NONE);
        gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = 400;
        gd.heightHint = 200;
        gd.verticalIndent = 0;
        gd.horizontalIndent = 0;
        infoGroup.setLayoutData(gd);
        infoGroup.setLayout(new GridLayout(1, false));
        compileLog = new ObjectCompilerLogViewer(infoGroup, true);
    }
    return composite;
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) GridLayout(org.eclipse.swt.layout.GridLayout) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) GridData(org.eclipse.swt.layout.GridData) ObjectCompilerLogViewer(org.jkiss.dbeaver.ui.controls.ObjectCompilerLogViewer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)

Example 5 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.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

ViewerColumnController (org.jkiss.dbeaver.ui.controls.ViewerColumnController)20 GridData (org.eclipse.swt.layout.GridData)9 List (java.util.List)5 DBDLabelValuePair (org.jkiss.dbeaver.model.data.DBDLabelValuePair)5 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Collection (java.util.Collection)4 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)4 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)4 ListContentProvider (org.jkiss.dbeaver.ui.controls.ListContentProvider)4 Pattern (java.util.regex.Pattern)3 Action (org.eclipse.jface.action.Action)3 MenuEvent (org.eclipse.swt.events.MenuEvent)3 MenuListener (org.eclipse.swt.events.MenuListener)3 Color (org.eclipse.swt.graphics.Color)3 Image (org.eclipse.swt.graphics.Image)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 TableItem (org.eclipse.swt.widgets.TableItem)3 SimpleDateFormat (java.text.SimpleDateFormat)2 java.util (java.util)2