Search in sources :

Example 6 with ISelection

use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.

the class NavigatorHandlerRefresh method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    //final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
    INavigatorModelView navigatorView;
    if (workbenchPart instanceof INavigatorModelView) {
        navigatorView = (INavigatorModelView) workbenchPart;
    } else {
        navigatorView = workbenchPart.getAdapter(INavigatorModelView.class);
    }
    if (navigatorView == null) {
        // Try to refresh as refreshable part
        if (workbenchPart instanceof IRefreshablePart) {
            ((IRefreshablePart) workbenchPart).refreshPart(this, true);
        }
        return null;
    }
    final List<DBNNode> refreshObjects = new ArrayList<>();
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode rootNode = navigatorView.getRootNode();
    if (rootNode == null) {
        if (workbenchPart instanceof IEditorPart) {
            if (((IEditorPart) workbenchPart).getEditorInput() instanceof IDatabaseEditorInput) {
                rootNode = ((IDatabaseEditorInput) ((IEditorPart) workbenchPart).getEditorInput()).getNavigatorNode();
            }
        }
    }
    if (rootNode != null && rootNode.getParentNode() instanceof DBNDatabaseNode) {
        refreshObjects.add(rootNode);
    } else if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object object = iter.next();
            if (object instanceof DBNNode) {
                refreshObjects.add((DBNNode) object);
            }
        }
    }
    // Refresh objects
    if (!refreshObjects.isEmpty()) {
        refreshNavigator(refreshObjects);
    }
    return null;
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) IRefreshablePart(org.jkiss.dbeaver.ui.IRefreshablePart) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 7 with ISelection

use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.

the class NavigatorHandlerCreateLink 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;
        }
        final IResource resource = ((DBNResource) element).getResource();
        if (resource instanceof IFolder) {
            final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
            DirectoryDialog dialog = new DirectoryDialog(workbenchWindow.getShell(), SWT.NONE);
            String folder = dialog.open();
            if (folder != null) {
                createLink(workbenchWindow, (IFolder) resource, folder);
            }
        }
    }
    return null;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 8 with ISelection

use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.

the class NavigatorHandlerFilterConfig method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode node = NavigatorUtils.getSelectedNode(selection);
    if (node instanceof DBNDatabaseItem) {
        node = node.getParentNode();
    }
    if (node instanceof DBNDatabaseFolder) {
        configureFilters(HandlerUtil.getActiveShell(event), node);
    }
    return null;
}
Also used : DBNDatabaseItem(org.jkiss.dbeaver.model.navigator.DBNDatabaseItem) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ISelection(org.eclipse.jface.viewers.ISelection) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Example 9 with ISelection

use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.

the class NavigatorHandlerObjectCreateCopy method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode curNode = NavigatorUtils.getSelectedNode(selection);
    if (curNode != null) {
        Clipboard clipboard = new Clipboard(Display.getDefault());
        try {
            @SuppressWarnings("unchecked") Collection<DBNNode> cbNodes = (Collection<DBNNode>) clipboard.getContents(TreeNodeTransfer.getInstance());
            if (cbNodes != null) {
                for (DBNNode nodeObject : cbNodes) {
                    if (nodeObject instanceof DBNDatabaseNode) {
                        createNewObject(HandlerUtil.getActiveWorkbenchWindow(event), curNode, ((DBNDatabaseNode) nodeObject));
                    } else if (nodeObject instanceof DBNResource && curNode instanceof DBNResource) {
                        pasteResource((DBNResource) nodeObject, (DBNResource) curNode);
                    }
                }
            } else if (curNode instanceof DBNResource) {
                String[] files = (String[]) clipboard.getContents(FileTransfer.getInstance());
                if (files != null) {
                    for (String fileName : files) {
                        final File file = new File(fileName);
                        if (file.exists()) {
                            pasteResource(file, (DBNResource) curNode);
                        }
                    }
                } else {
                    UIUtils.showErrorDialog(HandlerUtil.getActiveShell(event), "Paste error", "Unsupported clipboard format. File or folder were expected.");
                }
            } else {
                UIUtils.showErrorDialog(HandlerUtil.getActiveShell(event), "Paste error", "Clipboard contains data in unsupported format");
            }
        } finally {
            clipboard.dispose();
        }
    }
    return null;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ISelection(org.eclipse.jface.viewers.ISelection) Collection(java.util.Collection) Clipboard(org.eclipse.swt.dnd.Clipboard) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IFile(org.eclipse.core.resources.IFile)

Example 10 with ISelection

use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.

the class NavigatorHandlerObjectCreateNew method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode node = NavigatorUtils.getSelectedNode(selection);
    if (node != null) {
        createNewObject(HandlerUtil.getActiveWorkbenchWindow(event), node, null);
    }
    return null;
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ISelection(org.eclipse.jface.viewers.ISelection)

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