Search in sources :

Example 11 with ISelection

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;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISelection(org.eclipse.jface.viewers.ISelection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 12 with ISelection

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;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) Shell(org.eclipse.swt.widgets.Shell) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IResource(org.eclipse.core.resources.IResource)

Example 13 with ISelection

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;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection)

Example 14 with ISelection

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;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBException(org.jkiss.dbeaver.DBException) Shell(org.eclipse.swt.widgets.Shell) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 15 with ISelection

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

Aggregations

ISelection (org.eclipse.jface.viewers.ISelection)214 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)141 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)37 SelectionEvent (org.eclipse.swt.events.SelectionEvent)34 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)32 GridData (org.eclipse.swt.layout.GridData)31 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)30 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)30 ArrayList (java.util.ArrayList)27 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)25 WizardDialog (org.eclipse.jface.wizard.WizardDialog)22 GridLayout (org.eclipse.swt.layout.GridLayout)22 Composite (org.eclipse.swt.widgets.Composite)21 TableViewer (org.eclipse.jface.viewers.TableViewer)20 RepositoryNode (org.talend.repository.model.RepositoryNode)20 IFile (org.eclipse.core.resources.IFile)19 IProject (org.eclipse.core.resources.IProject)19 Iterator (java.util.Iterator)17 PartInitException (org.eclipse.ui.PartInitException)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16