Search in sources :

Example 1 with SelectDatabaseDialog

use of org.jkiss.dbeaver.ui.navigator.dialogs.SelectDatabaseDialog in project dbeaver by serge-rider.

the class SelectActiveSchemaHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    if (SelectActiveDataSourceHandler.getDataSourceContainerProvider(HandlerUtil.getActiveEditor(event)) == null) {
        return null;
    }
    DBPDataSourceContainer dataSourceContainer = DataSourceToolbarUtils.getCurrentDataSource(HandlerUtil.getActiveWorkbenchWindow(event));
    if (dataSourceContainer == null) {
        log.debug("No active connection. Action is in disabled state.");
        return null;
    }
    DBCExecutionContext executionContext = getExecutionContextFromPart(HandlerUtil.getActiveEditor(event));
    ContextDefaultObjectsReader contextDefaultObjectsReader = new ContextDefaultObjectsReader(dataSourceContainer.getDataSource(), executionContext);
    try {
        UIUtils.runInProgressService(contextDefaultObjectsReader);
    } catch (InvocationTargetException e) {
        DBWorkbench.getPlatformUI().showError("Schema list", "Error reading schema list", e.getTargetException());
        return null;
    } catch (InterruptedException e) {
        return null;
    }
    DBSObject selectedDB = null;
    DBSObject defaultObject = contextDefaultObjectsReader.getDefaultObject();
    if (defaultObject != null) {
        for (DBSObject object : contextDefaultObjectsReader.getObjectList()) {
            if (object == defaultObject || object == defaultObject.getParentObject()) {
                selectedDB = object;
            }
        }
    }
    DBNDatabaseNode selectedNode = selectedDB == null ? null : DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(selectedDB);
    SelectDatabaseDialog dialog = new SelectDatabaseDialog(HandlerUtil.getActiveShell(event), dataSourceContainer, contextDefaultObjectsReader.getDefaultCatalogName(), contextDefaultObjectsReader.getNodeList(), selectedNode == null ? null : Collections.singletonList(selectedNode));
    dialog.setModeless(true);
    if (dialog.open() == IDialogConstants.CANCEL_ID) {
        return null;
    }
    DBNDatabaseNode node = dialog.getSelectedObject();
    if (node != null && node.getObject() != defaultObject) {
        // Change current schema
        changeDataBaseSelection(dataSourceContainer, executionContext, contextDefaultObjectsReader.getDefaultCatalogName(), dialog.getCurrentInstanceName(), node.getNodeName());
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ContextDefaultObjectsReader(org.jkiss.dbeaver.model.impl.struct.ContextDefaultObjectsReader) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) SelectDatabaseDialog(org.jkiss.dbeaver.ui.navigator.dialogs.SelectDatabaseDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with SelectDatabaseDialog

use of org.jkiss.dbeaver.ui.navigator.dialogs.SelectDatabaseDialog in project dbeaver by dbeaver.

the class SelectActiveSchemaHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    if (SelectActiveDataSourceHandler.getDataSourceContainerProvider(HandlerUtil.getActiveEditor(event)) == null) {
        return null;
    }
    DBPDataSourceContainer dataSourceContainer = DataSourceToolbarUtils.getCurrentDataSource(HandlerUtil.getActiveWorkbenchWindow(event));
    if (dataSourceContainer == null) {
        log.debug("No active connection. Action is in disabled state.");
        return null;
    }
    DBCExecutionContext executionContext = getExecutionContextFromPart(HandlerUtil.getActiveEditor(event));
    ContextDefaultObjectsReader contextDefaultObjectsReader = new ContextDefaultObjectsReader(dataSourceContainer.getDataSource(), executionContext);
    try {
        UIUtils.runInProgressService(contextDefaultObjectsReader);
    } catch (InvocationTargetException e) {
        DBWorkbench.getPlatformUI().showError("Schema list", "Error reading schema list", e.getTargetException());
        return null;
    } catch (InterruptedException e) {
        return null;
    }
    DBSObject selectedDB = null;
    DBSObject defaultObject = contextDefaultObjectsReader.getDefaultObject();
    if (defaultObject != null) {
        for (DBSObject object : contextDefaultObjectsReader.getObjectList()) {
            if (object == defaultObject || object == defaultObject.getParentObject()) {
                selectedDB = object;
            }
        }
    }
    DBNDatabaseNode selectedNode = selectedDB == null ? null : DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(selectedDB);
    SelectDatabaseDialog dialog = new SelectDatabaseDialog(HandlerUtil.getActiveShell(event), dataSourceContainer, contextDefaultObjectsReader.getDefaultCatalogName(), contextDefaultObjectsReader.getNodeList(), selectedNode == null ? null : Collections.singletonList(selectedNode));
    dialog.setModeless(true);
    if (dialog.open() == IDialogConstants.CANCEL_ID) {
        return null;
    }
    DBNDatabaseNode node = dialog.getSelectedObject();
    if (node != null && node.getObject() != defaultObject) {
        // Change current schema
        changeDataBaseSelection(dataSourceContainer, executionContext, contextDefaultObjectsReader.getDefaultCatalogName(), dialog.getCurrentInstanceName(), node.getNodeName());
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ContextDefaultObjectsReader(org.jkiss.dbeaver.model.impl.struct.ContextDefaultObjectsReader) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) SelectDatabaseDialog(org.jkiss.dbeaver.ui.navigator.dialogs.SelectDatabaseDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)2 ContextDefaultObjectsReader (org.jkiss.dbeaver.model.impl.struct.ContextDefaultObjectsReader)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 SelectDatabaseDialog (org.jkiss.dbeaver.ui.navigator.dialogs.SelectDatabaseDialog)2