Search in sources :

Example 36 with IEditorReference

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

the class MultiFilesOper method hasOpenedIFile.

/**
	 * 验证当前要合并打开的文件是否有文件存在已经打开的情况,并从当前要合并打开的文件中删除已经打开的文件
	 * <div style='color:red'>这个方法一是验证 所选要打开的文件 中是否已经有被打开了的,第二是,会删除已经打开的文件,因此慎用。<br>
	 *  getOpenedIfile 方法也有验证所选择文件是否有打开的情况</div>
	 * @return
	 */
public boolean hasOpenedIFile() {
    IEditorReference[] editorRes = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    List<IFile> isOpenedXlfList = new ArrayList<IFile>();
    IXliffEditor xlfEditor;
    boolean hasOpenedIFile = false;
    try {
        for (int i = 0; i < editorRes.length; i++) {
            if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
                IFile iFile = ((FileEditorInput) editorRes[i].getEditorInput()).getFile();
                //合并打开的情况
                if ("xlp".equals(iFile.getFileExtension())) {
                    System.out.println("---------------");
                    xlfEditor = (IXliffEditor) editorRes[i].getEditor(true);
                    isOpenedXlfList.addAll(ResourceUtils.filesToIFiles(xlfEditor.getMultiFileList()));
                } else {
                    try {
                        isOpenedXlfList.add(((FileEditorInput) editorRes[i].getEditorInput()).getFile());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        if (isOpenedXlfList.size() > 0) {
            for (IFile iFile : isOpenedXlfList) {
                if (selectIFiles.indexOf(iFile) >= 0) {
                    hasOpenedIFile = true;
                    selectIFiles.remove(iFile);
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    return hasOpenedIFile;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ArrayList(java.util.ArrayList) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException)

Example 37 with IEditorReference

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

the class MultiFilesOper method validExist.

/**
	 * 验证该合并打开的文件是否已经重复被打开,如果被合并打开,则返回true,未被打开,返回false.
	 * @param selectIFiles
	 * @return ;
	 */
public boolean validExist() {
    IEditorReference[] editorRes = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    for (int i = 0; i < editorRes.length; i++) {
        if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
            try {
                IFile iFile = ((FileEditorInput) editorRes[i].getEditorInput()).getFile();
                if (!"xlp".equals(iFile.getFileExtension())) {
                    continue;
                }
            } catch (Exception e) {
                LOGGER.error("", e);
            }
            boolean isRepeat = true;
            IXliffEditor xlfEditor = (IXliffEditor) editorRes[i].getEditor(true);
            List<IFile> mergerIFileList = ResourceUtils.filesToIFiles(xlfEditor.getMultiFileList());
            if (mergerIFileList.size() == selectIFiles.size()) {
                for (IFile curIFile : selectIFiles) {
                    if (mergerIFileList.indexOf(curIFile) < 0) {
                        isRepeat = false;
                        break;
                    }
                }
            } else {
                isRepeat = false;
            }
            if (isRepeat) {
                return true;
            }
        }
    }
    return false;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 38 with IEditorReference

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

the class PreTranslationHandler method execute.

@Override
public Object execute(ExecutionEvent event, List<IFile> list) {
    // 首先验证是否是合并打开的文件 --robert 2012-10-17
    if (isEditor) {
        try {
            IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
            IEditorReference[] editorRefe = window.getActivePage().findEditors(new FileEditorInput(list.get(0)), XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
            if (editorRefe.length <= 0) {
                return null;
            }
            IXliffEditor xlfEditor = (IXliffEditor) editorRefe[0].getEditor(true);
            // 针对合并打开
            if (xlfEditor.isMultiFile()) {
                list = ResourceUtils.filesToIFiles(xlfEditor.getMultiFileList());
            }
        } catch (ExecutionException e) {
            logger.error("", e);
        }
    }
    CommonFunction.removeRepeateSelect(list);
    PreTransUitls.executeTranslation(list, shell);
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorReference(org.eclipse.ui.IEditorReference) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ExecutionException(org.eclipse.core.commands.ExecutionException) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 39 with IEditorReference

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

the class QAResultViewPart method openMultiFilesEditor.

/**
	 * 处理合并打开文件 nattable editor的相关问题
	 * @return ;
	 */
public IXliffEditor openMultiFilesEditor() {
    IXliffEditor xliffEditor = null;
    FileEditorInput fileInput = new FileEditorInput(oper.getCurMultiTempFile());
    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 = (IXliffEditor) editorPart;
        // 若该文件未激活,激活此文件
        if (window.getActivePage().getActiveEditor() != editorPart) {
            window.getActivePage().activate(editorPart);
        }
        // 对于已经打开过的文件,进行重排序
        xliffEditor.resetOrder();
    } else {
        // 如果文件没有打开,那么先打开文件
        try {
            // 如果保存合并打开所有信息的临时文件已经被删除,那么,重新生成临时文件
            if (!oper.getCurMultiTempFile().getLocation().toFile().exists()) {
                // 检查这两个文件是否重新进行合并打开了的。
                IFile findMultiTempIfile = oper.getMultiFilesTempIFile(true);
                if (findMultiTempIfile != null) {
                    fileInput = new FileEditorInput(findMultiTempIfile);
                    oper.setCurMultiTempFile(findMultiTempIfile);
                } else {
                    //先验证这些所处理的文件是否有已经被打开的
                    List<IFile> openedFileList = oper.getOpenedIfile();
                    if (openedFileList.size() > 0) {
                        String openFileStr = "";
                        for (IFile ifile : openedFileList) {
                            openFileStr += "\t" + ifile.getFullPath().toOSString() + "\n";
                        }
                        MessageDialog.openInformation(getSite().getShell(), Messages.getString("views.QAResultViewPart.msgTitle"), MessageFormat.format(Messages.getString("qa.views.QAResultViewPart.addTip1"), openFileStr));
                        return null;
                    }
                    // 如果选中的文件没有合并打开,那么就重新打开它们
                    IFile multiIFile = oper.createMultiTempFile();
                    if (multiIFile != null && multiIFile.exists()) {
                        fileInput = new FileEditorInput(multiIFile);
                        oper.setCurMultiTempFile(multiIFile);
                    } else {
                        MessageDialog.openInformation(getSite().getShell(), Messages.getString("views.QAResultViewPart.msgTitle"), Messages.getString("views.QAResultViewPart.msg1"));
                        return null;
                    }
                    xliffEditor = (IXliffEditor) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                }
            }
        } catch (PartInitException e) {
            e.printStackTrace();
            logger.error(Messages.getString("qa.views.QAResultViewPart.log2"), e);
        }
    }
    return xliffEditor;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 40 with IEditorReference

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

the class MatchViewPart method loadData.

private synchronized void loadData(List<AltTransBean> matches) {
    if (matches == null) {
        return;
    }
    IEditorReference[] editorReferences = getSite().getPage().getEditorReferences();
    if (editorReferences.length == 0) {
        return;
    }
    for (AltTransBean altTransBean : matches) {
        String type = altTransBean.getMatchProps().get("hs:matchType");
        if (type == null || type.equals("")) {
            type = "others";
        }
        String orgin = altTransBean.getMatchOrigin();
        if (orgin == null) {
            // Fixed bug 2258 by Jason 翻译匹配面板不支持非 HS 工具匹配信息的显示
            orgin = "";
        }
        String srcContent = altTransBean.getSrcContent();
        if (srcContent == null || srcContent.equals("")) {
            continue;
        }
        String tgtContent = altTransBean.getTgtContent();
        if (tgtContent == null || tgtContent.equals("")) {
            continue;
        }
        String quality = altTransBean.getMatchProps().get("match-quality").trim();
        if (quality == null) {
            quality = "";
        } else {
            if (!quality.endsWith("%")) {
                quality += "%";
            }
        }
        String changeDate = null;
        String changeid = null;
        String creationDate = null;
        String creationid = null;
        Vector<PropGroupBean> propGroups = altTransBean.getPropGroups();
        StringBuffer toolTipBfTemp = new StringBuffer();
        if (propGroups != null) {
            for (PropGroupBean propGroupBean : propGroups) {
                List<PropBean> propBeans = propGroupBean.getProps();
                for (PropBean bean : propBeans) {
                    String ptype = bean.getProptype();
                    String pVal = bean.getValue();
                    if (ptype.equals("changeDate")) {
                        if (pVal != null && !pVal.equals("")) {
                            changeDate = DateUtils.formatDateFromUTC(pVal);
                        }
                    } else if (ptype.equals("changeId")) {
                        changeid = pVal;
                    } else if (ptype.equals("creationId")) {
                        creationid = pVal;
                    } else if (ptype.equals("creationDate")) {
                        if (pVal != null && !pVal.equals("")) {
                            creationDate = DateUtils.formatDateFromUTC(pVal);
                        }
                    } else {
                        toolTipBfTemp.append(ptype).append(" : ").append(pVal).append("\n");
                    }
                }
            }
        }
        StringBuffer toolTipBf = new StringBuffer();
        if (creationid != null && !creationid.equals("")) {
            toolTipBf.append(Messages.getString("view.MatchViewPart.info.tooltip.creationId")).append(creationid).append("\n");
        }
        if (creationDate != null && !creationDate.equals("")) {
            toolTipBf.append(Messages.getString("view.MatchViewPart.info.tooltip.creationDate")).append(creationDate).append("\n");
        }
        toolTipBf.append(toolTipBfTemp);
        StringBuffer msgBf = new StringBuffer();
        if (changeDate != null && !changeDate.equals("")) {
            msgBf.append(changeDate);
        }
        if (changeid != null && !changeid.equals("")) {
            if (msgBf.length() != 0) {
                msgBf.append("  |  ");
            }
            msgBf.append(changeid);
        }
        if (orgin != null && !orgin.equals("")) {
            if (msgBf.length() != 0) {
                msgBf.append("  |  ");
            }
            msgBf.append(orgin);
        }
        if (gridTable.isDisposed()) {
            return;
        }
        String toolId = altTransBean.getMatchProps().get("tool-id");
        GridItem gridItem = new GridItem(gridTable, SWT.NONE);
        gridItem.setText(0, srcContent);
        gridItem.setText(1, quality);
        gridItem.setText(2, tgtContent);
        gridItem.setToolTipText(0, toolId);
        gridItem.setToolTipText(1, toolId);
        gridItem.setToolTipText(2, toolId);
        // 保存信息
        gridItem.setData("info", resetSpecialString(msgBf.toString()));
        gridItem.setData("infoTooltip", resetSpecialString(toolTipBf.toString()));
        // 保存目标纯文本
        gridItem.setData("tgtText", altTransBean.getTgtText());
        // 保存目标纯文本
        gridItem.setData("tgtContent", tgtContent);
        gridItem.setData("matchType", type);
        gridItem.setData("quality", quality.substring(0, quality.lastIndexOf('%')));
        gridItem.setData("typeImage", getImageByType(type));
        gridItem.setData("tmFuzzyInfo", altTransBean.getFuzzyResult());
    }
}
Also used : PropGroupBean(net.heartsome.cat.ts.core.bean.PropGroupBean) AltTransBean(net.heartsome.cat.ts.core.bean.AltTransBean) IEditorReference(org.eclipse.ui.IEditorReference) GridItem(org.eclipse.nebula.widgets.grid.GridItem) PropBean(net.heartsome.cat.ts.core.bean.PropBean)

Aggregations

IEditorReference (org.eclipse.ui.IEditorReference)174 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)83 IEditorPart (org.eclipse.ui.IEditorPart)78 PartInitException (org.eclipse.ui.PartInitException)59 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)55 IFile (org.eclipse.core.resources.IFile)50 IEditorInput (org.eclipse.ui.IEditorInput)49 ArrayList (java.util.ArrayList)34 FileEditorInput (org.eclipse.ui.part.FileEditorInput)28 Item (org.talend.core.model.properties.Item)17 IWorkbench (org.eclipse.ui.IWorkbench)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 IOException (java.io.IOException)12 CoreException (org.eclipse.core.runtime.CoreException)12 ProcessItem (org.talend.core.model.properties.ProcessItem)11 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)10 Path (org.eclipse.core.runtime.Path)10 IProcess2 (org.talend.core.model.process.IProcess2)10