Search in sources :

Example 21 with ISelection

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

the class AbstractCommentHandler method execute.

public final Object execute(ExecutionEvent event) throws ExecutionException {
    BaseTextEditor textEditor = BaseTextEditor.getTextEditor(HandlerUtil.getActiveEditor(event));
    if (textEditor != null) {
        ICommentsSupport commentsSupport = textEditor.getCommentsSupport();
        IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
        if (document != null && commentsSupport != null) {
            // get current text selection
            ISelectionProvider provider = textEditor.getSelectionProvider();
            if (provider != null) {
                ISelection selection = provider.getSelection();
                if (selection instanceof ITextSelection) {
                    ITextSelection textSelection = (ITextSelection) selection;
                    if (!textSelection.isEmpty()) {
                        try {
                            processAction(textEditor.getSelectionProvider(), commentsSupport, document, textSelection);
                        } catch (BadLocationException e) {
                            log.warn(e);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ICommentsSupport(org.jkiss.dbeaver.ui.ICommentsSupport) ISelection(org.eclipse.jface.viewers.ISelection) BaseTextEditor(org.jkiss.dbeaver.ui.editors.text.BaseTextEditor) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 22 with ISelection

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;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)

Example 23 with ISelection

use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.

the class TermDbManagerDialog method initTreePopMenu.

/**
	 * 初始化树右键菜单 ;
	 */
private void initTreePopMenu() {
    MenuManager menuManager = new MenuManager("");
    menuManager.add(new Action(Messages.getString("dialog.TermDbManagerDialog.deleteAction")) {

        @Override
        public void run() {
            ISelection selection = getTreeViewer().getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            if (obj instanceof DatabaseModelBean) {
                List<DatabaseModelBean> currDbTypeServers = treeInputMap.get(currDbType);
                configer.deleteServerById(((DatabaseModelBean) obj).getId());
                int i = currDbTypeServers.indexOf(obj);
                currDbTypeServers.remove(i);
                getTreeViewer().refresh();
                if (currDbTypeServers.size() != 0) {
                    if (i > currDbTypeServers.size() - 1) {
                        setLastSelectedServer(currDbTypeServers.get(i - 1).getId());
                    } else {
                        setLastSelectedServer(currDbTypeServers.get(i).getId());
                    }
                    initUI(false);
                } else {
                    setLastSelectedServer(null);
                    initUI(true);
                }
                selectSaveItem();
            }
        }
    });
    Tree tree = treeViewer.getTree();
    this.treePopMenu = menuManager.createContextMenu(tree);
}
Also used : Action(org.eclipse.jface.action.Action) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) MenuManager(org.eclipse.jface.action.MenuManager) ISelection(org.eclipse.jface.viewers.ISelection) Tree(org.eclipse.swt.widgets.Tree) WritableList(org.eclipse.core.databinding.observable.list.WritableList) List(java.util.List) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 24 with ISelection

use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.

the class TermDbManagerDialog method executeSelectDatabase.

/**
	 * 当使用该对话框作为数据库选择时 ;
	 */
private void executeSelectDatabase() {
    ISelection selection = getDbTableViewer().getSelection();
    if (selection.isEmpty()) {
        return;
    }
    hasSelected = new HashMap<DatabaseModelBean, String>();
    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
    Iterator<?> it = structuredSelection.iterator();
    while (it.hasNext()) {
        DatabaseManagerDbListBean dbBean = (DatabaseManagerDbListBean) it.next();
        DatabaseModelBean dbModelBean = new DatabaseModelBean();
        currServer.copyToOtherIntance(dbModelBean);
        dbModelBean.setDbName(dbBean.getDbName());
        // Fix Bug #3290 导出TMX/TBX--导出内容异常 去掉语言前后的空格
        hasSelected.put(dbModelBean, dbBean.getLangs().replace(" ", ""));
    }
}
Also used : DatabaseManagerDbListBean(net.heartsome.cat.database.ui.bean.DatabaseManagerDbListBean) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 25 with ISelection

use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.

the class AbstractSelectProjectFilesHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    shell = HandlerUtil.getActiveShell(event);
    isEditor = false;
    // UNDO 如果焦点在其他视图上时,获取的文件错误。
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    if (selection == null || !(selection instanceof StructuredSelection) || selection.isEmpty()) {
        MessageDialog.openInformation(shell, Messages.getString("handlers.AbstractSelectProjectFilesHandler.msgTitle"), Messages.getString("handlers.AbstractSelectProjectFilesHandler.msg1"));
        return null;
    }
    StructuredSelection structuredSelection = (StructuredSelection) selection;
    IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
    String partId = HandlerUtil.getActivePartIdChecked(event);
    if (part instanceof IEditorPart) {
        // 当前焦点在编辑器
        IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
        IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
        isEditor = true;
        ArrayList<IFile> list = new ArrayList<IFile>();
        //代替 Arrays.asList(iFile)
        list.add(iFile);
        return execute(event, list);
    } else if ("net.heartsome.cat.common.ui.navigator.view".equals(partId)) {
        // 当前焦点在导航视图
        ArrayList<IFile> list = new ArrayList<IFile>();
        ArrayList<IFile> wrongFiles = new ArrayList<IFile>();
        String projectName = null;
        @SuppressWarnings("unchecked") Iterator<IResource> iterator = structuredSelection.iterator();
        while (iterator.hasNext()) {
            IResource resource = iterator.next();
            if (projectName == null) {
                projectName = resource.getProject().getName();
            } else {
                if (!projectName.equals(resource.getProject().getName())) {
                    MessageDialog.openInformation(shell, Messages.getString("handlers.AbstractSelectProjectFilesHandler.msgTitle"), Messages.getString("handlers.AbstractSelectProjectFilesHandler.msg2"));
                    return null;
                }
            }
            if (resource instanceof IFile) {
                IFile file = (IFile) resource;
                String fileExtension = file.getFileExtension();
                if (getLegalFileExtensions() == null || getLegalFileExtensions().length == 0) {
                    // 未限制后缀名的情况
                    list.add(file);
                } else {
                    // 限制了后缀名的情况
                    if (fileExtension == null) {
                        // 无后缀名的文件
                        fileExtension = "";
                    }
                    if (CommonFunction.containsIgnoreCase(getLegalFileExtensions(), fileExtension)) {
                        list.add(file);
                    } else {
                        wrongFiles.add(file);
                    }
                }
            } else if (resource instanceof IContainer) {
                // IContainer 包含 IFolder、IPorject。
                try {
                    ResourceUtils.getFiles((IContainer) resource, list, getLegalFileExtensions());
                } catch (CoreException e) {
                    LOGGER.error(MessageFormat.format(Messages.getString("handlers.AbstractSelectProjectFilesHandler.msg3"), resource.getFullPath().toOSString()), e);
                    e.printStackTrace();
                }
            }
        }
        if (!wrongFiles.isEmpty()) {
            String msg = Messages.getString("handlers.AbstractSelectProjectFilesHandler.msg4");
            StringBuffer arg = new StringBuffer();
            for (IFile iFile : wrongFiles) {
                arg.append("\n").append(iFile.getFullPath().toOSString());
            }
            if (!MessageDialog.openConfirm(shell, Messages.getString("handlers.AbstractSelectProjectFilesHandler.msgTitle"), MessageFormat.format(msg.toString(), arg.toString()))) {
                return null;
            }
        }
        return execute(event, list);
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) IContainer(org.eclipse.core.resources.IContainer) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

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