Search in sources :

Example 6 with IEditorPart

use of org.eclipse.ui.IEditorPart in project dbeaver by serge-rider.

the class AbstractDataSourceHandler method getDataSourceContainer.

protected static DBPDataSourceContainer getDataSourceContainer(ExecutionEvent event, boolean useEditor) {
    if (useEditor) {
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
        if (editor != null) {
            DBPDataSourceContainer container = getDataSourceContainer(editor);
            if (container != null) {
                return container;
            }
        }
        return null;
    }
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    DBPDataSourceContainer container = getDataSourceContainer(activePart);
    if (container != null) {
        return container;
    }
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        DBSObject selectedObject = NavigatorUtils.getSelectedObject((IStructuredSelection) selection);
        if (selectedObject instanceof DBPDataSourceContainer) {
            return (DBPDataSourceContainer) selectedObject;
        } else if (selectedObject != null) {
            DBPDataSource dataSource = selectedObject.getDataSource();
            return dataSource == null ? null : dataSource.getContainer();
        }
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 7 with IEditorPart

use of org.eclipse.ui.IEditorPart in project dbeaver by serge-rider.

the class DataSourceAutoCommitHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
    if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
        return;
    }
    IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    boolean autoCommit = true;
    DBPTransactionIsolation isolation = null;
    DBCExecutionContext context = getExecutionContext(activeEditor);
    if (context != null && context.isConnected()) {
        DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
        if (txnManager != null) {
            try {
                // Change auto-commit mode
                autoCommit = txnManager.isAutoCommit();
                isolation = txnManager.getTransactionIsolation();
            } catch (DBCException e) {
                log.warn(e);
            }
        }
    } else if (activeEditor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer container = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
        if (container != null) {
            autoCommit = container.isDefaultAutoCommit();
            isolation = container.getActiveTransactionsIsolation();
        }
    }
    element.setChecked(autoCommit);
    // Update command image
    element.setIcon(DBeaverIcons.getImageDescriptor(autoCommit ? UIIcon.TXN_COMMIT_AUTO : UIIcon.TXN_COMMIT_MANUAL));
    String isolationName = isolation == null ? "?" : isolation.getTitle();
    element.setText(autoCommit ? "Switch to manual commit (" + isolationName + ")" : "Switch to auto-commit");
    element.setTooltip(autoCommit ? "Manual commit (" + isolationName + ")" : "Auto-commit");
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPTransactionIsolation(org.jkiss.dbeaver.model.DBPTransactionIsolation) DBCException(org.jkiss.dbeaver.model.exec.DBCException) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBCTransactionManager(org.jkiss.dbeaver.model.exec.DBCTransactionManager)

Example 8 with IEditorPart

use of org.eclipse.ui.IEditorPart 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 9 with IEditorPart

use of org.eclipse.ui.IEditorPart in project dbeaver by serge-rider.

the class RedoChangesHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
    if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
        return;
    }
    final IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
    if (activeEditor instanceof EntityEditor) {
        final DBECommandContext commandContext = ((EntityEditor) activeEditor).getCommandContext();
        String text = "Redo";
        if (commandContext != null && commandContext.getRedoCommand() != null) {
            text += " " + commandContext.getRedoCommand().getTitle();
        }
        element.setText(text);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) IEditorPart(org.eclipse.ui.IEditorPart)

Example 10 with IEditorPart

use of org.eclipse.ui.IEditorPart in project dbeaver by serge-rider.

the class NavigateQueryHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!(activeEditor instanceof SQLEditorBase)) {
        return null;
    }
    SQLEditorBase editor = (SQLEditorBase) activeEditor;
    String actionId = event.getCommand().getId();
    SQLQuery nextQuery;
    switch(actionId) {
        case CoreCommands.CMD_SQL_QUERY_NEXT:
            nextQuery = editor.extractNextQuery(true);
            break;
        case CoreCommands.CMD_SQL_QUERY_PREV:
            nextQuery = editor.extractNextQuery(false);
            break;
        default:
            nextQuery = null;
            break;
    }
    if (nextQuery != null) {
        editor.selectAndReveal(nextQuery.getOffset(), nextQuery.getLength());
    }
    return null;
}
Also used : SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) IEditorPart(org.eclipse.ui.IEditorPart) SQLQuery(org.jkiss.dbeaver.model.sql.SQLQuery)

Aggregations

IEditorPart (org.eclipse.ui.IEditorPart)286 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)114 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)80 PartInitException (org.eclipse.ui.PartInitException)57 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)53 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)45 IEditorReference (org.eclipse.ui.IEditorReference)43 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)41 IFile (org.eclipse.core.resources.IFile)41 ArrayList (java.util.ArrayList)36 IViewPart (org.eclipse.ui.IViewPart)31 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)27 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)26 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)24 FileEditorInput (org.eclipse.ui.part.FileEditorInput)23 IEditorInput (org.eclipse.ui.IEditorInput)19 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)18 List (java.util.List)17 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)17 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)16