Search in sources :

Example 1 with DBPContextProvider

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

the class DataSourceTransactionLogHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Shell activeShell = HandlerUtil.getActiveShell(event);
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    DBCExecutionContext context = null;
    if (editor instanceof DBPContextProvider) {
        context = ((DBPContextProvider) editor).getExecutionContext();
    }
    TransactionLogDialog.showDialog(activeShell, context);
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) IEditorPart(org.eclipse.ui.IEditorPart)

Example 2 with DBPContextProvider

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

the class SQLAttributeResolver method resolveAll.

@Override
protected String[] resolveAll(final TemplateContext context) {
    final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
    if (executionContext == null) {
        return super.resolveAll(context);
    }
    TemplateVariable tableVariable = ((SQLContext) context).getTemplateVariable("table");
    final String tableName = tableVariable == null ? null : tableVariable.getDefaultValue();
    if (!CommonUtils.isEmpty(tableName)) {
        final List<DBSEntityAttribute> attributes = new ArrayList<>();
        DBRRunnableWithProgress runnable = new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    List<DBSEntity> entities = new ArrayList<>();
                    SQLEntityResolver.resolveTables(monitor, executionContext, context, entities);
                    if (!CommonUtils.isEmpty(entities)) {
                        DBSEntity table = DBUtils.findObject(entities, tableName);
                        if (table != null) {
                            attributes.addAll(CommonUtils.safeCollection(table.getAttributes(monitor)));
                        }
                    }
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        RuntimeUtils.runTask(runnable, "Resolve attributes", 1000);
        if (!CommonUtils.isEmpty(attributes)) {
            String[] result = new String[attributes.size()];
            for (int i = 0; i < attributes.size(); i++) {
                DBSEntityAttribute entity = attributes.get(i);
                result[i] = entity.getName();
            }
            return result;
        }
    }
    return super.resolveAll(context);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity)

Example 3 with DBPContextProvider

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

the class SQLDataTypeResolver method resolveAll.

@Override
protected String[] resolveAll(final TemplateContext context) {
    final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
    if (executionContext == null) {
        return super.resolveAll(context);
    }
    DBPDataTypeProvider dataTypeProvider = DBUtils.getAdapter(DBPDataTypeProvider.class, executionContext.getDataSource());
    if (dataTypeProvider != null) {
        final Collection<? extends DBSDataType> localDataTypes = dataTypeProvider.getLocalDataTypes();
        if (!CommonUtils.isEmpty(localDataTypes)) {
            String[] result = new String[localDataTypes.size()];
            int index = 0;
            for (DBSDataType dataType : localDataTypes) {
                result[index++] = dataType.getName();
            }
            return result;
        }
    }
    return super.resolveAll(context);
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) DBPDataTypeProvider(org.jkiss.dbeaver.model.DBPDataTypeProvider)

Example 4 with DBPContextProvider

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

the class SQLObjectResolver method resolveAll.

@Override
protected String[] resolveAll(final TemplateContext context) {
    final List<T> entities = new ArrayList<>();
    if (context instanceof DBPContextProvider) {
        final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
        if (executionContext != null) {
            RuntimeUtils.runTask(new DBRRunnableWithProgress() {

                @Override
                public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    try {
                        resolveObjects(monitor, executionContext, context, entities);
                    } catch (DBException e) {
                        throw new InvocationTargetException(e);
                    }
                }
            }, "Resolve object references", 1000);
        }
    }
    if (!CommonUtils.isEmpty(entities)) {
        String[] result = new String[entities.size()];
        for (int i = 0; i < entities.size(); i++) {
            T entity = entities.get(i);
            result[i] = entity.getName();
        }
        return result;
    }
    return super.resolveAll(context);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 5 with DBPContextProvider

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

the class NavigatorHandlerObjectGoto method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    DBCExecutionContext context = null;
    DBSObject container = null;
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof DBPContextProvider) {
        context = ((DBPContextProvider) activePart).getExecutionContext();
    } else if (activePart instanceof INavigatorModelView) {
        final ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection instanceof IStructuredSelection) {
            Object element = ((IStructuredSelection) selection).getFirstElement();
            if (element instanceof DBSWrapper) {
                DBSObject object = ((DBSWrapper) element).getObject();
                if (object != null) {
                    container = object;
                    while (container instanceof DBSFolder) {
                        container = container.getParentObject();
                    }
                    DBPDataSource dataSource = object.getDataSource();
                    if (dataSource != null) {
                        context = dataSource.getDefaultContext(true);
                    }
                }
            }
        }
    }
    if (context == null) {
        DBUserInterface.getInstance().showError("Go to object", "No active datasource");
        return null;
    }
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    GotoObjectDialog dialog = new GotoObjectDialog(HandlerUtil.getActiveShell(event), context, container);
    dialog.open();
    Object[] objectsToOpen = dialog.getResult();
    if (!ArrayUtils.isEmpty(objectsToOpen)) {
        Collection<DBNDatabaseNode> nodes = NavigatorHandlerObjectBase.getNodesByObjects(Arrays.asList(objectsToOpen));
        for (DBNDatabaseNode node : nodes) {
            NavigatorUtils.openNavigatorNode(node, workbenchWindow);
        }
    }
    return null;
}
Also used : DBSFolder(org.jkiss.dbeaver.model.struct.DBSFolder) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) GotoObjectDialog(org.jkiss.dbeaver.ui.dialogs.GotoObjectDialog) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)9 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)7 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 DBException (org.jkiss.dbeaver.DBException)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)2 TemplateVariable (org.eclipse.jface.text.templates.TemplateVariable)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 Color (org.eclipse.swt.graphics.Color)1 Composite (org.eclipse.swt.widgets.Composite)1 Shell (org.eclipse.swt.widgets.Shell)1