use of org.eclipse.ui.IWorkbenchWindow in project dbeaver by serge-rider.
the class NavigatorHandlerObjectDelete method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
this.structSelection = null;
this.deleteAll = null;
this.tasksToExecute.clear();
final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
structSelection = (IStructuredSelection) selection;
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object element = iter.next();
if (element instanceof DBNDatabaseNode) {
deleteObject(activeWorkbenchWindow, (DBNDatabaseNode) element);
} else if (element instanceof DBNResource) {
deleteResource(activeWorkbenchWindow, (DBNResource) element);
} else if (element instanceof DBNLocalFolder) {
deleteLocalFolder(activeWorkbenchWindow, (DBNLocalFolder) element);
} else {
//$NON-NLS-1$ //$NON-NLS-2$
log.warn("Don't know how to delete element '" + element + "'");
}
if (deleteAll != null && !deleteAll) {
break;
}
}
}
if (!tasksToExecute.isEmpty()) {
TasksJob.runTasks(tasksToExecute.size() > 1 ? "Delete " + tasksToExecute.size() + " objects" : "Delete object", tasksToExecute);
tasksToExecute.clear();
}
return null;
}
use of org.eclipse.ui.IWorkbenchWindow in project dbeaver by serge-rider.
the class NavigatorHandlerCopyAbstract method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
copySelection(workbenchWindow, activePart, selection);
}
});
return null;
}
use of org.eclipse.ui.IWorkbenchWindow 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.IWorkbenchWindow in project dbeaver by serge-rider.
the class DataSourceToolsContributor method fillToolsMenu.
private static void fillToolsMenu(List<IContributionItem> menuItems, List<ToolDescriptor> tools, ISelection selection) {
boolean hasTools = false;
if (!CommonUtils.isEmpty(tools)) {
IWorkbenchWindow workbenchWindow = DBeaverUI.getActiveWorkbenchWindow();
if (workbenchWindow.getActivePage() != null) {
IWorkbenchPart activePart = workbenchWindow.getActivePage().getActivePart();
if (activePart != null) {
Map<ToolGroupDescriptor, IMenuManager> groupsMap = new HashMap<>();
for (ToolDescriptor tool : tools) {
hasTools = true;
IMenuManager parentMenu = null;
if (tool.getGroup() != null) {
parentMenu = getGroupMenu(menuItems, groupsMap, tool.getGroup());
}
IAction action = ActionUtils.makeAction(new NavigatorActionExecuteTool(workbenchWindow, tool), activePart.getSite(), selection, tool.getLabel(), tool.getIcon() == null ? null : DBeaverIcons.getImageDescriptor(tool.getIcon()), tool.getDescription());
if (parentMenu == null) {
menuItems.add(new ActionContributionItem(action));
} else {
parentMenu.add(new ActionContributionItem(action));
}
}
}
}
}
if (!hasTools) {
menuItems.add(new ActionContributionItem(new EmptyListAction()));
}
}
use of org.eclipse.ui.IWorkbenchWindow in project dbeaver by serge-rider.
the class DataTransferHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (!(selection instanceof IStructuredSelection)) {
return null;
}
IStructuredSelection ss = (IStructuredSelection) selection;
final List<IDataTransferProducer> producers = new ArrayList<>();
final List<IDataTransferConsumer> consumers = new ArrayList<>();
for (Iterator<?> iter = ss.iterator(); iter.hasNext(); ) {
Object object = iter.next();
IDataTransferNode node = adaptTransferNode(object);
if (node instanceof IDataTransferProducer) {
producers.add((IDataTransferProducer) node);
} else if (node instanceof IDataTransferConsumer) {
consumers.add((IDataTransferConsumer) node);
}
}
if (!consumers.isEmpty()) {
// We need to choose producer for consumers
for (IDataTransferConsumer consumer : consumers) {
IDataTransferProducer producer = chooseProducer(event, consumer);
if (producer == null) {
return null;
}
producers.add(producer);
}
}
// Run transfer wizard
if (!producers.isEmpty() || !consumers.isEmpty()) {
ActiveWizardDialog dialog = new ActiveWizardDialog(workbenchWindow, new DataTransferWizard(producers.toArray(new IDataTransferProducer[producers.size()]), consumers.toArray(new IDataTransferConsumer[consumers.size()])));
dialog.open();
}
return null;
}
Aggregations