Search in sources :

Example 1 with IDataSourceContainerProvider

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

the class NavigatorHandlerLinkEditor method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor == null) {
        return null;
    }
    NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
    if (navigatorView == null) {
        return null;
    }
    if (navigatorView instanceof ProjectExplorerView) {
        if (activeEditor instanceof SQLEditor) {
            IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
            if (file != null) {
                showResourceInNavigator(navigatorView, file);
            }
        } else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
            IFile editorFile = ((ProjectFileEditorInput) activeEditor.getEditorInput()).getFile();
            showResourceInNavigator(navigatorView, editorFile);
        }
    } else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
        IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
        DBNNode dbnNode = editorInput.getNavigatorNode();
        if (dbnNode != null) {
            navigatorView.showNode(dbnNode);
        }
    } else if (activeEditor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
        @NotNull final DBSObject activeObject;
        if (dsContainer != null) {
            DBPDataSource dataSource = dsContainer.getDataSource();
            if (dataSource != null) {
                activeObject = DBUtils.getDefaultOrActiveObject(dataSource);
            } else {
                activeObject = dsContainer;
            }
            final NavigatorViewBase view = navigatorView;
            DBeaverUI.runInUI(activePage.getWorkbenchWindow(), new DBRRunnableWithProgress() {

                @Override
                public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    DBSObject showObject = activeObject;
                    if (showObject instanceof DBPDataSource) {
                        showObject = ((DBPDataSource) showObject).getContainer();
                    }
                    DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
                    if (objectNode != null) {
                        view.showNode(objectNode);
                    }
                }
            });
        }
    }
    activePage.activate(navigatorView);
    return null;
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) ProjectExplorerView(org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ProjectFileEditorInput(org.jkiss.dbeaver.ui.editors.ProjectFileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) NotNull(org.jkiss.code.NotNull) InvocationTargetException(java.lang.reflect.InvocationTargetException) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 2 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 && (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 IDataSourceContainerProvider

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

the class DataSourceAutoCommitHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
    if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
        return;
    }
    IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    boolean autoCommit = true;
    DBPTransactionIsolation isolation = null;
    DBCExecutionContext context = getExecutionContext(activeEditor);
    if (context != null && context.isConnected()) {
        DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
        if (txnManager != null) {
            try {
                // Change auto-commit mode
                autoCommit = txnManager.isAutoCommit();
                isolation = txnManager.getTransactionIsolation();
            } catch (DBCException e) {
                log.warn(e);
            }
        }
    } else if (activeEditor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer container = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
        if (container != null) {
            autoCommit = container.isDefaultAutoCommit();
            isolation = container.getActiveTransactionsIsolation();
        }
    }
    element.setChecked(autoCommit);
    // Update command image
    element.setIcon(DBeaverIcons.getImageDescriptor(autoCommit ? UIIcon.TXN_COMMIT_AUTO : UIIcon.TXN_COMMIT_MANUAL));
    String isolationName = isolation == null ? "?" : isolation.getTitle();
    String text = autoCommit ? "Switch to manual commit (" + isolationName + ")" : "Switch to auto-commit";
    element.setText(text);
    element.setTooltip(text);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPTransactionIsolation(org.jkiss.dbeaver.model.DBPTransactionIsolation) DBCException(org.jkiss.dbeaver.model.exec.DBCException) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBCTransactionManager(org.jkiss.dbeaver.model.exec.DBCTransactionManager)

Example 4 with IDataSourceContainerProvider

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

the class NavigatorHandlerLinkEditor method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor == null) {
        return null;
    }
    NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
    if (navigatorView == null) {
        return null;
    }
    if (navigatorView instanceof ProjectExplorerView) {
        if (activeEditor instanceof SQLEditor) {
            IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
            if (file != null) {
                showResourceInNavigator(navigatorView, file);
            }
        } else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
            IFile editorFile = ((ProjectFileEditorInput) activeEditor.getEditorInput()).getFile();
            showResourceInNavigator(navigatorView, editorFile);
        }
    } else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
        IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
        DBNNode dbnNode = editorInput.getNavigatorNode();
        if (dbnNode != null) {
            navigatorView.showNode(dbnNode);
        }
    } else if (activeEditor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
        @NotNull final DBSObject activeObject;
        if (dsContainer != null) {
            DBPDataSource dataSource = dsContainer.getDataSource();
            if (dataSource != null) {
                activeObject = DBUtils.getDefaultOrActiveObject(dataSource);
            } else {
                activeObject = dsContainer;
            }
            final NavigatorViewBase view = navigatorView;
            DBeaverUI.runInUI(activePage.getWorkbenchWindow(), new DBRRunnableWithProgress() {

                @Override
                public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    DBSObject showObject = activeObject;
                    if (showObject instanceof DBPDataSource) {
                        showObject = ((DBPDataSource) showObject).getContainer();
                    }
                    DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
                    if (objectNode != null) {
                        view.showNode(objectNode);
                    }
                }
            });
        }
    }
    activePage.activate(navigatorView);
    return null;
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) ProjectExplorerView(org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ProjectFileEditorInput(org.jkiss.dbeaver.ui.editors.ProjectFileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) NotNull(org.jkiss.code.NotNull) InvocationTargetException(java.lang.reflect.InvocationTargetException) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 5 with IDataSourceContainerProvider

use of org.jkiss.dbeaver.model.IDataSourceContainerProvider 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 && (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())) {
                        // 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
            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) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject)

Aggregations

IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)12 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)9 IEditorPart (org.eclipse.ui.IEditorPart)5 Color (org.eclipse.swt.graphics.Color)4 DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)4 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 List (java.util.List)3 Composite (org.eclipse.swt.widgets.Composite)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 NotNull (org.jkiss.code.NotNull)3 Nullable (org.jkiss.code.Nullable)3 IFile (org.eclipse.core.resources.IFile)2 CTabFolder (org.eclipse.swt.custom.CTabFolder)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)2 DBPTransactionIsolation (org.jkiss.dbeaver.model.DBPTransactionIsolation)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 DBCTransactionManager (org.jkiss.dbeaver.model.exec.DBCTransactionManager)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2