Search in sources :

Example 1 with SQLEditor

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor 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 SQLEditor

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.

the class OpenObjectConsoleHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    DBPDataSourceContainer ds = null;
    List<DBSObject> selectedObjects = NavigatorUtils.getSelectedObjects(HandlerUtil.getCurrentSelection(event));
    List<DBSEntity> entities = new ArrayList<>();
    for (DBSObject object : selectedObjects) {
        if (object instanceof DBSEntity) {
            entities.add((DBSEntity) object);
            ds = object.getDataSource().getContainer();
        }
    }
    DBRRunnableWithResult<String> generator = GenerateSQLContributor.SELECT_GENERATOR(entities, true);
    DBeaverUI.runInUI(workbenchWindow, generator);
    String sql = generator.getResult();
    SQLEditor editor = OpenHandler.openSQLConsole(workbenchWindow, ds, "Query", sql);
    if (editor != null) {
        editor.processSQL(false, false);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) ArrayList(java.util.ArrayList) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 3 with SQLEditor

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.

the class RenameHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActivePart(event), SQLEditor.class);
    if (editor == null) {
        log.error("No active SQL editor");
        return null;
    }
    Shell shell = HandlerUtil.getActiveShell(event);
    IFile file = EditorUtils.getFileFromInput(editor.getEditorInput());
    if (file == null) {
        UIUtils.showErrorDialog(shell, "Rename", "Can't rename - no source file");
        return null;
    }
    String newName = EnterNameDialog.chooseName(shell, "Rename SQL script [" + file.getName() + "]", file.getName());
    if (newName == null) {
        return null;
    }
    if (newName.indexOf('.') == -1) {
        int divPos = file.getName().lastIndexOf('.');
        if (divPos != -1) {
            newName += file.getName().substring(divPos);
        }
    }
    if (!newName.equals(file.getName())) {
        NullProgressMonitor monitor = new NullProgressMonitor();
        editor.doSave(monitor);
        try {
            file.move(file.getParent().getFullPath().append(newName), true, monitor);
        } catch (CoreException e) {
            UIUtils.showErrorDialog(shell, "Rename", "Error renaming file '" + file.getName() + "'", e);
        }
    }
    //file.set
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) Shell(org.eclipse.swt.widgets.Shell) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException)

Example 4 with SQLEditor

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.

the class SwitchPanelHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActiveEditor(event), SQLEditor.class);
    if (editor == null) {
        return null;
    }
    String actionId = event.getCommand().getId();
    switch(actionId) {
        case CoreCommands.CMD_SQL_SWITCH_PANEL:
            editor.toggleActivePanel();
            break;
        case CoreCommands.CMD_SQL_SHOW_OUTPUT:
            editor.showOutputPanel();
            break;
        case CoreCommands.CMD_SQL_SHOW_LOG:
            editor.showExecutionLogPanel();
            break;
    }
    return null;
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor)

Example 5 with SQLEditor

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by dbeaver.

the class CopySourceCodeHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActiveEditor(event), SQLEditor.class);
    if (editor == null) {
        return null;
    }
    ISelection selection = editor.getSelectionProvider().getSelection();
    if (selection.isEmpty() || !(selection instanceof TextSelection)) {
        return null;
    }
    TargetFormatDialog dialog = new TargetFormatDialog(editor, (TextSelection) selection);
    if (dialog.open() != IDialogConstants.OK_ID) {
        return null;
    }
    UIUtils.setClipboardContents(Display.getCurrent(), TextTransfer.getInstance(), dialog.getConvertedText());
    return null;
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) TextSelection(org.eclipse.jface.text.TextSelection) ISelection(org.eclipse.jface.viewers.ISelection)

Aggregations

SQLEditor (org.jkiss.dbeaver.ui.editors.sql.SQLEditor)23 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)5 IFile (org.eclipse.core.resources.IFile)4 IEditorPart (org.eclipse.ui.IEditorPart)4 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)4 TextSelection (org.eclipse.jface.text.TextSelection)3 ISelection (org.eclipse.jface.viewers.ISelection)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)3 SQLQueryTransformerCount (org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerCount)3 SQLQueryTransformerExpression (org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerExpression)3 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 NotNull (org.jkiss.code.NotNull)2 DBException (org.jkiss.dbeaver.DBException)2