use of org.eclipse.jface.viewers.ISelection 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.jface.viewers.ISelection in project dbeaver by serge-rider.
the class NavigatorHandlerAssociateScript method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Shell activeShell = HandlerUtil.getActiveShell(event);
List<IFile> scripts = new ArrayList<>();
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
for (Iterator iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
final DBNNode node = RuntimeUtils.getObjectAdapter(iter.next(), DBNNode.class);
if (node instanceof DBNResource) {
IResource resource = ((DBNResource) node).getResource();
if (resource instanceof IFile) {
scripts.add((IFile) resource);
}
}
}
}
if (!scripts.isEmpty()) {
DBPDataSourceContainer dataSourceDescriptor = SelectDataSourceDialog.selectDataSource(activeShell, scripts.get(0).getProject());
if (dataSourceDescriptor != null) {
for (IFile script : scripts) {
EditorUtils.setFileDataSource(script, dataSourceDescriptor, true);
}
}
}
return null;
}
use of org.eclipse.jface.viewers.ISelection 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.jface.viewers.ISelection in project dbeaver by serge-rider.
the class NavigatorHandlerCreateFolder method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
Object element = structSelection.getFirstElement();
if (!(element instanceof DBNResource)) {
return null;
}
Shell activeShell = HandlerUtil.getActiveShell(event);
String folderName = EnterNameDialog.chooseName(activeShell, CoreMessages.actions_navigator_create_folder_folder_name);
if (!CommonUtils.isEmpty(folderName)) {
try {
((DBNResource) element).createNewFolder(folderName);
} catch (DBException e) {
UIUtils.showErrorDialog(activeShell, CoreMessages.actions_navigator_create_folder_error_title, NLS.bind(CoreMessages.actions_navigator_create_folder_error_message, folderName), e);
}
}
}
return null;
}
use of org.eclipse.jface.viewers.ISelection 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;
}
Aggregations