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;
}
use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.
the class CompileHandler method getSelectedObjects.
private List<OracleSourceObject> getSelectedObjects(ExecutionEvent event) {
List<OracleSourceObject> objects = new ArrayList<>();
final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (currentSelection instanceof IStructuredSelection && !currentSelection.isEmpty()) {
for (Iterator<?> iter = ((IStructuredSelection) currentSelection).iterator(); iter.hasNext(); ) {
final Object element = iter.next();
final OracleSourceObject sourceObject = RuntimeUtils.getObjectAdapter(element, OracleSourceObject.class);
if (sourceObject != null) {
objects.add(sourceObject);
}
}
}
if (objects.isEmpty()) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final OracleSourceObject sourceObject = RuntimeUtils.getObjectAdapter(activePart, OracleSourceObject.class);
if (sourceObject != null) {
objects.add(sourceObject);
}
}
return objects;
}
Aggregations