Search in sources :

Example 6 with DBRRunnableWithResult

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

the class DatabaseNavigatorTree method expandNodeOnLoad.

private void expandNodeOnLoad(final DBNNode node) {
    if (node instanceof DBNDataSource && DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_EXPAND_ON_CONNECT)) {
        try {
            DBRRunnableWithResult<DBNNode> runnable = new DBRRunnableWithResult<DBNNode>() {

                @Override
                public void run(DBRProgressMonitor monitor) throws InvocationTargetException {
                    try {
                        result = findActiveNode(monitor, node);
                    } catch (DBException e) {
                        throw new InvocationTargetException(e);
                    }
                }
            };
            UIUtils.runInProgressService(runnable);
            if (runnable.getResult() != null && !treeViewer.getTree().isDisposed()) {
                showNode(runnable.getResult());
                treeViewer.expandToLevel(runnable.getResult(), 1);
            /*
                    // TODO: it is a bug in Eclipse Photon.
                    try {
                        treeViewer.expandToLevel(runnable.getResult(), 1, true);
                    } catch (Throwable e) {
                        treeViewer.expandToLevel(runnable.getResult(), 1);
                    }
*/
            }
        } catch (InvocationTargetException e) {
            log.error("Can't expand node", e.getTargetException());
        } catch (InterruptedException e) {
        // skip it
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBRRunnableWithResult(org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with DBRRunnableWithResult

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

the class DBUtils method createNewAttributeValue.

public static <T> T createNewAttributeValue(DBCExecutionContext context, DBDValueHandler valueHandler, DBSTypedObject valueType, Class<T> targetType) throws DBCException {
    DBRRunnableWithResult<Object> runnable = new DBRRunnableWithResult<Object>() {

        @Override
        public void run(DBRProgressMonitor monitor) throws InvocationTargetException {
            try (DBCSession session = context.openSession(monitor, DBCExecutionPurpose.UTIL, "Create new object")) {
                result = valueHandler.createNewValueObject(session, valueType);
            } catch (DBCException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    try {
        DBWorkbench.getPlatformUI().executeWithProgress(runnable);
    // UIUtils.runInProgressService(runnable);
    } catch (InvocationTargetException e) {
        throw new DBCException(e.getTargetException(), context);
    } catch (InterruptedException e) {
        throw new DBCException(e, context);
    }
    Object result = runnable.getResult();
    if (result == null) {
        throw new DBCException("Internal error - null object created");
    }
    if (!targetType.isInstance(result)) {
        throw new DBCException("Internal error - wrong object type '" + result.getClass().getName() + "' while '" + targetType.getName() + "' was expected");
    }
    return targetType.cast(result);
}
Also used : DBRRunnableWithResult(org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)7 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)7 DBRRunnableWithResult (org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult)7 DBException (org.jkiss.dbeaver.DBException)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 GridData (org.eclipse.swt.layout.GridData)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 SWT (org.eclipse.swt.SWT)2 Composite (org.eclipse.swt.widgets.Composite)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 CreateRequest (org.eclipse.gef.requests.CreateRequest)1 CreationFactory (org.eclipse.gef.requests.CreationFactory)1 Action (org.eclipse.jface.action.Action)1 IContributionManager (org.eclipse.jface.action.IContributionManager)1 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)1 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)1 IFontProvider (org.eclipse.jface.viewers.IFontProvider)1