Search in sources :

Example 21 with ViewerColumnController

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

the class GenericFilterValueEdit method loadMultiValueList.

private void loadMultiValueList(@NotNull Collection<DBDLabelValuePair> values, boolean mergeResultsWithData) {
    if (tableViewer == null || tableViewer.getControl() == null || tableViewer.getControl().isDisposed()) {
        return;
    }
    Pattern pattern = null;
    if (!CommonUtils.isEmpty(filterPattern) && attribute.getDataKind() == DBPDataKind.STRING) {
        pattern = Pattern.compile(SQLUtils.makeLikePattern("%" + filterPattern + "%"), Pattern.CASE_INSENSITIVE);
    }
    // Get all values from actual RSV data
    boolean hasNulls = false;
    Map<Object, DBDLabelValuePair> rowData = new HashMap<>();
    for (DBDLabelValuePair pair : values) {
        final DBDLabelValuePair oldLabel = rowData.get(pair.getValue());
        if (oldLabel != null) {
            // Duplicate label for single key - may happen in case of composite foreign keys
            String multiLabel = oldLabel.getLabel() + "," + pair.getLabel();
            if (multiLabel.length() > 200) {
                multiLabel = multiLabel.substring(0, 200) + MULTI_KEY_LABEL;
            }
            rowData.put(pair.getValue(), new DBDLabelValuePair(multiLabel, pair.getValue()));
        } else {
            rowData.put(pair.getValue(), pair);
        }
    }
    if (mergeResultsWithData) {
        // Add values from fetched rows
        for (ResultSetRow row : viewer.getModel().getAllRows()) {
            Object cellValue = viewer.getModel().getCellValue(attribute, row);
            if (DBUtils.isNullValue(cellValue)) {
                hasNulls = true;
                continue;
            }
            if (!keyPresents(rowData, cellValue)) {
                String itemString = attribute.getValueHandler().getValueDisplayString(attribute, cellValue, DBDDisplayFormat.UI);
                rowData.put(cellValue, new DBDLabelValuePair(itemString, cellValue));
            }
        }
    }
    List<DBDLabelValuePair> sortedList = new ArrayList<>(rowData.values());
    if (pattern != null) {
        for (Iterator<DBDLabelValuePair> iter = sortedList.iterator(); iter.hasNext(); ) {
            final DBDLabelValuePair valuePair = iter.next();
            String itemString = attribute.getValueHandler().getValueDisplayString(attribute, valuePair.getValue(), DBDDisplayFormat.UI);
            if (!pattern.matcher(itemString).matches() && (valuePair.getLabel() == null || !pattern.matcher(valuePair.getLabel()).matches())) {
                iter.remove();
            }
        }
    } else if (filterPattern != null && attribute.getDataKind() == DBPDataKind.NUMERIC) {
        // Filter numeric values
        double minValue = CommonUtils.toDouble(filterPattern);
        for (Iterator<DBDLabelValuePair> iter = sortedList.iterator(); iter.hasNext(); ) {
            final DBDLabelValuePair valuePair = iter.next();
            String itemString = attribute.getValueHandler().getValueDisplayString(attribute, valuePair.getValue(), DBDDisplayFormat.EDIT);
            double itemValue = CommonUtils.toDouble(itemString);
            if (itemValue < minValue) {
                iter.remove();
            }
        }
    }
    try {
        Collections.sort(sortedList);
    } catch (Exception e) {
        // FIXME: This may happen in some crazy cases -
        // FIXME: error "Comparison method violates its general contract!" happens in case of long strings sorting
        // FIXME: Test on sakila.film.description
        log.error("Error sorting value collection", e);
    }
    if (hasNulls) {
        boolean nullPresents = false;
        for (DBDLabelValuePair val : rowData.values()) {
            if (DBUtils.isNullValue(val.getValue())) {
                nullPresents = true;
                break;
            }
        }
        if (!nullPresents) {
            sortedList.add(0, new DBDLabelValuePair(DBValueFormatting.getDefaultValueDisplayString(null, DBDDisplayFormat.UI), null));
        }
    }
    Set<Object> checkedValues = new HashSet<>();
    for (ResultSetRow row : rows) {
        Object value = viewer.getModel().getCellValue(attribute, row);
        checkedValues.add(value);
    }
    DBDAttributeConstraint constraint = viewer.getModel().getDataFilter().getConstraint(attribute);
    if (constraint != null && constraint.getOperator() == DBCLogicalOperator.IN) {
        // checkedValues.add(constraint.getValue());
        if (constraint.getValue() instanceof Object[]) {
            Collections.addAll(checkedValues, (Object[]) constraint.getValue());
        }
    }
    checkedValues.addAll(savedValues);
    tableViewer.setInput(sortedList);
    DBDLabelValuePair firstVisibleItem = null;
    if (isCheckedTable)
        for (DBDLabelValuePair row : sortedList) {
            Object cellValue = row.getValue();
            if (checkedValues.contains(cellValue)) {
                TableItem t = (TableItem) tableViewer.testFindItem(row);
                t.setChecked(true);
                // ((CheckboxTableViewer) tableViewer).setChecked(row, true);
                if (firstVisibleItem == null) {
                    firstVisibleItem = row;
                }
            }
        }
    ViewerColumnController vcc = ViewerColumnController.getFromControl(tableViewer.getTable());
    if (vcc != null) {
        vcc.repackColumns();
    } else {
        UIUtils.packColumns(tableViewer.getTable(), true);
    }
    if (firstVisibleItem != null) {
        final Widget item = tableViewer.testFindItem(firstVisibleItem);
        if (item != null) {
            tableViewer.getTable().setSelection((TableItem) item);
            tableViewer.getTable().showItem((TableItem) item);
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) DBDLabelValuePair(org.jkiss.dbeaver.model.data.DBDLabelValuePair)

Example 22 with ViewerColumnController

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

the class NavigatorUtils method createContextMenu.

public static MenuManager createContextMenu(final IWorkbenchSite workbenchSite, final Viewer viewer, 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, CoreCommands.CMD_OBJECT_OPEN);
                // Get contribution item from menu item and check it's ID
                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);
                        }
                    }
                }
            }
        }
    });
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(final IMenuManager manager) {
            ViewerColumnController columnController = ViewerColumnController.getFromControl(control);
            if (columnController != null && columnController.isClickOnHeader()) {
                columnController.fillConfigMenu(manager);
                manager.add(new Separator());
                return;
            }
            manager.add(new GroupMarker(MB_NAVIGATOR_ADDITIONS));
            final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            final DBNNode selectedNode = getSelectedNode(viewer);
            if (selectedNode != null && !selectedNode.isLocked() && workbenchSite != null) {
                // Add "Set active object" menu
                if (selectedNode.isPersisted() && selectedNode instanceof DBNDatabaseNode && !(selectedNode instanceof DBNDatabaseFolder) && ((DBNDatabaseNode) selectedNode).getObject() != null) {
                    final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, ((DBNDatabaseNode) selectedNode).getObject());
                    if (activeContainer != null && activeContainer.supportsDefaultChange()) {
                        DBSObject activeChild;
                        activeChild = activeContainer.getDefaultObject();
                        if (activeChild != ((DBNDatabaseNode) selectedNode).getObject()) {
                            DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
                            if (databaseNode.getObject() != null && (activeChild == null || activeChild.getClass() == databaseNode.getObject().getClass())) {
                                // + databaseNode.getNodeType();
                                String text = "Set Active ";
                                // Fill context menu
                                IAction action = ActionUtils.makeAction(new NavigatorActionSetActiveObject(), workbenchSite, selection, text, null, null);
                                manager.add(action);
                            }
                        }
                    }
                }
                manager.add(new Separator());
                manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
                manager.add(new GroupMarker(IActionConstants.MB_ADDITIONS_END));
                // Add properties button
                if (PreferencesUtil.hasPropertiesContributors(selection.getFirstElement())) {
                    manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_PROPERTIES));
                }
                if (selectedNode.isPersisted()) {
                    // Add refresh button
                    manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REFRESH));
                }
            }
            manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS));
            if (menuListener != null) {
                menuListener.menuAboutToShow(manager);
            }
        }
    });
    menuMgr.setRemoveAllWhenShown(true);
    control.setMenu(menu);
    control.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            menuMgr.dispose();
        }
    });
    return menuMgr;
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) DisposeListener(org.eclipse.swt.events.DisposeListener) MenuListener(org.eclipse.swt.events.MenuListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Control(org.eclipse.swt.widgets.Control) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) NavigatorActionSetActiveObject(org.jkiss.dbeaver.ui.actions.navigator.NavigatorActionSetActiveObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) NavigatorActionSetActiveObject(org.jkiss.dbeaver.ui.actions.navigator.NavigatorActionSetActiveObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector)

Example 23 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 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, CoreCommands.CMD_OBJECT_OPEN);
                // Get contribution item from menu item and check it's ID
                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);
                        }
                    }
                }
            }
        }
    });
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(final IMenuManager manager) {
            ViewerColumnController columnController = ViewerColumnController.getFromControl(control);
            if (columnController != null && columnController.isClickOnHeader()) {
                columnController.fillConfigMenu(manager);
                manager.add(new Separator());
                return;
            }
            manager.add(new GroupMarker(CoreCommands.GROUP_NAVIGATOR_ADDITIONS));
            final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            final DBNNode selectedNode = getSelectedNode(viewer);
            if (selectedNode != null && !selectedNode.isLocked() && workbenchSite != null) {
                // Add "Set active object" menu
                if (selectedNode.isPersisted() && selectedNode instanceof DBNDatabaseNode && !(selectedNode instanceof DBNDatabaseFolder) && ((DBNDatabaseNode) selectedNode).getObject() != null) {
                    final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, ((DBNDatabaseNode) selectedNode).getObject());
                    if (activeContainer != null && activeContainer.supportsDefaultChange()) {
                        DBSObject activeChild;
                        activeChild = activeContainer.getDefaultObject();
                        if (activeChild != ((DBNDatabaseNode) selectedNode).getObject()) {
                            DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
                            if (databaseNode.getObject() != null && (activeChild == null || activeChild.getClass() == databaseNode.getObject().getClass())) {
                                manager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_SET_ACTIVE));
                            }
                        }
                    }
                }
                manager.add(new Separator());
                manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
                manager.add(new GroupMarker(IActionConstants.MB_ADDITIONS_END));
                // Add properties button
                if (PreferencesUtil.hasPropertiesContributors(selection.getFirstElement())) {
                    manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_PROPERTIES));
                }
                if (selectedNode.isPersisted()) {
                    // Add refresh button
                    manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REFRESH));
                }
            }
            manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS));
            manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS_END));
            if (menuListener != null) {
                menuListener.menuAboutToShow(manager);
            }
        }
    });
    menuMgr.setRemoveAllWhenShown(true);
    control.setMenu(menu);
    control.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            menuMgr.dispose();
        }
    });
    return menuMgr;
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) DisposeListener(org.eclipse.swt.events.DisposeListener) MenuListener(org.eclipse.swt.events.MenuListener) MenuItem(org.eclipse.swt.widgets.MenuItem) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Control(org.eclipse.swt.widgets.Control) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 24 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(OracleUIMessages.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 = DBNUtils.getNodeByObject(unit);
                if (node != null) {
                    cell.setText(node.getNodeName());
                    cell.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
                } else {
                    cell.setText(unit.toString());
                }
            }
        });
        columnController.addColumn(OracleUIMessages.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 = DBNUtils.getNodeByObject(unit);
                if (node != null) {
                    cell.setText(node.getNodeType());
                } else {
                    // $NON-NLS-1$
                    cell.setText("???");
                }
            }
        });
        columnController.createColumns();
        unitTable.addSelectionChangedListener(event -> {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            getButton(COMPILE_ID).setEnabled(!selection.isEmpty());
        });
        unitTable.addDoubleClickListener(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, null, true);
    }
    return composite;
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBCException(org.jkiss.dbeaver.model.exec.DBCException) Table(org.eclipse.swt.widgets.Table) BaseDialog(org.jkiss.dbeaver.ui.dialogs.BaseDialog) DBNUtils(org.jkiss.dbeaver.model.navigator.DBNUtils) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) ViewerCell(org.eclipse.jface.viewers.ViewerCell) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ObjectCompilerLogViewer(org.jkiss.dbeaver.ui.controls.ObjectCompilerLogViewer) GridData(org.eclipse.swt.layout.GridData) CommonUtils(org.jkiss.utils.CommonUtils) Shell(org.eclipse.swt.widgets.Shell) NLS(org.eclipse.osgi.util.NLS) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) NavigatorHandlerObjectOpen(org.jkiss.dbeaver.ui.navigator.actions.NavigatorHandlerObjectOpen) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject) SWT(org.eclipse.swt.SWT) OracleUIMessages(org.jkiss.dbeaver.ext.oracle.ui.internal.OracleUIMessages) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ViewerCell(org.eclipse.jface.viewers.ViewerCell) 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) TableViewer(org.eclipse.jface.viewers.TableViewer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider)

Example 25 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 && (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)

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