Search in sources :

Example 66 with IViewPart

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

the class SetSplitPointByWordNumHandler 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;
    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("all.dialog.info"), Messages.getString("SetSplitPointHandler.cantSetPointToNotXlf"));
                    return null;
                }
            }
        }
    } else if (activePart instanceof IEditorPart) {
        if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
            xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
            if (xliffEditor.isMultiFile()) {
                MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("SetSplitPointByWOrdNumHandler.cantSetForMulty"));
                return null;
            }
            selectFile = ((FileEditorInput) xliffEditor.getEditorInput()).getFile();
        }
    }
    if (selectFile == null) {
        return null;
    }
    XLIFFEditorImplWithNatTable nattable = XLIFFEditorImplWithNatTable.getCurrent();
    final XLFHandler xlfHander = nattable.getXLFHandler();
    Map<String, Integer> rowWordNumMap = xlfHander.getSplitFileInfoForPointSetting(selectFile.getLocation().toOSString());
    if (rowWordNumMap.size() <= 1) {
        MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("SetSplitPointHandler.cantSetPointForTuNum"));
        return null;
    }
    List<String> splitPointList = nattable.getSplitXliffPoints();
    // 排序之前先过滤重复
    HashSet<String> set = new HashSet<String>(splitPointList);
    splitPointList.clear();
    splitPointList.addAll(set);
    // 先对 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<SegPointBean> segPointList = new ArrayList<SegPointBean>();
    if (splitPointList.size() > 0) {
        int segWordNum = 0;
        int i = 0;
        String pointRowId = splitPointList.get(i);
        for (Entry<String, Integer> entry : rowWordNumMap.entrySet()) {
            segWordNum += entry.getValue();
            if (pointRowId.equals(entry.getKey())) {
                segPointList.add(new SegPointBean(segWordNum));
                segWordNum = 0;
                i++;
                if (i < splitPointList.size()) {
                    pointRowId = splitPointList.get(i);
                }
            }
        }
        if (splitPointList.size() + 1 > segPointList.size()) {
            segPointList.add(new SegPointBean(segWordNum));
        }
    }
    SetSplitPointByWordNumDialog dialog = new SetSplitPointByWordNumDialog(shell, xlfHander, selectFile.getLocation().toOSString(), rowWordNumMap, segPointList);
    int openResult = dialog.open();
    if (openResult == IDialogConstants.OK_ID) {
        // 如果选择确定,那么在界面上生成分割点
        nattable.getSplitXliffPoints().clear();
        for (SegPointBean bean : segPointList) {
            if (bean.getRowId() != null && !bean.getRowId().isEmpty()) {
                nattable.getSplitXliffPoints().add(bean.getRowId());
            }
        }
        nattable.refresh();
    }
    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) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) 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) SetSplitPointByWordNumDialog(net.heartsome.cat.ts.handlexlf.dialog.SetSplitPointByWordNumDialog) HashSet(java.util.HashSet) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SegPointBean(net.heartsome.cat.ts.core.bean.SegPointBean) IEditorPart(org.eclipse.ui.IEditorPart) FileEditorInput(org.eclipse.ui.part.FileEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 67 with IViewPart

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

the class FileAnalysisHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    model = new FAModel();
    faItemId = event.getParameter("faItemId");
    allTUSize = 0;
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    shell = window.getShell();
    IFile multiTempIFile = null;
    IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
    ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
    if (HandlerUtil.getActivePart(event) instanceof IViewPart) {
        ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
        if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
            IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
            @SuppressWarnings("unchecked") Iterator<Object> selectIt = structuredSelection.iterator();
            while (selectIt.hasNext()) {
                Object object = selectIt.next();
                if (object instanceof IFile) {
                    IFile selectFile = (IFile) object;
                    String fileExtension = selectFile.getFileExtension();
                    // 如果后缀名不是xlf,那么就进行提示
                    if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
                        boolean isSure = MessageDialog.openConfirm(shell, Messages.getString("qa.all.dialog.warning"), MessageFormat.format(Messages.getString("qa.all.tip.notXliff"), new Object[] { selectFile.getFullPath() }));
                        if (!isSure) {
                            return null;
                        }
                    }
                    selectIFiles.add(selectFile);
                } else if (object instanceof IContainer) {
                    IContainer selectContainer = (IContainer) object;
                    try {
                        ResourceUtils.getXliffs(selectContainer, selectIFiles);
                    } catch (Exception e) {
                        e.printStackTrace();
                        logger.error(Messages.getString("qa.handlers.FileAnalysisHandler.log1"), e);
                    }
                }
            }
        }
    } else if (HandlerUtil.getActivePart(event) instanceof IEditorPart) {
        // 如果左边未选择品质检查的类型,那么,获取nattable中打开的文件
        IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
        String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
        if (activeEditor != null && !activeEditor.getSite().getId().equals(XLIFF_EDITOR_ID)) {
            MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.BatchQAHandler.tip2"));
            return null;
        }
        XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) activeEditor;
        isMultiFile = nattable.isMultiFile();
        multiTempIFile = ((FileEditorInput) nattable.getEditorInput()).getFile();
        if (isMultiFile) {
            List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
            for (String multiFileStr : multiFilesList) {
                selectIFiles.add(ResourceUtils.fileToIFile(multiFileStr));
            }
        } else {
            selectIFiles.add(multiTempIFile);
        }
    } else {
        MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip3"));
        return null;
    }
    CommonFunction.removeRepeateSelect(selectIFiles);
    if (selectIFiles.size() <= 0) {
        MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip1"));
        return null;
    }
    List<IFile> lstFiles = new ArrayList<IFile>();
    XLFValidator.resetFlag();
    for (IFile iFile : selectIFiles) {
        if (!XLFValidator.validateXliffFile(iFile)) {
            lstFiles.add(iFile);
        }
    }
    XLFValidator.resetFlag();
    selectIFiles.removeAll(lstFiles);
    if (selectIFiles.size() == 0) {
        return null;
    }
    // 判断要分析的文件是否是属于同一个项目中的.
    IProject project = selectIFiles.get(0).getProject();
    if (selectIFiles.size() >= 2) {
        for (int i = 1; i < selectIFiles.size(); i++) {
            if (selectIFiles.get(i).getProject() != project) {
                MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip2"));
                return null;
            }
        }
    }
    model.setAnalysisIFileList(selectIFiles);
    model.setShell(shell);
    model.setMultiFile(isMultiFile);
    if (isMultiFile) {
        model.setMultiTempIFile(multiTempIFile);
    }
    // 文件分析框的框名
    title = model.getAnalysisItemMap().get(faItemId).get(QAConstant.FA_ITEM_NAME);
    FileAnalysisDialog dialog = new FileAnalysisDialog(shell, model, title, faItemId);
    int result = dialog.open();
    if (result == IDialogConstants.OK_ID) {
        analysisFile(title);
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FileAnalysisDialog(net.heartsome.cat.ts.ui.qa.dialogs.FileAnalysisDialog) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) List(java.util.List) IContainer(org.eclipse.core.resources.IContainer) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorPart(org.eclipse.ui.IEditorPart) ExecutionException(org.eclipse.core.commands.ExecutionException) IProject(org.eclipse.core.resources.IProject) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FAModel(net.heartsome.cat.ts.core.qa.FAModel) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 68 with IViewPart

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

the class NumberOrTagConsisQAHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    boolean isMultiFile = false;
    IFile multiTempIFile = null;
    IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
    // 改为布局
    if (editorPart != null && editorPart instanceof XLIFFEditorImplWithNatTable) {
        String qaItem = event.getParameter("qaItemId");
        XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) editorPart;
        ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
        FileEditorInput input = (FileEditorInput) nattable.getEditorInput();
        // 首先判断是否是合并打开的文件
        if (nattable.isMultiFile()) {
            isMultiFile = true;
        }
        if (isMultiFile) {
            multiTempIFile = input.getFile();
            List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
            for (String filePath : multiFilesList) {
                selectIFiles.add(ResourceUtils.fileToIFile(filePath));
            }
        } else {
            selectIFiles.add(input.getFile());
        }
        QAModel model = new QAModel();
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        shell = window.getShell();
        // 先调用方法,查看品质检查结果视图是否处于显示状态,如果是显示的,就删除数据
        IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IViewPart view = workbenchPage.findView(QAResultViewPart.ID);
        if (view != null) {
            // 运行时,将结果视图中列表的数据清除
            ((QAResultViewPart) view).clearTableData();
        }
        QAResult qaResult = new QAResult();
        // 存储品质检查的检查项
        // model.setBatchQAItemIdList(getBatchQAItems());
        // 存储品质检查的检查时不包括的文本段
        model.setNotInclude(getNotIncludePara());
        // 给品质检查结果视图发出通告,本次检查对象为合并打开文件
        qaResult.firePropertyChange(isMultiFile, new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
        if (isMultiFile) {
            model.setMuliFiles(true);
            model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
        } else {
            model.setMuliFiles(false);
        }
        boolean isNumberQA = false;
        if (QAConstant.QA_NUMBER.equals(qaItem)) {
            isNumberQA = true;
        } else if (QAConstant.QA_TAG.equals(qaItem)) {
            isNumberQA = false;
        }
        List<String> fileList = new ArrayList<String>();
        for (IFile iFIle : selectIFiles) {
            fileList.add(iFIle.getLocation().toOSString());
        }
        qaResult.setFilePathList(fileList);
        HsMultiActiveCellEditor.commit(true);
        beginQA(selectIFiles, model, isNumberQA, qaResult);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) QAResult(net.heartsome.cat.ts.ui.qa.model.QAResult) QAResultViewPart(net.heartsome.cat.ts.ui.qa.views.QAResultViewPart) QAModel(net.heartsome.cat.ts.ui.qa.model.QAModel) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 69 with IViewPart

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

the class UpdateTMHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell shell = HandlerUtil.getActiveShell(event);
    String partId = HandlerUtil.getActivePartId(event);
    ArrayList<IFile> lstXliff = new ArrayList<IFile>();
    //		boolean isShowCurrentLangBtn = true;
    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();
        // ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
            List<?> lstObj = ((IStructuredSelection) selection).toList();
            for (Object obj : lstObj) {
                if (obj instanceof IFile) {
                    IFile file = (IFile) obj;
                    // Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
                    if (file.getFileExtension() != null && CommonFunction.validXlfExtension(file.getFileExtension())) {
                        lstXliff.add(file);
                    }
                } else if (obj instanceof IFolder) {
                    try {
                        ResourceUtils.getXliffs((IFolder) obj, lstXliff);
                    } catch (CoreException e) {
                        LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger1"), e);
                        MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg1"));
                    }
                } else if (obj instanceof IProject) {
                    try {
                        ResourceUtils.getXliffs((IProject) obj, lstXliff);
                    } catch (CoreException e) {
                        LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger2"), e);
                        MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg2"));
                    }
                }
            }
            CommonFunction.removeRepeateSelect(lstXliff);
            if (lstXliff.size() == 0) {
                MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
                return null;
            }
            Iterator<IFile> iterator = lstXliff.iterator();
            while (iterator.hasNext()) {
                IFile file = iterator.next();
                FileEditorInput editorInput = new FileEditorInput(file);
                IEditorPart editorPart = page.findEditor(editorInput);
                if (editorPart == null || (editorPart != null && !(editorPart instanceof IXliffEditor))) {
                    //						isShowCurrentLangBtn = false;
                    break;
                }
            }
        } else {
            MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
            return null;
        }
    } 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()) {
            List<String> lstFile = new XLFHandler().getMultiFiles(iFile);
            if (lstFile.size() > 0) {
                for (String filePath : lstFile) {
                    lstXliff.add(ResourceUtils.fileToIFile(filePath));
                }
            }
        } else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
            lstXliff.add(iFile);
        }
    }
    if (lstXliff.size() > 0) {
        if (lstXliff.size() > 1) {
            String projectPath = lstXliff.get(0).getProject().getFullPath().toOSString();
            for (int i = 1; i < lstXliff.size(); i++) {
                String projectPath2 = lstXliff.get(i).getProject().getFullPath().toOSString();
                if (!projectPath.equals(projectPath2)) {
                    MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg4"));
                    return null;
                }
            }
        }
        ArrayList<IFile> lstFiles = new ArrayList<IFile>();
        XLFValidator.resetFlag();
        for (IFile iFile : lstXliff) {
            if (!XLFValidator.validateXliffFile(iFile)) {
                lstFiles.add(iFile);
            }
        }
        XLFValidator.resetFlag();
        lstXliff.removeAll(lstFiles);
        if (lstXliff.size() == 0) {
            return null;
        }
        ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(lstXliff.get(0).getProject());
        if (projectConfig.getDefaultTMDb() == null) {
            MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg5"));
            return null;
        }
        UpdateTMWizard wizard = new UpdateTMWizard(lstXliff);
        TSWizardDialog dialog = new UpdateTMWizardDialog(shell, wizard);
        //			UpdateTMDialog dialog = new UpdateTMDialog(shell, isShowCurrentLangBtn, lstXliff);
        dialog.open();
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) UpdateTMWizard(net.heartsome.cat.database.ui.tm.wizard.UpdateTMWizard) Shell(org.eclipse.swt.widgets.Shell) UpdateTMWizardDialog(net.heartsome.cat.database.ui.tm.wizard.UpdateTMWizardDialog) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) ArrayList(java.util.ArrayList) List(java.util.List) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog) IEditorInput(org.eclipse.ui.IEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) IFolder(org.eclipse.core.resources.IFolder)

Example 70 with IViewPart

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

the class ExecuteBingTransHandler method execute.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof IXliffEditor)) {
        return null;
    }
    // check the google translation state: check the key availability
    PrefrenceParameters ps = PrefrenceParameters.getInstance();
    if (!ps.isBingState()) {
        MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteBingTransHandler.msgTitle"), Messages.getString("handler.ExecuteBingTransHandler.msg"));
        return null;
    }
    final IXliffEditor xliffEditor = (IXliffEditor) editor;
    final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return null;
    }
    ISimpleMatcher matcher = new SimpleMatcherBingImpl();
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher);
    }
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SimpleMatcherBingImpl(net.heartsome.cat.ts.machinetranslation.SimpleMatcherBingImpl) IViewPart(org.eclipse.ui.IViewPart) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) PrefrenceParameters(net.heartsome.cat.ts.machinetranslation.bean.PrefrenceParameters) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Aggregations

IViewPart (org.eclipse.ui.IViewPart)104 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)58 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)39 IEditorPart (org.eclipse.ui.IEditorPart)34 PartInitException (org.eclipse.ui.PartInitException)28 IViewReference (org.eclipse.ui.IViewReference)26 ArrayList (java.util.ArrayList)16 IFile (org.eclipse.core.resources.IFile)15 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)15 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)15 IEditorInput (org.eclipse.ui.IEditorInput)13 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)13 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)10 ITermViewPart (net.heartsome.cat.ts.ui.view.ITermViewPart)10 Shell (org.eclipse.swt.widgets.Shell)9 IEditorReference (org.eclipse.ui.IEditorReference)9 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)8 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)8 IProject (org.eclipse.core.resources.IProject)8