Search in sources :

Example 11 with IDataSourceContainerProvider

use of org.jkiss.dbeaver.model.IDataSourceContainerProvider in project dbeaver by serge-rider.

the class DataSourceToolbarUtils method refreshSelectorToolbar.

public static void refreshSelectorToolbar(IWorkbenchWindow window) {
    if (window instanceof WorkbenchWindow) {
        MTrimBar topTrim = ((WorkbenchWindow) window).getTopTrim();
        for (MTrimElement element : topTrim.getChildren()) {
            if (CONNECTION_SELECTOR_TOOLBAR_ID.equals(element.getElementId())) {
                boolean showConnectionSelector = false;
                IEditorPart activeEditor = window.getActivePage().getActiveEditor();
                DBPDataSourceContainer dataSourceContainer = null;
                if (activeEditor instanceof IDataSourceContainerProvider) {
                    showConnectionSelector = true;
                    dataSourceContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
                }
                if (element instanceof MElementContainer) {
                    Object widget = element.getWidget();
                    if (widget instanceof Composite) {
                        Composite controlsPanel = (Composite) widget;
                        Color bgColor = dataSourceContainer == null ? null : UIUtils.getConnectionTypeColor(dataSourceContainer.getConnectionConfiguration().getConnectionType());
                        Control[] childControl = controlsPanel.getChildren();
                        for (Control cc : childControl) {
                            // if (bgColor != null) {
                            // Color oldBackground = cc.getBackground();
                            // if (oldBackground != null) {
                            // RGB newBackground = UIUtils.blend(oldBackground.getRGB(), bgColor.getRGB(), 50);
                            // cc.setBackground(UIUtils.getSharedColor(newBackground));
                            // continue;
                            // }
                            // }
                            cc.setBackground(bgColor);
                        }
                    }
                    MElementContainer<? extends MUIElement> container = (MElementContainer<? extends MUIElement>) element;
                    for (MUIElement tbItem : container.getChildren()) {
                        // So we need to hide/show it to force text update
                        if (showConnectionSelector) {
                            tbItem.setVisible(false);
                        }
                        tbItem.setVisible(showConnectionSelector);
                    }
                }
                return;
            }
        }
    }
    // By some reason we can't locate the toolbar (#5712?). Let's just refresh elements then - its better than nothing
    updateCommandsUI();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkbenchWindow(org.eclipse.ui.internal.WorkbenchWindow) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) IEditorPart(org.eclipse.ui.IEditorPart) MElementContainer(org.eclipse.e4.ui.model.application.ui.MElementContainer) MTrimBar(org.eclipse.e4.ui.model.application.ui.basic.MTrimBar) Control(org.eclipse.swt.widgets.Control) MTrimElement(org.eclipse.e4.ui.model.application.ui.basic.MTrimElement) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 12 with IDataSourceContainerProvider

use of org.jkiss.dbeaver.model.IDataSourceContainerProvider in project dbeaver by serge-rider.

the class DatabaseEditorUtils method setPartBackground.

public static void setPartBackground(IEditorPart editor, Composite composite) {
    if (composite == null || composite.isDisposed()) {
        return;
    }
    CTabFolder tabFolder = null;
    Composite rootComposite = composite;
    for (Composite c = composite; c != null; c = c.getParent()) {
        if (!c.isDisposed() && c.getParent() instanceof CTabFolder) {
            tabFolder = (CTabFolder) c.getParent();
            // rootComposite = c;
            break;
        }
    }
    if (tabFolder != null) {
        tabFolder.setBorderVisible(false);
    }
    DBPDataSourceContainer dsContainer = null;
    if (editor instanceof IDataSourceContainerProvider) {
        dsContainer = ((IDataSourceContainerProvider) editor).getDataSourceContainer();
    } else if (editor instanceof DBPContextProvider) {
        DBCExecutionContext context = ((DBPContextProvider) editor).getExecutionContext();
        if (context != null) {
            dsContainer = context.getDataSource().getContainer();
        }
    }
    if (dsContainer == null) {
        rootComposite.setBackground(null);
    } else {
        Color bgColor = UIUtils.getConnectionColor(dsContainer.getConnectionConfiguration());
        rootComposite.setData(DBStyles.DATABASE_EDITOR_COMPOSITE_DATASOURCE, dsContainer);
        rootComposite.setBackground(bgColor);
    }
}
Also used : IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) CTabFolder(org.eclipse.swt.custom.CTabFolder) Composite(org.eclipse.swt.widgets.Composite) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) Color(org.eclipse.swt.graphics.Color) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 13 with IDataSourceContainerProvider

use of org.jkiss.dbeaver.model.IDataSourceContainerProvider 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)

Example 14 with IDataSourceContainerProvider

use of org.jkiss.dbeaver.model.IDataSourceContainerProvider in project dbeaver by dbeaver.

the class DatabaseEditorUtils method setPartBackground.

public static void setPartBackground(IEditorPart editor, Composite composite) {
    if (composite == null || composite.isDisposed()) {
        return;
    }
    CTabFolder tabFolder = null;
    Composite rootComposite = composite;
    for (Composite c = composite; c != null; c = c.getParent()) {
        if (!c.isDisposed() && c.getParent() instanceof CTabFolder) {
            tabFolder = (CTabFolder) c.getParent();
            // rootComposite = c;
            break;
        }
    }
    if (tabFolder != null) {
        tabFolder.setBorderVisible(false);
    }
    DBPDataSourceContainer dsContainer = null;
    if (editor instanceof IDataSourceContainerProvider) {
        dsContainer = ((IDataSourceContainerProvider) editor).getDataSourceContainer();
    } else if (editor instanceof DBPContextProvider) {
        DBCExecutionContext context = ((DBPContextProvider) editor).getExecutionContext();
        if (context != null) {
            dsContainer = context.getDataSource().getContainer();
        }
    }
    if (dsContainer == null) {
        rootComposite.setBackground(null);
    } else {
        Color bgColor = UIUtils.getConnectionColor(dsContainer.getConnectionConfiguration());
        rootComposite.setData(DBStyles.DATABASE_EDITOR_COMPOSITE_DATASOURCE, dsContainer);
        rootComposite.setBackground(bgColor);
    }
}
Also used : IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) CTabFolder(org.eclipse.swt.custom.CTabFolder) Composite(org.eclipse.swt.widgets.Composite) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) Color(org.eclipse.swt.graphics.Color) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Aggregations

IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)14 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)10 Color (org.eclipse.swt.graphics.Color)6 IEditorPart (org.eclipse.ui.IEditorPart)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 List (java.util.List)4 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)4 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)4 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)4 Composite (org.eclipse.swt.widgets.Composite)3 NotNull (org.jkiss.code.NotNull)3 Nullable (org.jkiss.code.Nullable)3 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)3 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)3 ProgressPageControl (org.jkiss.dbeaver.ui.controls.ProgressPageControl)3 ViewerColumnController (org.jkiss.dbeaver.ui.controls.ViewerColumnController)3 java.util (java.util)2 Pattern (java.util.regex.Pattern)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2