Search in sources :

Example 51 with ISelection

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

the class GenerateSQLContributor method getSelectionFromPart.

@Nullable
static IStructuredSelection getSelectionFromPart(IWorkbenchPart part) {
    if (part == null) {
        return null;
    }
    ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return null;
    }
    ISelection selection = selectionProvider.getSelection();
    if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
        return null;
    }
    return (IStructuredSelection) selection;
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Nullable(org.jkiss.code.Nullable)

Example 52 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 53 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 54 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)

Example 55 with ISelection

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

the class PortingActionProvider method fillContextMenu.

public void fillContextMenu(IMenuManager aMenu) {
    if (!contribute) {
        return;
    }
    Assert.isTrue(!disposed);
    ISelection selection = getContext().getSelection();
    if (!(selection instanceof IStructuredSelection) || ((IStructuredSelection) selection).size() > 1) {
        addSimplePortingMenus(aMenu);
    } else {
        addImportMenu(aMenu);
        addExportMenu(aMenu);
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

ISelection (org.eclipse.jface.viewers.ISelection)951 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)595 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)173 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)113 ArrayList (java.util.ArrayList)102 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)101 IResource (org.eclipse.core.resources.IResource)89 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)88 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)85 IFile (org.eclipse.core.resources.IFile)84 GridData (org.eclipse.swt.layout.GridData)80 Composite (org.eclipse.swt.widgets.Composite)67 PartInitException (org.eclipse.ui.PartInitException)66 ITextSelection (org.eclipse.jface.text.ITextSelection)65 IEditorPart (org.eclipse.ui.IEditorPart)65 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)65 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)58 SelectionEvent (org.eclipse.swt.events.SelectionEvent)57 GridLayout (org.eclipse.swt.layout.GridLayout)57 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)52