Search in sources :

Example 1 with GotoObjectDialog

use of org.jkiss.dbeaver.ui.dialogs.GotoObjectDialog in project dbeaver by dbeaver.

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)

Example 2 with GotoObjectDialog

use of org.jkiss.dbeaver.ui.dialogs.GotoObjectDialog 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

ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)2 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 DBSFolder (org.jkiss.dbeaver.model.struct.DBSFolder)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 DBSWrapper (org.jkiss.dbeaver.model.struct.DBSWrapper)2 GotoObjectDialog (org.jkiss.dbeaver.ui.dialogs.GotoObjectDialog)2 INavigatorModelView (org.jkiss.dbeaver.ui.navigator.INavigatorModelView)2