Search in sources :

Example 6 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart 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 7 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart 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 8 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project translationstudio8 by heartsome.

the class NextSplitPointHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    final Shell shell = window.getShell();
    XLIFFEditorImplWithNatTable xliffEditor = null;
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof IEditorPart) {
        if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
            xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
            List<String> splitPointList = xliffEditor.getSplitXliffPoints();
            if (splitPointList.size() <= 0) {
                MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("NextSplitPointHandler.msg.nullSplitPoint"));
                return null;
            }
            final XLFHandler xlfHander = xliffEditor.getXLFHandler();
            // 先对 splitPointList 进行排序
            Collections.sort(splitPointList, new Comparator<String>() {

                public int compare(String rowId1, String rowId2) {
                    int rowIndex1 = xlfHander.getRowIndex(rowId1);
                    int rowIndex2 = xlfHander.getRowIndex(rowId2);
                    return rowIndex1 > rowIndex2 ? 1 : -1;
                }
            });
            List<String> selectionRowIdList = xliffEditor.getSelectedRowIds();
            if (selectionRowIdList != null && selectionRowIdList.size() > 0) {
                curSelectionRowId = selectionRowIdList.get(0);
            }
            // 开始定位,定位之前让 nattable 恢复默认布局
            xliffEditor.resetOrder();
            if (curSelectionRowId == null) {
                curSelectionRowId = splitPointList.get(0);
            } else {
                int curSelectionRowIndex = xlfHander.getRowIndex(curSelectionRowId);
                for (String curRowId : splitPointList) {
                    int pointRowIndex = xlfHander.getRowIndex(curRowId);
                    if (pointRowIndex > curSelectionRowIndex) {
                        curSelectionRowId = curRowId;
                        xliffEditor.jumpToRow(curSelectionRowId);
                        break;
                    }
                }
            }
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Shell(org.eclipse.swt.widgets.Shell) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 9 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project translationstudio8 by heartsome.

the class SplitXliffHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    final String navegatorID = "net.heartsome.cat.common.ui.navigator.view";
    final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    final Shell shell = window.getShell();
    IFile selectFile = null;
    XLIFFEditorImplWithNatTable xliffEditor = null;
    List<Integer> splitXlfPointsIndex = new LinkedList<Integer>();
    List<String> splitXlfPointsRowId = new LinkedList<String>();
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    // 如果是导航视图,那么就获取导航视图中选中的文件
    if (activePart instanceof IViewPart) {
        if (navegatorID.equals(activePart.getSite().getId())) {
            IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(navegatorID);
            ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
            if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
                Object object = structuredSelection.getFirstElement();
                if (object instanceof IFile) {
                    selectFile = (IFile) object;
                    String fileExtension = selectFile.getFileExtension();
                    // 如果后缀名不是xlf,那么就退出操作
                    if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
                        MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
                        return null;
                    }
                    FileEditorInput fileInput = new FileEditorInput(selectFile);
                    IEditorReference[] editorRefer = window.getActivePage().findEditors(fileInput, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                    IEditorPart editorPart = null;
                    if (editorRefer.length >= 1) {
                        editorPart = editorRefer[0].getEditor(true);
                        xliffEditor = (XLIFFEditorImplWithNatTable) editorPart;
                        if (window.getActivePage().getActiveEditor() != editorPart) {
                            window.getActivePage().activate(editorPart);
                        }
                    } else {
                        try {
                            xliffEditor = (XLIFFEditorImplWithNatTable) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                        } catch (PartInitException e) {
                            LOGGER.error("", e);
                            e.printStackTrace();
                        }
                    }
                } else {
                    MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
                    return null;
                }
            }
        }
    } else if (activePart instanceof IEditorPart) {
        if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
            xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
            selectFile = ((FileEditorInput) xliffEditor.getEditorInput()).getFile();
        }
    }
    // 根据每个tu节点的rowId获取其具体的位置,才好进行排序
    Map<Integer, String> pointIndexRowIdMap = new HashMap<Integer, String>();
    for (String rowId : xliffEditor.getSplitXliffPoints()) {
        // 获取指定tu节点所处其他结点的序列号
        int tuPostion = xliffEditor.getXLFHandler().getTUPositionByRowId(rowId);
        if (tuPostion >= 1) {
            splitXlfPointsIndex.add(tuPostion);
            pointIndexRowIdMap.put(tuPostion, rowId);
        }
    }
    if (splitXlfPointsIndex.size() <= 0) {
        MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg2"));
        return null;
    }
    // 对切割点集合进行排序
    for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
        int point1 = splitXlfPointsIndex.get(i);
        for (int j = i + 1; j < splitXlfPointsIndex.size(); j++) {
            int point2 = splitXlfPointsIndex.get(j);
            if (point1 > point2) {
                splitXlfPointsIndex.set(i, point2);
                splitXlfPointsIndex.set(j, point1);
                point1 = point2;
            }
        }
    }
    // 向存储rowId的list存放数据,这样的话,所存储的rowId就是经过排序了的。
    for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
        splitXlfPointsRowId.add(pointIndexRowIdMap.get(splitXlfPointsIndex.get(i)));
    }
    SplitOrMergeXlfModel model = new SplitOrMergeXlfModel();
    model.setSplitFile(selectFile);
    model.setSplitXlfPointsIndex(splitXlfPointsIndex);
    model.setSplitXlfPointsRowId(splitXlfPointsRowId);
    model.setXliffEditor(xliffEditor);
    model.setShell(shell);
    SplitXliffWizard wizard = new SplitXliffWizard(model);
    final TSWizardDialog dialog = new NattableWizardDialog(shell, wizard);
    dialog.open();
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) SplitOrMergeXlfModel(net.heartsome.cat.ts.handlexlf.split.SplitOrMergeXlfModel) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SplitXliffWizard(net.heartsome.cat.ts.handlexlf.wizard.SplitXliffWizard) Shell(org.eclipse.swt.widgets.Shell) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) NattableWizardDialog(net.heartsome.cat.ts.handlexlf.wizard.NattableWizardDialog) IEditorPart(org.eclipse.ui.IEditorPart) LinkedList(java.util.LinkedList) FileEditorInput(org.eclipse.ui.part.FileEditorInput) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog)

Example 10 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project translationstudio8 by heartsome.

the class AbstractExportHandler method initExportConfig.

public boolean initExportConfig(ExecutionEvent event) throws ExecutionException {
    config = new ExportConfig();
    Shell shell = HandlerUtil.getActiveShell(event);
    String partId = HandlerUtil.getActivePartId(event);
    if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
        // 导航视图处于激活状态
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
        StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
        if (selection != null && !selection.isEmpty()) {
            for (Object obj : selection.toList()) {
                if (obj instanceof IFile) {
                    addXLFFile((IFile) obj);
                } else if (obj instanceof IFolder) {
                    traversalFile((IFolder) obj);
                } else if (obj instanceof IProject) {
                    IProject proj = (IProject) obj;
                    traversalFile(proj.getFolder(XLF));
                }
            }
            if (config.getProjects() == null || config.getProjects().size() < 1) {
                MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("xlf2tmx.info.notfoundxlf"));
                return false;
            }
        }
    } else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
        // nattable 处于激活状态
        IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
        IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
        IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        if (xliffEditor.isMultiFile()) {
            MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg2"));
            return false;
        } else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
            addXLFFile(iFile);
        }
    }
    return true;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ExportConfig(net.heartsome.cat.ts.ui.external.ExportConfig) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)50 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 IEditorPart (org.eclipse.ui.IEditorPart)17 ISelection (org.eclipse.jface.viewers.ISelection)16 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)12 ArrayList (java.util.ArrayList)11 Shell (org.eclipse.swt.widgets.Shell)11 IFile (org.eclipse.core.resources.IFile)10 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)10 IViewPart (org.eclipse.ui.IViewPart)10 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)10 IEditorInput (org.eclipse.ui.IEditorInput)8 Command (org.eclipse.gef.commands.Command)6 CommandStack (org.eclipse.gef.commands.CommandStack)6 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)5 PartInitException (org.eclipse.ui.PartInitException)5 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)5 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)4 Iterator (java.util.Iterator)3 IPartListener (org.eclipse.ui.IPartListener)3