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;
}
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");
}
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;
}
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);
}
}
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;
}
Aggregations