Search in sources :

Example 6 with ProjectConfiger

use of net.heartsome.cat.ts.core.file.ProjectConfiger in project translationstudio8 by heartsome.

the class UpdateTMWizard method performFinish.

public boolean performFinish() {
    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final boolean isDraft = page.isDraft();
    final boolean isApproved = page.isApproved();
    final boolean isSignedOff = page.isSignedOff();
    final boolean isTranslated = page.isTranslated();
    final boolean isLocked = page.isLocked();
    if (!isDraft && !isApproved && !isSignedOff && !isTranslated && !isLocked) {
        MessageDialog.openInformation(getShell(), Messages.getString("wizard.UpdateTMWizard.msgTitle"), Messages.getString("wizard.UpdateTMWizard.msg"));
        return false;
    }
    IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
    final int contextSize = ps.getInt(TMPreferenceConstants.CONTEXT_MATCH);
    final int tmxImportStrategy = ps.getInt(TMPreferenceConstants.TM_UPDATE);
    IRunnableWithProgress progress = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) {
            monitor.setTaskName(Messages.getString("dialog.UpdateTMDialog.jobTask1"));
            monitor.beginTask(Messages.getString("dialog.UpdateTMDialog.jobTask1"), lstXLIFF.size() * 2);
            for (final IFile xliffFile : lstXLIFF) {
                ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(xliffFile.getProject());
                DatabaseModelBean modelBean = projectConfig.getDefaultTMDb();
                FileEditorInput editorInput = new FileEditorInput(xliffFile);
                IEditorPart editorPart = activePage.findEditor(editorInput);
                // 选择所有语言
                XLFHandler handler = null;
                if (editorPart != null && editorPart instanceof IXliffEditor) {
                    // xliff 文件已用 XLIFF 编辑器打开
                    IXliffEditor xliffEditor = (IXliffEditor) editorPart;
                    handler = xliffEditor.getXLFHandler();
                } else {
                    // xliff 文件未打开
                    handler = new XLFHandler();
                }
                monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask2"));
                // 修改获取系统用户方式/*System.getProperty("user.name");*/
                String systemUser = PlatformUI.getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
                String[] arrTempTMX = handler.generateTMXToUpdateTM(xliffFile, isApproved, isSignedOff, isTranslated, isDraft, isLocked, contextSize, systemUser);
                monitor.worked(1);
                if (arrTempTMX != null) {
                    monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask3"));
                    // }
                    try {
                        DatabaseService.importTmxWithString(modelBean.toDbMetaData(), arrTempTMX[1], new SubProgressMonitor(monitor, 1), tmxImportStrategy, false, arrTempTMX[0]);
                    } catch (ImportException e) {
                        final String msg = e.getMessage();
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateTMDialog.job.msgTitle"), msg);
                            }
                        });
                        canFinish = false;
                        return;
                    }
                }
            }
            monitor.done();
            // 刷新项目
            ResourceUtils.refreshCurentSelectProject();
            canFinish = true;
        }
    };
    try {
        getContainer().run(true, true, progress);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return canFinish;
}
Also used : IFile(org.eclipse.core.resources.IFile) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ImportException(net.heartsome.cat.common.core.exception.ImportException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 7 with ProjectConfiger

use of net.heartsome.cat.ts.core.file.ProjectConfiger in project translationstudio8 by heartsome.

the class ArchiveFileExportOperation2 method getProjectSQLiteFiles.

/**
	 * @param project
	 * @param type
	 * @return ;
	 */
private List<File> getProjectSQLiteFiles(IProject project, int type) {
    ProjectConfiger projectConfiger = ProjectConfigerFactory.getProjectConfiger(project);
    ProjectInfoBean currentProjectConfig = projectConfiger.getCurrentProjectConfig();
    List<DatabaseModelBean> sqlDbs = null;
    if (TM == type) {
        sqlDbs = currentProjectConfig.getTmDb();
    } else if (TB == type) {
        sqlDbs = currentProjectConfig.getTbDb();
    }
    List<File> files = new ArrayList<File>();
    for (DatabaseModelBean bean : sqlDbs) {
        if ("SQLite".equals(bean.getDbType())) {
            File file = new File(getSqliteFilePath(bean));
            if (file.exists() && file.isFile()) {
                files.add(file);
            }
        }
    }
    return files;
}
Also used : ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ArrayList(java.util.ArrayList) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 8 with ProjectConfiger

use of net.heartsome.cat.ts.core.file.ProjectConfiger in project translationstudio8 by heartsome.

the class WordsFA method createFAResultHtml.

/**
	 * 生成字数分析结果html文件
	 * @return html文件的路径
	 */
public String createFAResultHtml() {
    allFolderList = new LinkedList<IContainer>();
    Date createDate = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String createTime = formatter.format(createDate);
    formatter = new SimpleDateFormat("yyyyMMdd-HHmmss");
    String htmlNameTime = formatter.format(createDate);
    IProject curProject = model.getAnalysisIFileList().get(0).getProject();
    String htmlName = "WordLog" + htmlNameTime + ".html";
    String htmlPath = curProject.getLocation().append("Intermediate").append("Report").append(htmlName).toOSString();
    File htmlFile = new File(htmlPath);
    if (!htmlFile.getParentFile().exists()) {
        htmlFile.getParentFile().mkdirs();
    }
    FileOutputStream output;
    try {
        output = new FileOutputStream(htmlPath);
        output.write(QAConstant.FA_HtmlDoctype.getBytes("UTF-8"));
        output.write("<html>\n".getBytes("UTF-8"));
        String headerNode = QAConstant.FA_htmlHeader;
        headerNode = headerNode.replace("###Title###", Messages.getString("qa.fileAnalysis.WordsFA.name1"));
        output.write(headerNode.getBytes("UTF-8"));
        output.write("\t<body>\n".getBytes("UTF-8"));
        output.write(("<p class=\"title\">" + Messages.getString("qa.all.fa.WordsFA") + "</p>").getBytes("UTF-8"));
        // ----------------<<<<<<start-- 下面是相关信息提示部份---------------------
        output.write("\t<div>\n".getBytes("UTF-8"));
        output.write("\t\t<table class=\"infoTableStyle\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n".getBytes("UTF-8"));
        // 记忆库
        String title = Messages.getString("qa.fa.info.tm");
        ProjectConfiger projectConfiger = ProjectConfigerFactory.getProjectConfiger(curProject);
        List<DatabaseModelBean> tmBeanList = projectConfiger.getAllTmDbs();
        StringBuffer tmInfoSB = new StringBuffer();
        if (tmBeanList.size() > 0) {
            for (DatabaseModelBean bean : tmBeanList) {
                tmInfoSB.append("\t\t\t<div style=\"margin-bottom: 2px;\">");
                String dbType = bean.getDbType();
                if ("MySQL 5.x".equals(dbType)) {
                    dbType = "MySQL";
                } else if ("MsSQL2005".equals(dbType)) {
                    dbType = "SQL Server";
                }
                tmInfoSB.append(dbType);
                String location = "";
                if ("Internal DB".equals(dbType) || "SQLite".equals(dbType)) {
                    location = bean.getItlDBLocation();
                } else {
                    location = bean.getHost() + ":" + bean.getPort();
                    if (":".equals(location)) {
                        location = "";
                    }
                }
                if (location != null && !"".equals(location.trim()) && !" : ".equals(location)) {
                    tmInfoSB.append(" ( " + location + " ) ");
                }
                tmInfoSB.append(": ");
                tmInfoSB.append(MessageFormat.format("{0}" + bean.getDbName() + "{1}", new Object[] { bean.isDefault() ? "<b>" : "", bean.isDefault() ? "</b>" : "" }));
                tmInfoSB.append("</div>\n");
            }
        } else {
            tmInfoSB.append("\t\t\t<div style=\"margin-bottom: 2px;\">");
            tmInfoSB.append("N/A");
            tmInfoSB.append("</div>\n");
        }
        String infoStr = QAConstant.FA_Report_Info.replace("###Title###", title).replace("###Content###", tmInfoSB.toString());
        output.write(infoStr.getBytes("UTF-8"));
        // 最底匹配率
        title = Messages.getString("qa.fa.info.newWordMatch");
        String content = newWordsMaxMatchRate + "%";
        infoStr = QAConstant.FA_Report_Info.replace("###Title###", title).replace("###Content###", content);
        output.write(infoStr.getBytes("UTF-8"));
        // 分析文件总数
        title = Messages.getString("qa.fa.info.fileSum");
        content = "" + model.getSubFileNum();
        infoStr = QAConstant.FA_Report_Info.replace("###Title###", title).replace("###Content###", content);
        output.write(infoStr.getBytes("UTF-8"));
        // 分析失败文件
        title = Messages.getString("qa.fa.info.errorFiles");
        StringBuffer errorFileSB = new StringBuffer();
        errorFileSB.append("\t\t\t<div style=\"margin-bottom: 2px;\">");
        errorFileSB.append(model.getErrorIFileList().size());
        errorFileSB.append("</div>");
        for (IFile iFile : model.getErrorIFileList()) {
            errorFileSB.append("\t\t\t<div style=\"margin-bottom: 2px;\">");
            errorFileSB.append(iFile.getFullPath().toOSString());
            errorFileSB.append("</div>");
        }
        infoStr = QAConstant.FA_Report_Info.replace("###Title###", title).replace("###Content###", errorFileSB.toString());
        output.write(infoStr.getBytes("UTF-8"));
        // 报告生成时间
        title = Messages.getString("qa.fa.info.createTime");
        infoStr = QAConstant.FA_Report_Info.replace("###Title###", title).replace("###Content###", createTime);
        output.write(infoStr.getBytes("UTF-8"));
        output.write("</table></div><br>\n".getBytes("UTF-8"));
        // ---------------->>>>>>end-- 报表信息提示部分结束---------------------
        int paddLeft = 6;
        String folderId = curProject.getFullPath().toOSString();
        getAllFolder(curProject, allFolderList);
        // 向所有的文件夹传值
        setDataToFolder(curProject);
        // 首先写下项目
        WordsFAResult proFaResult = WordsFAResultMap.get(curProject.getLocation().toOSString());
        // --------------数据库匹配率区间---------------------
        output.write(("\t\t<div class=\"legendStyle\"><b>" + Messages.getString("qa.fileAnalysis.WordsFA.wordsFA") + "</b></div>").getBytes("UTF-8"));
        StringBuffer exterFAdata = new StringBuffer();
        //"100-101:0.5;89-99:0.4"
        String[] equivArray = equivStr.split(";");
        int length = equivArray.length;
        // 是否有 上下文匹配
        boolean hasExter101 = equivStr.indexOf("external101") != -1;
        int interMathNum = 0;
        if (interRepeat && !interMatch) {
            interMathNum = 1;
        } else if (interRepeat && interMatch) {
            interMathNum = length - (hasExter101 ? 2 : 1);
        }
        //要显示列的总数(文件列是普通列的三倍)
        int columLength = length - 1 + interMathNum + 3 + 4;
        float width = (float) 100 / columLength;
        //开始创建表头
        exterFAdata.append("\t<table class='tableStyle' cellpadding='0' cellspacing='1'> \n");
        // 表头
        exterFAdata.append("\t\t<tr>\n");
        exterFAdata.append("\t\t\t<td class='headerTd' rowSpan='2' width='" + 3 * width + "%'>" + Messages.getString("qa.all.fa.fileName") + "</td>\n");
        exterFAdata.append("\t\t\t<td class='headerTd' colSpan='" + (length - 1) + "' width='" + (length - 1) * width + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.exterMatch") + "</td>\n");
        if (interRepeat) {
            exterFAdata.append("\t\t\t<td class='headerTd' colSpan='" + interMathNum + "' width='" + interMathNum * width + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.interMatch") + "</td>\n");
        }
        exterFAdata.append("\t\t\t<td class='headerTd' rowSpan='2' width='" + width + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.newWordsNum") + "</td>\n");
        exterFAdata.append("\t\t\t<td class='headerTd' rowSpan='2' width='" + width + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.equivWordsNum") + "</td>\n");
        exterFAdata.append("\t\t\t<td class='headerTd' rowSpan='2' width='" + width + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.lockWordsNum") + "</td>\n");
        exterFAdata.append("\t\t\t<td class='headerTd' rowSpan='2' width='" + width + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.wordsSum") + "</td>\n");
        exterFAdata.append("\t\t</tr>\n");
        exterFAdata.append("\t\t<tr>\n");
        //这是创建显示结果的外部匹配部份
        for (int i = 0; i < length; i++) {
            String matchPair = equivArray[i].substring(0, equivArray[i].indexOf(":"));
            String className = "headerTd";
            if (QAConstant._External101.equals(matchPair)) {
                exterFAdata.append("\t\t\t<td class='" + className + "' width='" + width + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.contentMath") + "</td>\n");
            } else if (QAConstant._External100.equals(matchPair)) {
                exterFAdata.append("\t\t\t<td class='" + className + "' width='" + width + "%'>" + "100%" + "</td>\n");
            } else if (!QAConstant._InternalRepeat.equals(matchPair)) {
                matchPair = matchPair.substring(0, matchPair.indexOf("-")) + "%" + matchPair.substring(matchPair.indexOf("-"), matchPair.length()) + "%";
                exterFAdata.append("\t\t\t<td class='" + className + "' width='" + width + "%'>" + matchPair + "</td>\n");
            }
        }
        //这是创建显示结果的内部匹配部份
        for (int i = 0; i < length; i++) {
            String matchPair = equivArray[i].substring(0, equivArray[i].indexOf(":"));
            String className = "headerTd";
            if (interRepeat && QAConstant._InternalRepeat.equals(matchPair)) {
                exterFAdata.append("\t\t\t<td class='" + className + "' width='" + width + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.contentRepeat") + "</td>\n");
            } else if (interMatch && matchPair.indexOf("external") == -1) {
                matchPair = matchPair.substring(0, matchPair.indexOf("-")) + "%" + matchPair.substring(matchPair.indexOf("-"), matchPair.length()) + "%";
                exterFAdata.append("\t\t\t<td class='" + className + "' width='" + width + "%'>" + matchPair + "</td>\n");
            }
        }
        exterFAdata.append("\t\t</tr>\n");
        // 首先写下项目
        exterFAdata.append("<tr onmouseover= \"this.bgColor= '#F1F1FC'\" onmouseout= \"this.bgColor='#FFFFFF'\" bgcolor='#FFFFFF'>\n" + "<td class='folderTd' style='padding-left: 6'><a href='javascript:void(0)' id='" + folderId + "' name='allExter' class='link'  " + "title='" + Messages.getString("qa.all.fa.clickToShrink") + "' onclick='clickFolder(id, name)' >" + "<span id='" + folderId + "_span'>-</span> " + curProject.getName() + "</a></td>\n");
        //项目的外部匹配部份
        for (int i = 0; i < length; i++) {
            String matchPair = equivArray[i].substring(0, equivArray[i].indexOf(":"));
            String className = "folderTd";
            if (QAConstant._External101.equals(matchPair)) {
                exterFAdata.append("\t\t\t<td class='" + className + "' align='right'>" + proFaResult.getExterMatch("101") + "</td>\n");
            } else if (QAConstant._External100.equals(matchPair)) {
                exterFAdata.append("\t\t\t<td class='" + className + "' align='right'>" + proFaResult.getExterMatch("100") + "</td>\n");
            } else if (!QAConstant._InternalRepeat.equals(matchPair)) {
                exterFAdata.append("\t\t\t<td class='" + className + "' align='right'>" + proFaResult.getExterMatch(matchPair) + "</td>\n");
            }
        }
        //项目的内部匹配部份
        for (int i = 0; i < length; i++) {
            String matchPair = equivArray[i].substring(0, equivArray[i].indexOf(":"));
            String className = "folderTd";
            if (interRepeat && QAConstant._InternalRepeat.equals(matchPair)) {
                exterFAdata.append("\t\t\t<td class='" + className + "' align='right'>" + proFaResult.getInterMatch("100-101") + "</td>\n");
            } else if (interMatch && matchPair.indexOf("external") == -1) {
                exterFAdata.append("\t\t\t<td class='" + className + "' align='right'>" + proFaResult.getInterMatch(matchPair) + "</td>\n");
            }
        }
        //新字数,锁定字数,总字数
        exterFAdata.append("\t\t\t<td class='folderTd' align='right'>" + proFaResult.getNewWords() + "</td>\n");
        exterFAdata.append("\t\t\t<td class='folderTd' align='right'>" + proFaResult.getEqalWords(equivStr) + "</td>\n");
        exterFAdata.append("\t\t\t<td class='folderTd' align='right'>" + proFaResult.getLockedWords() + "</td>\n");
        exterFAdata.append("\t\t\t<td class='folderTd' align='right'>" + proFaResult.getTotalWords() + "</td>\n");
        exterFAdata.append("</tr>");
        allExterMatchSetInputData(curProject, exterFAdata, paddLeft, equivArray);
        exterFAdata.append("\t</table>\n");
        output.write(exterFAdata.toString().getBytes("UTF-8"));
        // --------------文本段---------------------
        output.write("<br/>\n".getBytes("UTF-8"));
        output.write(("\t\t\t<div class=\"legendStyle\"><b>" + Messages.getString("qa.fileAnalysis.WordsFA.paragraph") + "</b></div>").getBytes("UTF-8"));
        StringBuffer paraFAdata = new StringBuffer();
        int paraTableColumnNum = 4 + 3;
        if (interRepeat && !interMatch) {
            // 文件名列占两个单位的长度
            paraTableColumnNum = 5 + 3;
        } else if (interRepeat && interMatch) {
            paraTableColumnNum = 6 + 3;
        }
        float paraCloumnWidth = (float) 100 / paraTableColumnNum;
        // 创建一个表
        paraFAdata.append("\t<table class='tableStyle' cellpadding='0' cellspacing='1'> \n");
        // 表头
        paraFAdata.append("\t\t<tr>\n");
        paraFAdata.append("\t\t\t<td class='headerTd' width='" + 2 * paraCloumnWidth + "%'>" + Messages.getString("qa.all.fa.fileName") + "</td>\n");
        paraFAdata.append("\t\t\t<td class='headerTd' width='" + paraCloumnWidth + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.newPara") + "</td>\n");
        if (interMatch) {
            paraFAdata.append("\t\t\t<td class='headerTd' width='" + paraCloumnWidth + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.interMatchPara") + "</td>\n");
        }
        paraFAdata.append("\t\t\t<td class='headerTd' width='" + paraCloumnWidth + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.exterMatchPara") + "</td>\n");
        if (interRepeat) {
            paraFAdata.append("\t\t\t<td class='headerTd' width='" + paraCloumnWidth + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.interRepeatPara") + "</td>\n");
        }
        paraFAdata.append("\t\t\t<td class='headerTd' width='" + paraCloumnWidth + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.exterRepeatPara") + "</td>\n");
        paraFAdata.append("\t\t\t<td class='headerTd' width='" + paraCloumnWidth + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.lockedPara") + "</td>\n");
        paraFAdata.append("\t\t\t<td class='headerTd' width='" + paraCloumnWidth + "%'>" + Messages.getString("qa.fileAnalysis.WordsFA.paraSum") + "</td>\n");
        paraFAdata.append("\t\t</tr>\n");
        // 首先写下项目
        paddLeft = 6;
        paraFAdata.append("<tr onmouseover= \"this.bgColor= '#F1F1FC'\" onmouseout= \"this.bgColor='#FFFFFF'\" bgcolor='#FFFFFF'>\n" + "<td class='folderTd' style='padding-left: 6'><a href='javascript:void(0)' id='" + folderId + "' name='paras' class='link'  " + "title='" + Messages.getString("qa.all.fa.clickToShrink") + "' onclick='clickFolder(id, name)' ><span id='" + folderId + "_span'>-</span> " + curProject.getName() + "</a></td>\n" + "<td class='folderTd' align='right'>" + proFaResult.getNewPara() + "</td>\n" + (interMatch ? "<td class='folderTd' align='right'>" + proFaResult.getInterMatchPara() + "</td>\n" : "") + "<td class='folderTd' align='right'>" + proFaResult.getExterMatchPara() + "</td>\n" + (interRepeat ? "<td class='folderTd' align='right'>" + proFaResult.getInterRepeatPara() + "</td>\n" : "") + "<td class='folderTd' align='right'>" + proFaResult.getExterRepeatPara() + "</td>\n" + "<td class='folderTd' align='right'>" + proFaResult.getLockedPara() + "</td>\n" + "<td class='folderTd' align='right'>" + proFaResult.getTotalPara() + "</td>\n" + "</tr>");
        paraSetInputData(curProject, paraFAdata, paddLeft);
        paraFAdata.append("\t</table>\n");
        output.write(paraFAdata.toString().getBytes("UTF-8"));
        //			output.write("\t\t</fieldset><br/>\n".getBytes("UTF-8"));
        /*			String htmlPathDiv = "<div style='width:100%;font-size:14;color:blue;'>"
					+ Messages.getString("qa.all.fa.fileLocation")
					+ curProject.getFullPath().append("Report").append(htmlName).toOSString() + "</div>";
			output.write(htmlPathDiv.getBytes("UTF-8"));*/
        output.write("\t</body>\n".getBytes("UTF-8"));
        output.write("</html>".getBytes("UTF-8"));
        output.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        logger.error(Messages.getString("qa.fileAnalysis.WordsFA.log6"), e);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        logger.error(Messages.getString("qa.fileAnalysis.WordsFA.log7"), e);
    } catch (IOException e) {
        e.printStackTrace();
        logger.error(Messages.getString("qa.fileAnalysis.WordsFA.log8"), e);
    }
    return htmlPath;
}
Also used : IFile(org.eclipse.core.resources.IFile) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) WordsFAResult(net.heartsome.cat.ts.ui.qa.model.WordsFAResult) Date(java.util.Date) IProject(org.eclipse.core.resources.IProject) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) FileOutputStream(java.io.FileOutputStream) IContainer(org.eclipse.core.resources.IContainer) SimpleDateFormat(java.text.SimpleDateFormat) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 9 with ProjectConfiger

use of net.heartsome.cat.ts.core.file.ProjectConfiger 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 10 with ProjectConfiger

use of net.heartsome.cat.ts.core.file.ProjectConfiger in project translationstudio8 by heartsome.

the class TermViewerBodyMenu method getDbOperator.

DBOperator getDbOperator(IProject project) {
    if (null == project) {
        return null;
    }
    ProjectConfiger projectConfiger = ProjectConfigerFactory.getProjectConfiger(project);
    List<DatabaseModelBean> termBaseDbs = projectConfiger.getTermBaseDbs(true);
    if (null == termBaseDbs || termBaseDbs.isEmpty()) {
        return null;
    }
    return DatabaseService.getDBOperator(termBaseDbs.get(0).toDbMetaData());
}
Also used : ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean)

Aggregations

ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)11 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)7 IFile (org.eclipse.core.resources.IFile)5 ArrayList (java.util.ArrayList)4 ProjectInfoBean (net.heartsome.cat.common.bean.ProjectInfoBean)4 Language (net.heartsome.cat.common.locale.Language)4 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)4 IProject (org.eclipse.core.resources.IProject)4 CoreException (org.eclipse.core.runtime.CoreException)4 IEditorPart (org.eclipse.ui.IEditorPart)4 FileEditorInput (org.eclipse.ui.part.FileEditorInput)3 File (java.io.File)2 List (java.util.List)2 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 NavException (com.ximpleware.NavException)1 XPathEvalException (com.ximpleware.XPathEvalException)1