file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
TBXTemplateUtil.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.plugin/src/net/heartsome/cat/ts/ui/plugin/util/TBXTemplateUtil.java
package net.heartsome.cat.ts.ui.plugin.util; import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Vector; import javax.xml.parsers.ParserConfigurationException; import net.heartsome.util.CommonFunctions; import net.heartsome.xml.Catalogue; import net.heartsome.xml.Document; import net.heartsome.xml.Element; import net.heartsome.xml.SAXBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; /** * 该类与 net.heartsome.util.TbxTemplate 类似,由于 TbxTemplate 中的 XCS 模板路径是写在代码中的, * 不能直接调用,因此写了一个与 TbxTemplate 类似的类 * @author peason * @version * @since JDK1.6 */ public class TBXTemplateUtil { private static final Logger LOGGER = LoggerFactory.getLogger(TBXTemplateUtil.class); private Vector<Element> items; private String templateFileName; private String templatePath; private Document document; public static String teLevel = "termEntry"; //$NON-NLS-1$ public static String lsLevel = "langSet"; //$NON-NLS-1$ public static String termLevel = "term"; //$NON-NLS-1$ public static String termNoteSpec = "termNoteSpec"; //$NON-NLS-1$ public static String descripSpec = "descripSpec"; //$NON-NLS-1$ public static String adminSpec = "adminSpec"; public TBXTemplateUtil(String templateFile, String templatePath, String catalogueFile) throws Exception { this.templateFileName = templateFile; this.templatePath = templatePath; this.items = new Vector<Element>(); loadTemplate(catalogueFile); } public String getTemplateFileName() { return templateFileName; } private void loadTemplate(String catalogueFile) throws SAXException, ParserConfigurationException, IOException { SAXBuilder builder = new SAXBuilder(); if (!catalogueFile.equals("")) { //$NON-NLS-1$ Catalogue cat = new Catalogue(catalogueFile); builder.setEntityResolver(cat); builder.setValidating(true); } File templateFile = new File(templatePath, templateFileName); //$NON-NLS-1$ document = builder.build(templateFile.getAbsolutePath()); Element tbxXCS = document.getRootElement(); Element datCatSet = tbxXCS.getChild("datCatSet"); //$NON-NLS-1$ if (datCatSet != null) { List<Element> specs = datCatSet.getChildren(); Iterator<Element> specsIt = specs.iterator(); while (specsIt.hasNext()) { Element spec = specsIt.next(); Element contents = spec.getChild("contents"); //$NON-NLS-1$ if (contents != null) { items.add(spec); } } } } public int getItemCount() { return items.size(); } public String getItemLevels(int item) { Element spec = items.get(item); Element levels = spec.getChild("levels"); //$NON-NLS-1$ if (levels != null) { return levels.getText(); } return ""; //$NON-NLS-1$ } public String getSpecName(int item) { Element spec = items.get(item); return spec.getName(); } public String getItemDescription(int item) { Element spec = items.get(item); String itemDesc = spec.getAttributeValue("display"); //$NON-NLS-1$ if (itemDesc.equals("")) { //$NON-NLS-1$ return getItemName(item); } return itemDesc; } public String getItemName(int item){ Element spec = items.get(item); return spec.getAttributeValue("name"); //$NON-NLS-1$ } public static Vector<String> getTemplateFiles(String catalogueFile, String templatePath, boolean needArray) { Vector<String> result = new Vector<String>(); File templateDir = new File(templatePath); String[] contents = templateDir.list(); if (contents != null) { for (int i = 0; i < contents.length; i++) { File currentFile = new File(templateDir.getAbsolutePath(), contents[i]); if (currentFile.isFile()) { try { SAXBuilder builder = new SAXBuilder(); if (!catalogueFile.equals("")) { //$NON-NLS-1$ Catalogue cat = new Catalogue(catalogueFile); builder.setEntityResolver(cat); } Document doc = builder.build(currentFile.getAbsolutePath()); Element tbxXCS = doc.getRootElement(); Element datCatSet = tbxXCS.getChild("datCatSet"); //$NON-NLS-1$ if (datCatSet != null) { result.add(currentFile.getName()); } } catch (Exception e) { LOGGER.error("", e); } } } } return result; } public static Vector<String> getTemplateFiles(String catalogueFile, boolean needArray) { return getTemplateFiles(catalogueFile, "templates", needArray); } public static String[] getTemplateFiles(String catalogueFile, String templatePath) { return CommonFunctions.Vector2StringArray(getTemplateFiles(catalogueFile, templatePath, false)); } }
4,715
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
Messages.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.plugin/src/net/heartsome/cat/ts/ui/plugin/resource/Messages.java
package net.heartsome.cat.ts.ui.plugin.resource; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * 国际化工具类 * @author peason * @version * @since JDK1.6 */ public class Messages { private static final String BUNDLE_NAME = "net.heartsome.cat.ts.ui.plugin.resource.message"; private static ResourceBundle BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); public static String getString(String key) { try { return BUNDLE.getString(key); } catch (MissingResourceException e) { return key; } } }
562
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
PreTranslation.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/PreTranslation.java
/** * PreTranslation.java * * Version information : * * Date:Dec 13, 2011 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.pretranslation; import java.io.BufferedOutputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Hashtable; import java.util.List; import java.util.Vector; import net.heartsome.cat.common.bean.FuzzySearchResult; import net.heartsome.cat.ts.core.bean.AltTransBean; import net.heartsome.cat.ts.core.bean.Constants; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.pretranslation.bean.PreTransParameters; import net.heartsome.cat.ts.pretranslation.bean.PreTranslationCounter; import net.heartsome.cat.ts.pretranslation.resource.Messages; import net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean; import net.heartsome.cat.ts.tm.match.TmMatcher; import net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher; import net.heartsome.cat.ts.tm.simpleMatch.SimpleMatcherFactory; import net.heartsome.cat.ts.ui.util.IntelligentTagPrcessor; import net.heartsome.cat.ts.ui.util.TmUtils; import net.heartsome.xml.vtdimpl.VTDUtils; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.SubProgressMonitor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ximpleware.AutoPilot; import com.ximpleware.ModifyException; import com.ximpleware.NavException; import com.ximpleware.TranscodeException; import com.ximpleware.VTDNav; import com.ximpleware.XMLModifier; import com.ximpleware.XPathEvalException; import com.ximpleware.XPathParseException; /** * 预翻译业务逻辑实现 * @author Jason * @version * @since JDK1.6 */ /** * @author Jason * @version * @since JDK1.6 */ public class PreTranslation { public static final Logger logger = LoggerFactory.getLogger(PreTranslation.class); private int updateStrategy; private PreTransParameters parameters; private IProject currentProject; private TmMatcher tmMatcher; /** 上下文个数 */ private int contextSize = 1; /** 项目中的XLIFF文件解析 */ private XLFHandler xlfHandler; /** 项目中的XLIFF文件路径,绝对路径 */ private List<String> xlfFiles; private List<PreTranslationCounter> transCounters; private PreTranslationCounter currentCounter; public PreTranslation(XLFHandler xlfHandler, List<String> xlfFiles, IProject currIProject, PreTransParameters parameters) { this.xlfHandler = xlfHandler; this.xlfFiles = xlfFiles; this.parameters = parameters; tmMatcher = new TmMatcher(); tmMatcher.setCustomeMatchParameters(tmMatcher.getMaxMatchSize(), parameters.getIgnoreTag(), parameters.getLowestMatchPercent(), !parameters.getIgnoreCase(), 1, parameters.getPanalty()); this.updateStrategy = parameters.getUpdateStrategy(); this.currentProject = currIProject; this.contextSize = tmMatcher.getContextSize(); transCounters = new ArrayList<PreTranslationCounter>(); } /** * 根据构建参数执行预翻译 ; * @throws InterruptedException */ public List<PreTranslationCounter> executeTranslation(IProgressMonitor monitor) throws InterruptedException { if (monitor == null) { monitor = new NullProgressMonitor(); } monitor.beginTask("", this.xlfFiles.size()); monitor.setTaskName(Messages.getString("pretranslation.PreTranslation.task1")); try { for (String xlfPath : xlfFiles) { if (monitor != null && monitor.isCanceled()) { throw new InterruptedException(); } currentCounter = new PreTranslationCounter(xlfPath); this.transCounters.add(currentCounter); VTDNav vn = xlfHandler.getVnMap().get(xlfPath); VTDUtils vu = new VTDUtils(vn); AutoPilot ap = new AutoPilot(vu.getVTDNav()); int tuNumber = xlfHandler.getNodeCount(xlfPath, "/xliff/file//descendant::trans-unit[(source/text()!='' or source/*)]"); currentCounter.setTuNumber(tuNumber); ap.selectXPath("/xliff/file"); String srcLang = ""; String tgtLang = ""; XMLModifier xm = new XMLModifier(vn); IProgressMonitor monitor2 = new SubProgressMonitor(monitor, 1); monitor2.beginTask(Messages.getString("pretranslation.PreTranslation.task2"), tuNumber); while (ap.evalXPath() != -1) { // 循环 file 节点 String _srcLang = vu.getCurrentElementAttribut("source-language", ""); String _tgtLang = vu.getCurrentElementAttribut("target-language", ""); if (!_srcLang.equals("")) { srcLang = _srcLang; } if (!_tgtLang.equals("")) { tgtLang = _tgtLang; } if (srcLang.equals("") || tgtLang.equals("")) { continue; } if (updateStrategy == PreTransParameters.KEEP_OLD_TARGET) { keepCurrentMatchs(vu, _srcLang, _tgtLang, xm, monitor2); } else if (updateStrategy == PreTransParameters.KEEP_BEST_MATCH_TARGET) { keepHigherMatchs(vu, _srcLang, _tgtLang, xm, monitor2); } else if (updateStrategy == PreTransParameters.KEEP_NEW_TARGET) { overwriteMatchs(vu, srcLang, tgtLang, xm, monitor2); } } monitor2.done(); FileOutputStream fos = new FileOutputStream(xlfPath); BufferedOutputStream bos = new BufferedOutputStream(fos); xm.output(bos); // 写入文件 bos.close(); fos.close(); } } catch (XPathParseException e) { logger.error("", e); e.printStackTrace(); } catch (NavException e) { logger.error("", e); e.printStackTrace(); } catch (ModifyException e) { logger.error("", e); e.printStackTrace(); } catch (XPathEvalException e) { logger.error("", e); e.printStackTrace(); } catch (UnsupportedEncodingException e) { logger.error("", e); e.printStackTrace(); } catch (FileNotFoundException e) { logger.error("", e); e.printStackTrace(); } catch (TranscodeException e) { logger.error("", e); e.printStackTrace(); } catch (IOException e) { logger.error("", e); e.printStackTrace(); } monitor.done(); return this.transCounters; } public void clearResources() { // 完成翻译后清除使用的资源 tmMatcher.clearResources(); this.transCounters.clear(); this.transCounters = null; } /** * 保留最大上限匹配数量 * @param tmpVector * ; */ private void checkMaxMatchSize(Vector<Hashtable<String, String>> tmpVector) { int size = tmpVector.size(); while (size > tmMatcher.getMaxMatchSize()) { size--; tmpVector.remove(size); } } private void keepCurrentMatchs(VTDUtils vu, String srcLang, String tgtLang, XMLModifier xm, IProgressMonitor monitor) throws NavException, XPathParseException, XPathEvalException, ModifyException, UnsupportedEncodingException, InterruptedException { AutoPilot tuAp = new AutoPilot(vu.getVTDNav()); tuAp.selectXPath("./body//trans-unit"); boolean needUpdateTgt = true; while (tuAp.evalXPath() != -1) { // 循环 Trans-unit if (monitor != null && monitor.isCanceled()) { throw new InterruptedException(); } // skip locked segment String locked = vu.getCurrentElementAttribut("translate", "yes"); if (locked.equals("no")) { continue; } String tgtContent = vu.getElementContent("./target"); if (tgtContent != null && !tgtContent.trim().equals("")) { needUpdateTgt = false; } TransUnitInfo2TranslationBean tuInfo = getTransUnitInfo(vu); if (tuInfo == null) { continue; } tuInfo.setSrcLanguage(srcLang); tuInfo.setTgtLangugage(tgtLang); getTuContext(vu, contextSize, tuInfo); List<FuzzySearchResult> result = tmMatcher.executeFuzzySearch(currentProject, tuInfo); updateXliffFile(vu, tuInfo, result, xm, needUpdateTgt); needUpdateTgt = true; monitor.worked(1); } } private void updateXliffFile(VTDUtils vu, TransUnitInfo2TranslationBean tuInfo, List<FuzzySearchResult> fuzzyResult, XMLModifier xm, boolean updateTarget) throws XPathParseException, XPathEvalException, NavException, ModifyException, UnsupportedEncodingException { String altTransContent = ""; String targetContent = ""; vu.delete(new AutoPilot(vu.getVTDNav()), xm, "./alt-trans[@tool-id='" + Constants.TM_TOOLID + "']", VTDUtils.PILOT_TO_END); if (!fuzzyResult.isEmpty()) { altTransContent = generateAltTransUnitNodeXML(fuzzyResult); } if (updateTarget && !fuzzyResult.isEmpty()) { vu.delete(new AutoPilot(vu.getVTDNav()), xm, "./target", VTDUtils.PILOT_TO_END); targetContent = generateTargetNodeXML(fuzzyResult.get(0), tuInfo); currentCounter.countTransTu(); } targetContent += altTransContent; String simpleMatchContent = ""; // executeSimpleMatch(vu, tuInfo, xm/* , updateTargetTemp */); targetContent += simpleMatchContent; if (targetContent.length() > 0) { xm.insertBeforeTail(targetContent); } if (fuzzyResult.size() > 0) { String similarity = fuzzyResult.get(0).getSimilarity() + ""; // 取最大匹配率的 if (parameters.isLockContextMatch() && similarity.equals("101")) { lockTransUnit(vu.getVTDNav(), xm); currentCounter.countLockedContextmatch(); } else if (parameters.isLockFullMatch() && similarity.equals("100")) { lockTransUnit(vu.getVTDNav(), xm); currentCounter.countLockedFullMatch(); } } } // private String defaultSimplematcher; private String executeSimpleMatch(VTDUtils vu, TransUnitInfo2TranslationBean tuInfo, XMLModifier xm/* * , boolean * updateTarget */) throws XPathParseException, XPathEvalException, NavException { List<ISimpleMatcher> simpleMatchers = SimpleMatcherFactory.getInstance().getCuurentMatcher(); StringBuffer bf = new StringBuffer(); /* * final List<String> toolIds = new ArrayList<String>(); if (defaultSimplematcher == null) { for (ISimpleMatcher * matcher : simpleMatchers) { if (matcher.isSuportPreTrans() && matcher.matchChecker()) { * toolIds.add(matcher.getMathcerToolId()); } } if (toolIds.size() > 1) { Display.getDefault().syncExec(new * Runnable() { * * @Override public void run() { Shell shell = Display.getCurrent().getActiveShell(); PromptDialog dlg = new * PromptDialog(shell, toolIds); if (dlg.open() == Window.OK) { defaultSimplematcher = dlg.getChoiceResult(); } * } }); } else if (toolIds.size() == 1) { defaultSimplematcher = toolIds.get(0); } else { defaultSimplematcher * = null; } } */ for (ISimpleMatcher matcher : simpleMatchers) { if (!matcher.isSuportPreTrans()) { continue; } String toolId = matcher.getMathcerToolId(); boolean isOverwrite = matcher.isOverwriteMatch(); boolean needClear = false; vu.getVTDNav().push(); AutoPilot ap = new AutoPilot(vu.getVTDNav()); ap.selectXPath("./alt-trans[@tool-id='" + toolId + "']"); if (ap.evalXPath() != -1) { if (!isOverwrite) { vu.getVTDNav().pop(); continue; } else { needClear = true; } } vu.getVTDNav().pop(); if (needClear) { vu.delete(new AutoPilot(vu.getVTDNav()), xm, "./alt-trans[@tool-id='" + toolId + "']", VTDUtils.PILOT_TO_END); } String tgtText = matcher.executeMatch(tuInfo); if (tgtText.equals("")) { continue; } /* * if (updateTarget && defaultSimplematcher.equals(toolId)) { vu.delete(new AutoPilot(vu.getVTDNav()), xm, * "./target", VTDUtils.PILOT_TO_END); bf.append("<target xml:lang=\"" + tuInfo.getTgtLangugage() + * "\" state=\"new\" hs:matchType=\"" + matcher.getMatcherType() + "\" hs:quality=\"100\">"); * bf.append(tgtText); bf.append("</target>"); * * currentCounter.countTransTu(); } */ AltTransBean bean = new AltTransBean(tuInfo.getSrcPureText(), tgtText, tuInfo.getSrcLanguage(), tuInfo.getTgtLangugage(), matcher.getMathcerOrigin(), matcher.getMathcerToolId()); bean.getMatchProps().put("match-quality", "100"); bean.setSrcContent(tuInfo.getSrcPureText()); bean.setTgtContent(tgtText); bean.getMatchProps().put("hs:matchType", matcher.getMatcherType()); bf.append(bean.toXMLString()); } return bf.toString(); } private void lockTransUnit(VTDNav vn, XMLModifier xm) throws NavException, ModifyException, UnsupportedEncodingException, XPathParseException, XPathEvalException { vn.push(); int attrIdx = vn.getAttrVal("translate"); if (attrIdx != -1) { // 存在translate属性 String translate = vn.toString(attrIdx); if (!translate.equals("no")) { // translate属性值不为指定的translateValue xm.updateToken(attrIdx, "no"); } } else { xm.insertAttribute(" translate=\"no\" "); } vn.pop(); } private boolean checkTuCurrentMatch(VTDUtils vu, Vector<Hashtable<String, String>> tmMatch) throws XPathParseException, XPathEvalException, NavException { if (tmMatch.size() == 0) { return false; } Vector<Hashtable<String, String>> currentMatch = new Vector<Hashtable<String, String>>(); vu.getVTDNav().push(); AutoPilot ap = new AutoPilot(vu.getVTDNav()); ap.selectXPath("./alt-trans[@tool-id='" + Constants.TM_TOOLID + "']"); int existMatchCount = 0; while (ap.evalXPath() != -1) { Hashtable<String, String> altTrans = new Hashtable<String, String>(); String quality = vu.getCurrentElementAttribut("match-quality", "0"); String srcText = vu.getElementContent("./source"); String tgtText = vu.getElementContent("./target"); if (srcText != null && tgtText != null) { altTrans.put("srcText", srcText); altTrans.put("tgtText", tgtText); } else { continue; } if (!isDuplicated(tmMatch, altTrans)) { String content = vu.getElementFragment(); altTrans.put("content", content); if (quality.endsWith("%")) { quality = quality.substring(0, quality.length() - 1); } altTrans.put("similarity", quality); altTrans.put("flag", "exist"); currentMatch.add(altTrans); } else { existMatchCount++; } } vu.getVTDNav().pop(); if (existMatchCount == tmMatch.size()) { // 库中查询的内容和文件中的内容是一样的 return false; } else { tmMatch.addAll(currentMatch); Collections.sort(tmMatch, new FindMatchComparator()); checkMaxMatchSize(tmMatch); return true; } } private TransUnitInfo2TranslationBean getTransUnitInfo(VTDUtils vu) throws XPathParseException, XPathEvalException, NavException { TransUnitInfo2TranslationBean tuInfo = new TransUnitInfo2TranslationBean(); vu.getVTDNav().push(); AutoPilot sourceAp = new AutoPilot(vu.getVTDNav()); sourceAp.selectXPath("./source"); String fullText = ""; String pureText = ""; if (sourceAp.evalXPath() != -1) { fullText = vu.getElementContent(); pureText = xlfHandler.getTUPureText(vu.getVTDNav()); } vu.getVTDNav().pop(); if (fullText == null || fullText.equals("") || pureText.equals("")) { return null; } tuInfo.setSrcFullText(fullText); tuInfo.setSrcPureText(pureText); return tuInfo; } private void getTuContext(VTDUtils vu, int contextSize, TransUnitInfo2TranslationBean tuInfo) { AutoPilot ap = new AutoPilot(vu.getVTDNav()); String preContext = xlfHandler.getContext(vu, ap, contextSize, true); String nextContext = xlfHandler.getContext(vu, ap, contextSize, false); tuInfo.setPreContext(preContext); tuInfo.setNextContext(nextContext); } private void keepHigherMatchs(VTDUtils vu, String srcLang, String tgtLang, XMLModifier xm, IProgressMonitor monitor) throws NavException, XPathParseException, XPathEvalException, ModifyException, UnsupportedEncodingException, InterruptedException { AutoPilot tuAp = new AutoPilot(vu.getVTDNav()); tuAp.selectXPath("./body//trans-unit"); boolean needUpdateTarget = false; while (tuAp.evalXPath() != -1) { // 循环 Trans-unit if (monitor != null && monitor.isCanceled()) { throw new InterruptedException(); } String locked = vu.getCurrentElementAttribut("translate", "yes"); if (locked.equals("no")) { continue; } //  ===从库中查询匹配=== TransUnitInfo2TranslationBean tuInfo = getTransUnitInfo(vu); if (tuInfo == null) { continue; } tuInfo.setSrcLanguage(srcLang); tuInfo.setTgtLangugage(tgtLang); getTuContext(vu, contextSize, tuInfo); List<FuzzySearchResult> result = tmMatcher.executeFuzzySearch(currentProject, tuInfo); // Vector<Hashtable<String, String>> tmMatches = tmMatcher.executeSearch(currentProject, tuInfo); //  ====查询结束=== if (!result.isEmpty()) { int matchMaxSimiInt = result.get(0).getSimilarity(); // ===获取当前目标的匹配率=== int currMaxSimInt = 0; vu.getVTDNav().push(); AutoPilot targetAp = new AutoPilot(vu.getVTDNav()); targetAp.selectXPath("./target"); if (targetAp.evalXPath() != -1) { String targetContent = vu.getElementContent(); if (targetContent != null && !targetContent.equals("")) { Hashtable<String, String> attrs = vu.getCurrentElementAttributs(); if (attrs != null) { String type = attrs.get("hs:matchType"); String quality = attrs.get("hs:quality"); if (type != null && type.equals("TM") && quality != null && !quality.equals("")) { currMaxSimInt = Integer.parseInt(quality); } else { //对于这种没有匹配率的 segment(手动翻译了,但是没入库,没锁定的情况。),需要覆盖2013-09-02, Austen。 currMaxSimInt = 1; } } } else { // target内容为空 needUpdateTarget = true; } } else { // 无target内容 needUpdateTarget = true; } vu.getVTDNav().pop(); if (currMaxSimInt != 0 && matchMaxSimiInt > currMaxSimInt) { needUpdateTarget = true; } } //  ===获取当前最大匹配结束=== updateXliffFile(vu, tuInfo, result, xm, needUpdateTarget); needUpdateTarget = false; monitor.worked(1); } } private void overwriteMatchs(VTDUtils vu, String srcLang, String tgtLang, XMLModifier xm, IProgressMonitor monitor) throws NavException, XPathParseException, XPathEvalException, ModifyException, UnsupportedEncodingException, InterruptedException { AutoPilot tuAp = new AutoPilot(vu.getVTDNav()); tuAp.selectXPath("./body//trans-unit"); while (tuAp.evalXPath() != -1) { // 循环 Trans-unit if (monitor != null && monitor.isCanceled()) { throw new InterruptedException(); } String locked = vu.getCurrentElementAttribut("translate", "yes"); if (locked.equals("no")) { continue; } TransUnitInfo2TranslationBean tuInfo = getTransUnitInfo(vu); if (tuInfo == null) { continue; } // System.out.println(tuInfo.getSrcFullText()); tuInfo.setSrcLanguage(srcLang); tuInfo.setTgtLangugage(tgtLang); getTuContext(vu, contextSize, tuInfo); // Vector<Hashtable<String, String>> result = tmMatcher.executeSearch(currentProject, tuInfo); List<FuzzySearchResult> result = tmMatcher.executeFuzzySearch(currentProject, tuInfo); updateXliffFile(vu, tuInfo, result, xm, true); monitor.worked(1); } } private boolean isDuplicated(Vector<Hashtable<String, String>> vector, Hashtable<String, String> tu) { int size = vector.size(); String src = tu.get("srcText"); //$NON-NLS-1$ String tgt = tu.get("tgtText"); //$NON-NLS-1$ for (int i = 0; i < size; i++) { Hashtable<String, String> table = vector.get(i); if (src.trim().equals(table.get("srcText").trim()) //$NON-NLS-1$ && tgt.trim().equals(table.get("tgtText").trim())) { //$NON-NLS-1$ return true; } } return false; } /** * 生成target节点 * @param target * @return ; */ private String generateTargetNodeXML(FuzzySearchResult fuzzyResult, TransUnitInfo2TranslationBean tuInfo) { String lang = fuzzyResult.getTu().getTarget().getLangCode(); String quality = fuzzyResult.getSimilarity() + ""; StringBuffer bf = new StringBuffer(); bf.append("<target xml:lang=\"" + lang + "\" state=\"new\" hs:matchType=\"TM\" hs:quality=\"" + quality + "\">"); String content = fuzzyResult.getTu().getTarget().getFullText(); String srcFullText = tuInfo.getSrcFullText(); String temp = IntelligentTagPrcessor.intelligentAppendTag(srcFullText, content); bf.append(temp); bf.append("</target>"); return bf.toString(); } /** * 根据匹配结果生成alt-trans节点 * @param altMatchs *  所有匹配信息 * @return 生成alt-trans节点; */ private String generateAltTransUnitNodeXML(List<FuzzySearchResult> fuzzyResults) { List<AltTransBean> altTransBeans = TmUtils.fuzzyResult2Alttransbean(fuzzyResults); StringBuffer bf = new StringBuffer(); for (AltTransBean bean : altTransBeans) { bf.append(bean.toXMLString()); } return bf.toString(); } /** * 字符串状态的匹配率排序器 * @author Jason * @version * @since JDK1.6 */ private final class SimilarityComparator implements Comparator<String> { public SimilarityComparator() { } public int compare(String o1, String o2) { try { Integer a = Integer.parseInt(o1.endsWith("%") ? o1.substring(0, o1.length() - 1) : o1); Integer b = Integer.parseInt(o2.endsWith("%") ? o2.substring(0, o2.length() - 1) : o2); if (a < b) { return 1; } else { return -1; } } catch (Exception e) { return 0; } } } /** * 查找匹配结果排序器 * @author Jason * @version * @since JDK1.6 */ private final class FindMatchComparator implements Comparator<Hashtable<String, String>> { public FindMatchComparator() { } public int compare(Hashtable<String, String> a, Hashtable<String, String> b) { Integer a1 = Integer.parseInt(a.get("similarity")); Integer b1 = Integer.parseInt(b.get("similarity")); if (a1 < b1) { return 1; } else { return -1; } } } }
22,418
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
Activator.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/Activator.java
package net.heartsome.cat.ts.pretranslation; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.ImageData; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ public class Activator extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "net.heartsome.cat.ts.pretranslation"; //$NON-NLS-1$ // The shared instance private static Activator plugin; /** * The constructor */ public Activator() { } /* * (non-Javadoc) * * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } /* * (non-Javadoc) * * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } /** * Returns the shared instance * @return the shared instance */ public static Activator getDefault() { return plugin; } /** * 提供一个图片文件对插件的相对路径,返回该图片的描述信息。 * @param path * 图片资源对插件的相对路径。 * @return the image descriptor */ public static ImageDescriptor getImageDescriptor(String path) { return imageDescriptorFromPlugin(PLUGIN_ID, path); } /** * 提供一个图片文件对插件的相对路径,返回该图片被伸缩变换为16*16像素的描述信息。 * @param path * the path * @return the icon descriptor */ public static ImageDescriptor getIconDescriptor(String path) { ImageDescriptor image = getImageDescriptor(path); ImageData data = image.getImageData(); data = data.scaledTo(16, 16); image = ImageDescriptor.createFromImageData(data); return image; } }
1,943
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
PreTransUitls.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/PreTransUitls.java
/** * PreTransUitls.java * * Version information : * * Date:2012-6-25 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.pretranslation; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import java.util.Map; import net.heartsome.cat.common.core.Constant; import net.heartsome.cat.common.file.XLFValidator; import net.heartsome.cat.common.resources.ResourceUtils; import net.heartsome.cat.ts.core.bean.XliffBean; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.pretranslation.bean.PreTransParameters; import net.heartsome.cat.ts.pretranslation.bean.PreTranslationCounter; import net.heartsome.cat.ts.pretranslation.dialog.PreTranslationDialog; import net.heartsome.cat.ts.pretranslation.dialog.PreTranslationResultDialog; import net.heartsome.cat.ts.pretranslation.resource.Messages; import net.heartsome.cat.ts.ui.editors.IXliffEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiCellEditorControl; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.FileEditorInput; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ximpleware.VTDGen; /** * @author jason * @version * @since JDK1.6 */ public class PreTransUitls { public static final Logger logger = LoggerFactory.getLogger(PreTransUitls.class); public static void executeTranslation(List<IFile> list, final Shell shell) { HsMultiActiveCellEditor.commit(true); try { if (list.size() == 0) { MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg1")); return; } List<IFile> lstFiles = new ArrayList<IFile>(); XLFValidator.resetFlag(); for (IFile iFile : list) { if (!XLFValidator.validateXliffFile(iFile)) { lstFiles.add(iFile); } } XLFValidator.resetFlag(); list = new ArrayList<IFile>(list); list.removeAll(lstFiles); if (list.size() == 0) { return; } final IProject project = list.get(0).getProject(); final List<String> filesWithOsPath = ResourceUtils.IFilesToOsPath(list); final XLFHandler xlfHandler = new XLFHandler(); Map<String, Object> resultMap = xlfHandler.openFiles(filesWithOsPath); if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) { // 打开文件失败。 MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg2")); return; } Map<String, List<XliffBean>> map = xlfHandler.getXliffInfo(); final PreTransParameters parameters = new PreTransParameters(); PreTranslationDialog dialog = new PreTranslationDialog(shell, map, parameters); if (dialog.open() == Window.OK) { if (project == null) { MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg3")); return; } if (filesWithOsPath == null || filesWithOsPath.size() == 0) { MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg4")); return; } final List<IFile> lstFile = list; IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { PreTranslation pt = new PreTranslation(xlfHandler, filesWithOsPath, project, parameters); try { final List<PreTranslationCounter> result = pt.executeTranslation(monitor); Display.getDefault().syncExec(new Runnable() { public void run() { PreTranslationResultDialog dialog = new PreTranslationResultDialog(shell, result); dialog.open(); } }); project.refreshLocal(IResource.DEPTH_INFINITE, null); result.clear(); } catch (InterruptedException e) { e.printStackTrace(); } catch (CoreException e) { logger.error("", e); e.printStackTrace(); } finally { pt.clearResources(); } Display.getDefault().syncExec(new Runnable() { public void run() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage(); for (IFile file : lstFile) { FileEditorInput editorInput = new FileEditorInput(file); IEditorPart editorPart = page.findEditor(editorInput); // 选择所有语言 XLFHandler handler = null; if (editorPart != null && editorPart instanceof IXliffEditor) { // xliff 文件已用 XLIFF 编辑器打开 IXliffEditor xliffEditor = (IXliffEditor) editorPart; handler = xliffEditor.getXLFHandler(); handler.resetCache(); VTDGen vg = new VTDGen(); String path = ResourceUtils.iFileToOSPath(file); if (vg.parseFile(path, true)) { handler.getVnMap().put(path, vg.getNav()); xliffEditor.refresh(); } } } } }); } }; try { new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run( true, true, runnable); } catch (InvocationTargetException e) { logger.error(Messages.getString("pretranslation.PreTransUitls.logger1"), e); } catch (InterruptedException e) { logger.error(Messages.getString("pretranslation.PreTransUitls.logger1"), e); } } } finally { HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent()); } } }
7,043
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
PreTranslationPreferencePage.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/preference/PreTranslationPreferencePage.java
//package net.heartsome.cat.ts.pretranslation.preference; // //import net.heartsome.cat.ts.pretranslation.Activator; //import net.heartsome.cat.ts.pretranslation.bean.IPreTransConstants; //import net.heartsome.cat.ts.pretranslation.resource.Messages; //import net.heartsome.cat.common.ui.HsImageLabel; //import net.heartsome.cat.common.util.CommonFunction; // //import org.eclipse.jface.preference.IPreferenceStore; //import org.eclipse.jface.preference.PreferencePage; //import org.eclipse.swt.SWT; //import org.eclipse.swt.layout.GridData; //import org.eclipse.swt.layout.GridLayout; //import org.eclipse.swt.widgets.Button; //import org.eclipse.swt.widgets.Composite; //import org.eclipse.swt.widgets.Control; //import org.eclipse.swt.widgets.Group; //import org.eclipse.ui.IWorkbench; //import org.eclipse.ui.IWorkbenchPreferencePage; // ///** // * 预翻译首选项 // * @author peason // * @version // * @since JDK1.6 // */ //public class PreTranslationPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { // // public static final String ID = "net.heartsome.cat.ts.pretranslation.preferencepage"; // // private IPreferenceStore preferenceStore; // // private Button lockedFullMatchBtn; // private Button lockedContextMatchBtn; // // // /** 是否覆盖 100% 匹配复选框 */ // // private Button btnOverwriteMatch100; // // /** 模糊匹配 > 保留现有匹配单选按钮 */ // private Button btnKeepNowMatch; // // /** 模糊匹配 > 覆盖现有匹配单选按钮 */ // private Button btnOverwriteNowMatch; // // /** 模糊匹配 > 始终覆盖现有匹配单选按钮 */ // private Button btnAlwaysOverwriteNowMatch; // // /** // * 构造函数 // */ // public PreTranslationPreferencePage() { // setTitle(Messages.getString("preference.PreTranslationPreferencePage.title")); // setPreferenceStore(Activator.getDefault().getPreferenceStore()); // preferenceStore = getPreferenceStore(); // } // // public void init(IWorkbench workbench) { // // TODO Auto-generated method stub // // } // // @Override // protected Control createContents(Composite parent) { // Composite tparent = new Composite(parent, SWT.NONE); // tparent.setLayout(new GridLayout()); // tparent.setLayoutData(new GridData(GridData.FILL_BOTH)); // // Group settingGroup = new Group(tparent, SWT.NONE); // settingGroup.setLayout(new GridLayout()); // settingGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // settingGroup.setText(Messages.getString("preference.PreTranslationPreferencePage.settingGroup")); // HsImageLabel settingImageLabel = new HsImageLabel( // Messages.getString("preference.PreTranslationPreferencePage.settingImageLabel"), // Activator.getImageDescriptor("images/preference/trans_pre_32.png")); // Composite settingComp = settingImageLabel.createControl(settingGroup); // // lockedFullMatchBtn = new Button(settingComp, SWT.CHECK); // lockedFullMatchBtn.setText(Messages.getString("preference.PreTranslationPreferencePage.lockedFullMatchBtn")); // lockedFullMatchBtn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // // if (CommonFunction.checkEdition("U")) { // lockedContextMatchBtn = new Button(settingComp, SWT.CHECK); // lockedContextMatchBtn.setText(Messages // .getString("preference.PreTranslationPreferencePage.lockedContextMatchBtn")); // lockedContextMatchBtn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // } // // settingImageLabel.computeSize(); // // Group matchGroup = new Group(tparent, SWT.NONE); // matchGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // matchGroup.setLayout(new GridLayout()); // matchGroup.setText(Messages.getString("preference.PreTranslationPreferencePage.matchGroup")); // // // HsImageLabel imageLabel = new HsImageLabel("", null); // // Composite matchComp = imageLabel.createControl(matchGroup); // // btnKeepNowMatch = new Button(matchGroup, SWT.RADIO); // btnKeepNowMatch.setText(Messages.getString("preference.PreTranslationPreferencePage.btnKeepNowMatch")); // btnKeepNowMatch.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // // btnOverwriteNowMatch = new Button(matchGroup, SWT.RADIO); // btnOverwriteNowMatch // .setText(Messages.getString("preference.PreTranslationPreferencePage.btnOverwriteNowMatch")); // btnOverwriteNowMatch.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // // btnAlwaysOverwriteNowMatch = new Button(matchGroup, SWT.RADIO); // btnAlwaysOverwriteNowMatch.setText(Messages // .getString("preference.PreTranslationPreferencePage.btnAlwaysOverwriteNowMatch")); // btnAlwaysOverwriteNowMatch.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // // imageLabel.computeSize(); // // setValues(false); // return parent; // } // // @Override // protected void performDefaults() { // setValues(true); // } // // @Override // public boolean performOk() { // // preferenceStore.setValue(IPreTransConstants.LOCK_FULL_MATCH, lockedFullMatchBtn.getSelection()); // if (CommonFunction.checkEdition("U")) { // preferenceStore.setValue(IPreTransConstants.LOCK_CONTEXT_MATCH, lockedContextMatchBtn.getSelection()); // } // // int intFuzzyMatch = -1; // if (btnKeepNowMatch.getSelection()) { // intFuzzyMatch = IPreTransConstants.UPDATE_KEEP_NOW; // } else if (btnOverwriteNowMatch.getSelection()) { // intFuzzyMatch = IPreTransConstants.UPDATE_OVERWRITE_BY_QUALITY; // } else if (btnAlwaysOverwriteNowMatch.getSelection()) { // intFuzzyMatch = IPreTransConstants.UPDATE_ALWAYS_OVERWRITE; // } // preferenceStore.setValue(IPreTransConstants.UPDATE_STRATEGY, intFuzzyMatch); // return true; // } // // private void setValues(boolean isApplyDefault) { // int intFuzzyMatch; // if (isApplyDefault) { // if (CommonFunction.checkEdition("U")) { // lockedContextMatchBtn.setSelection(preferenceStore // .getDefaultBoolean(IPreTransConstants.LOCK_CONTEXT_MATCH)); // } // lockedFullMatchBtn.setSelection(preferenceStore.getDefaultBoolean(IPreTransConstants.LOCK_FULL_MATCH)); // // intFuzzyMatch = preferenceStore.getDefaultInt(IPreTransConstants.UPDATE_STRATEGY); // } else { // if (CommonFunction.checkEdition("U")) { // lockedContextMatchBtn.setSelection(preferenceStore.getBoolean(IPreTransConstants.LOCK_CONTEXT_MATCH)); // } // lockedFullMatchBtn.setSelection(preferenceStore.getBoolean(IPreTransConstants.LOCK_FULL_MATCH)); // intFuzzyMatch = preferenceStore.getInt(IPreTransConstants.UPDATE_STRATEGY); // } // // if (intFuzzyMatch == IPreTransConstants.UPDATE_KEEP_NOW) { // btnKeepNowMatch.setSelection(true); // btnOverwriteNowMatch.setSelection(false); // btnAlwaysOverwriteNowMatch.setSelection(false); // } else if (intFuzzyMatch == IPreTransConstants.UPDATE_OVERWRITE_BY_QUALITY) { // btnKeepNowMatch.setSelection(false); // btnOverwriteNowMatch.setSelection(true); // btnAlwaysOverwriteNowMatch.setSelection(false); // } else if (intFuzzyMatch == IPreTransConstants.UPDATE_ALWAYS_OVERWRITE) { // btnKeepNowMatch.setSelection(false); // btnOverwriteNowMatch.setSelection(false); // btnAlwaysOverwriteNowMatch.setSelection(true); // } // } //}
7,128
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
PreTransPreferenceInitializer.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/preference/PreTransPreferenceInitializer.java
///** // * PreTransPreferenceInitializer.java // * // * Version information : // * // * Date:2012-5-8 // * // * Copyright notice : // * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 // * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, // * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 // */ //package net.heartsome.cat.ts.pretranslation.preference; // //import net.heartsome.cat.ts.pretranslation.Activator; //import net.heartsome.cat.ts.pretranslation.bean.IPreTransConstants; // //import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; //import org.eclipse.jface.preference.IPreferenceStore; // ///** // * @author jason // * @version // * @since JDK1.6 // */ //public class PreTransPreferenceInitializer extends AbstractPreferenceInitializer { // // @Override // public void initializeDefaultPreferences() { // IPreferenceStore store = Activator.getDefault().getPreferenceStore(); // // 预翻译设置默认值 // store.setDefault(IPreTransConstants.LOCK_FULL_MATCH, false); // store.setDefault(IPreTransConstants.LOCK_CONTEXT_MATCH, false); // store.setDefault(IPreTransConstants.UPDATE_STRATEGY, IPreTransConstants.UPDATE_KEEP_NOW); // } // //}
1,542
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
IPreTransConstants.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/bean/IPreTransConstants.java
///** // * IPreferenceConstants.java // * // * Version information : // * // * Date:2012-5-8 // * // * Copyright notice : // * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 // * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, // * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 // */ //package net.heartsome.cat.ts.pretranslation.bean; // ///** // * @author jason // * @version // * @since JDK1.6 // */ //public interface IPreTransConstants { // // // 首选项 // String LOCK_FULL_MATCH = "PRETRANS_LOCK_FULL_MATCH"; // String LOCK_CONTEXT_MATCH = "PRETRANS_LOCK_CONTEXT_MATCH"; // String UPDATE_STRATEGY = "PRETRANS_UPDATE_STRATEGY"; // // // 预翻译策略 // /** 保留现在匹配 */ // int UPDATE_KEEP_NOW = 0; // /** 当前匹配比已经存在匹配高时,覆盖 */ // int UPDATE_OVERWRITE_BY_QUALITY = 1; // /** 始终覆盖*/ // int UPDATE_ALWAYS_OVERWRITE = 2; //}
1,247
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
PreTransParameters.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/bean/PreTransParameters.java
/** * PreTransParameters.java * * Version information : * * Date:2012-5-8 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.pretranslation.bean; /** * @author jason * @version * @since JDK1.6 */ public class PreTransParameters { /** 保留现在匹配 */ public final static int KEEP_OLD_TARGET = 0; /** 当前匹配比已经存在匹配高时,覆盖 */ public final static int KEEP_BEST_MATCH_TARGET = 1; /** 始终覆盖*/ public final static int KEEP_NEW_TARGET = 2; //预翻译选项 private int LowestMatchPercent = 70; private boolean ignoreCase = true; private boolean ignoreTag = true; private int panalty = 2; // 覆盖策略 private int updateStrategy = KEEP_BEST_MATCH_TARGET; //锁定选项 private boolean lockFullMatch = false; private boolean lockContextMatch = false; // private IPreferenceStore ps; public int getLowestMatchPercent() { return LowestMatchPercent; } public void setLowestMatchPercent(int lowestMatchPercent) { LowestMatchPercent = lowestMatchPercent; } public boolean getIgnoreCase() { return ignoreCase; } public void setIgnoreCase(boolean ignoreCase) { this.ignoreCase = ignoreCase; } public boolean getIgnoreTag() { return ignoreTag; } public void setIgnoreTag(boolean ignoreTag) { this.ignoreTag = ignoreTag; } public void setUpdateStrategy(int updateStrategy) { this.updateStrategy = updateStrategy; } public void setLockFullMatch(boolean lockFullMatch) { this.lockFullMatch = lockFullMatch; } public void setLockContextMatch(boolean lockContextMatch) { this.lockContextMatch = lockContextMatch; } // // private static PreTransParameters instance; // // public static PreTransParameters getInstance() { // if (instance == null) { // instance = new PreTransParameters(); // } // return instance; // } // // private PreTransParameters() { // this.ps = Activator.getDefault().getPreferenceStore(); // if (ps != null) { // this.ps.addPropertyChangeListener(this); // this.loadParameters(); // } // } // // private void loadParameters() { // updateStrategy = ps.getInt(IPreTransConstants.UPDATE_STRATEGY); // lockFullMatch = ps.getBoolean(IPreTransConstants.LOCK_FULL_MATCH); // lockContextMatch = ps.getBoolean(IPreTransConstants.LOCK_CONTEXT_MATCH); // } // // /** // * (non-Javadoc) // * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) // */ // public void propertyChange(PropertyChangeEvent event) { // loadParameters(); // } /** * 预翻译时,当前已经存在匹配时的更新策略 * @return the updateStrategy */ public int getUpdateStrategy() { return updateStrategy; } /** * 是否锁定完全匹配 * @return the lockFullMatch */ public boolean isLockFullMatch() { return lockFullMatch; } /** * 是否锁定上下文匹配 * @return the lockContextMatch */ public boolean isLockContextMatch() { return lockContextMatch; } public int getPanalty() { return panalty; } public void setPanalty(int panalty) { this.panalty = panalty; } }
3,620
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
PreTranslationCounter.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/bean/PreTranslationCounter.java
/** * PreTranslationCounter.java * * Version information : * * Date:2012-5-10 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.pretranslation.bean; /** * 预翻译计数器,用于对预翻译的文件进行统计 * @author jason * @version * @since JDK1.6 */ public class PreTranslationCounter { private int transTuCount = 0; private int lockedFullCount = 0; private int lockedContextCount = 0; private int tuNumber = 0; private String currentFile = ""; public PreTranslationCounter(String file) { this.currentFile = file; } public void countTransTu() { this.transTuCount++; } public void countLockedFullMatch() { this.lockedFullCount++; } public void countLockedContextmatch() { this.lockedContextCount++; } /** @return the transTuCount */ public int getTransTuCount() { return transTuCount; } /** @return the lockedFullCount */ public int getLockedFullCount() { return lockedFullCount; } /** @return the lockedContextCount */ public int getLockedContextCount() { return lockedContextCount; } /** @return the tuNumber */ public int getTuNumber() { return tuNumber; } /** * @param tuNumber * the tuNumber to set */ public void setTuNumber(int tuNumber) { this.tuNumber = tuNumber; } /** @return the currentFile */ public String getCurrentFile() { return currentFile; } }
1,885
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ImageConstants.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/bean/ImageConstants.java
/** * ImageConstants.java * * Version information : * * Date:2012-5-8 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.pretranslation.bean; /** * @author jason * @version * @since JDK1.6 */ public class ImageConstants { public final static String PRE_TRANSLTATION_LOGO = "images/dialog/pre-translation-logo.png"; }
856
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
PreTranslationResultDialog.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/dialog/PreTranslationResultDialog.java
/** * PreTranslationResultDialog.java * * Version information : * * Date:Oct 20, 2011 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.pretranslation.dialog; import java.util.ArrayList; import java.util.List; import net.heartsome.cat.ts.pretranslation.bean.PreTranslationCounter; import net.heartsome.cat.ts.pretranslation.resource.Messages; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; /** * 预翻译结果显示对话框 * @author Jason * @version * @since JDK1.6 */ public class PreTranslationResultDialog extends Dialog { private TableViewer tableViewer; List<PreTranslationCounter> preTransResult; /** * Create the dialog. * @param parentShell */ public PreTranslationResultDialog(Shell parentShell, List<PreTranslationCounter> preTransResult) { super(parentShell); this.preTransResult = preTransResult; } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(Messages.getString("dialog.PreTranslationResultDialog.title")); } /** * Create contents of the dialog. * @param parent */ @Override protected Control createDialogArea(Composite parent) { Composite container = (Composite) super.createDialogArea(parent); container.setLayout(new GridLayout(1, false)); Composite composite = new Composite(container, SWT.NONE); GridLayout gl_composite = new GridLayout(1, false); gl_composite.verticalSpacing = 0; gl_composite.marginWidth = 0; gl_composite.marginHeight = 0; composite.setLayout(gl_composite); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL); Table table = tableViewer.getTable(); GridData tableGd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); tableGd.heightHint = 220; table.setLayoutData(tableGd); table.setLinesVisible(true); table.setHeaderVisible(true); String[] clmnTitles = new String[] { Messages.getString("dialog.PreTranslationResultDialog.clmnTitles1"), Messages.getString("dialog.PreTranslationResultDialog.clmnTitles2"), Messages.getString("dialog.PreTranslationResultDialog.clmnTitles3"), Messages.getString("dialog.PreTranslationResultDialog.clmnTitles4"), Messages.getString("dialog.PreTranslationResultDialog.clmnTitles5"), Messages.getString("dialog.PreTranslationResultDialog.clmnTitles6") }; int[] clmnBounds = { 60, 200, 100, 110, 110, 110 }; for (int i = 0; i < clmnTitles.length; i++) { createTableViewerColumn(tableViewer, clmnTitles[i], clmnBounds[i], i); } tableViewer.setLabelProvider(new TableViewerLabelProvider()); tableViewer.setContentProvider(new ArrayContentProvider()); tableViewer.setInput(this.getTableViewerInput()); return container; } /** * Create contents of the button bar. * @param parent */ @Override protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); } /** * Return the initial size of the dialog. */ @Override protected Point getInitialSize() { return getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); } private String[][] getTableViewerInput() { String wPath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString(); List<String[]> rows = new ArrayList<String[]>(); int i = 1; for (PreTranslationCounter counter : preTransResult) { String iFilePath = counter.getCurrentFile().replace(wPath, ""); String[] row = new String[] { (i++) + "", iFilePath, counter.getTuNumber() + "", counter.getTransTuCount() + "", counter.getLockedContextCount() + "", counter.getLockedFullCount() + "" }; rows.add(row); } return rows.toArray(new String[][] {}); } /** * 设置TableViewer 列属性 * @param viewer * @param title * 列标题 * @param bound * 列宽 * @param colNumber * 列序号 * @return {@link TableViewerColumn}; */ private TableViewerColumn createTableViewerColumn(TableViewer viewer, String title, int bound, final int colNumber) { final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE | SWT.Resize); final TableColumn column = viewerColumn.getColumn(); column.setText(title); column.setWidth(bound); column.setResizable(true); column.setMoveable(true); return viewerColumn; } /** * tableViewer的标签提供器 * @author Jason */ class TableViewerLabelProvider extends LabelProvider implements ITableLabelProvider { public Image getColumnImage(Object element, int columnIndex) { return null; } public String getColumnText(Object element, int columnIndex) { if (element instanceof String[]) { String[] array = (String[]) element; return array[columnIndex]; } return null; } } /** * @param tableViewer * the tableViewer to set */ public void setTableViewer(TableViewer tableViewer) { this.tableViewer = tableViewer; } public boolean close() { this.preTransResult.clear(); this.preTransResult = null; return super.close(); } }
6,399
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
PreTranslationDialog.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/dialog/PreTranslationDialog.java
/** * PreTranslationDialog.java * * Version information : * * Date:Oct 20, 2011 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.pretranslation.dialog; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import net.heartsome.cat.common.util.CommonFunction; import net.heartsome.cat.ts.core.bean.XliffBean; import net.heartsome.cat.ts.pretranslation.Activator; import net.heartsome.cat.ts.pretranslation.bean.ImageConstants; import net.heartsome.cat.ts.pretranslation.bean.PreTransParameters; import net.heartsome.cat.ts.pretranslation.resource.Messages; import net.heartsome.cat.ts.ui.composite.DialogLogoCmp; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.TrayDialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Spinner; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import org.eclipse.ui.PlatformUI; /** * 预翻译信息显示对话框,用于展示文件列表 * @author Jason * @version * @since JDK1.6 */ public class PreTranslationDialog extends TrayDialog { private TableViewer viewer; private Map<String, List<XliffBean>> xliffInofs; private PreTransParameters parameters = null; private Image logoImage = Activator.getImageDescriptor(ImageConstants.PRE_TRANSLTATION_LOGO).createImage(); /** 忽略大小写 */ private Button btnIgnoreCase; /** 忽略标记 */ private Button btnIgnoretag; /** 最低匹配率 */ private Spinner spinner; /** 完全匹配 */ private Button btn101Match; /** 上下文匹配 */ private Button btnContextMatch; /** 保留原来译文 */ private Button btnKeepOld; /** 匹配率高于现有译文 */ private Button btnKeepBestMatch; /** 始终覆盖现有译文 */ private Button btnKeepNew; /** 不一致罚分. */ private Spinner spinnnerPanalty; private Label lblTagPenalty; private IDialogSettings dialogSettings; /** * Create the dialog. * @param parentShell * @param parameters */ public PreTranslationDialog(Shell parentShell, Map<String, List<XliffBean>> xliffInofs, PreTransParameters parameters) { super(parentShell); dialogSettings = Activator.getDefault().getDialogSettings(); this.parameters = parameters; this.xliffInofs = xliffInofs; setHelpAvailable(true); } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(Messages.getString("dialog.PreTranslationDialog.title")); } /** * 添加帮助按钮 robert 2012-09-06 */ @Override protected Control createHelpControl(Composite parent) { // ROBERTHELP 预翻译 String language = CommonFunction.getSystemLanguage(); final String helpUrl = MessageFormat.format( "/net.heartsome.cat.ts.ui.help/html/{0}/ch05s03.html#pre-translation", language); Image helpImage = JFaceResources.getImage(DLG_IMG_HELP); ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS); ((GridLayout) parent.getLayout()).numColumns++; toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND); toolBar.setCursor(cursor); toolBar.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { cursor.dispose(); } }); ToolItem helpItem = new ToolItem(toolBar, SWT.NONE); helpItem.setImage(helpImage); helpItem.setToolTipText(JFaceResources.getString("helpToolTip")); //$NON-NLS-1$ helpItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl); } }); return toolBar; } /** * Create contents of the dialog. * @param parent */ @Override protected Control createDialogArea(Composite parent) { Composite container = (Composite) super.createDialogArea(parent); GridLayoutFactory.fillDefaults().extendedMargins(-1, -1, -1, 8).numColumns(1).applyTo(container); createLogoArea(container); Composite parentCmp = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().extendedMargins(9, 9, 0, 0).numColumns(1).applyTo(parentCmp); GridDataFactory.fillDefaults().grab(true, true).applyTo(parentCmp); createPageContent(parentCmp); viewer.getTable().setFocus(); return container; } /** * Return the initial size of the dialog. */ @Override protected Point getInitialSize() { return getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); } /** * 创建页面内容 * @param parent * ; */ private void createPageContent(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout gl_composite = new GridLayout(1, false); gl_composite.marginHeight = 0; gl_composite.marginWidth = 0; gl_composite.verticalSpacing = 0; composite.setLayout(gl_composite); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); viewer = new TableViewer(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); final Table table = viewer.getTable(); GridData tableGd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); tableGd.heightHint = 220; table.setLayoutData(tableGd); table.setLinesVisible(true); table.setHeaderVisible(true); String[] clmnTitles = new String[] { Messages.getString("dialog.PreTranslationDialog.clmnTitles1"), Messages.getString("dialog.PreTranslationDialog.clmnTitles2"), Messages.getString("dialog.PreTranslationDialog.clmnTitles3"), Messages.getString("dialog.PreTranslationDialog.clmnTitles4") }; int[] clmnBounds = { 80, 250, 100, 100 }; for (int i = 0; i < clmnTitles.length; i++) { createTableViewerColumn(viewer, clmnTitles[i], clmnBounds[i], i); } viewer.setLabelProvider(new TableViewerLabelProvider()); viewer.setContentProvider(new ArrayContentProvider()); viewer.setInput(this.getTableViewerInput()); // 参数面板 Composite cmpPerTranParam = new Composite(composite, SWT.BORDER); GridDataFactory.createFrom(new GridData(GridData.FILL_BOTH)).applyTo(cmpPerTranParam); GridLayoutFactory.swtDefaults().numColumns(3).applyTo(cmpPerTranParam); // 预翻译参数 Group groupMatch = new Group(cmpPerTranParam, SWT.NONE); GridDataFactory.createFrom(new GridData(GridData.FILL_BOTH)).applyTo(groupMatch); GridLayoutFactory.swtDefaults().applyTo(groupMatch); groupMatch.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.match")); Composite cmpPercent = new Composite(groupMatch, SWT.NONE); GridDataFactory.createFrom(new GridData(GridData.FILL_BOTH)).applyTo(cmpPercent); GridLayoutFactory.fillDefaults().numColumns(3).applyTo(cmpPercent); Label lblLowest = new Label(cmpPercent, SWT.NONE); lblLowest.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.lowestmatch")); spinner = new Spinner(cmpPercent, SWT.BORDER); spinner.setMinimum(1); spinner.setIncrement(5); spinner.setSelection(70); Label lblPercentage = new Label(cmpPercent, SWT.NONE); lblPercentage.setText("%"); btnIgnoreCase = new Button(groupMatch, SWT.CHECK); btnIgnoreCase.setSelection(true); btnIgnoreCase.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.ignorecase")); GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1).applyTo(btnIgnoreCase); btnIgnoretag = new Button(groupMatch, SWT.CHECK); GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1).applyTo(btnIgnoretag); btnIgnoretag.setSelection(true); btnIgnoretag.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.ignoretag")); btnIgnoretag.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { setPanalty(!btnIgnoretag.getSelection()); } }); Composite cmpPenalty = new Composite(groupMatch, SWT.NONE); cmpPenalty.setLayoutData(new GridData(GridData.FILL_BOTH)); GridLayoutFactory.fillDefaults().margins(15, 0).numColumns(2).applyTo(cmpPenalty); lblTagPenalty = new Label(cmpPenalty, SWT.NONE); lblTagPenalty.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.tagPenalty")); spinnnerPanalty = new Spinner(cmpPenalty, SWT.BORDER); spinnnerPanalty.setSelection(2); setPanalty(false); // 锁定参数 String lockGrpText = Messages.getString("dialog.PreTranslationDialog.pertrans.lock"); Group groupLockWhenPerTrans = new Group(cmpPerTranParam, SWT.MULTI | SWT.WRAP); GridDataFactory.createFrom(new GridData(GridData.FILL_BOTH)).applyTo(groupLockWhenPerTrans); GridLayoutFactory.swtDefaults().numColumns(1).applyTo(groupLockWhenPerTrans); groupLockWhenPerTrans.setText(lockGrpText); btn101Match = new Button(groupLockWhenPerTrans, SWT.CHECK); btn101Match.setSelection(true); btn101Match.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.fullMatch")); btnContextMatch = new Button(groupLockWhenPerTrans, SWT.CHECK); btnContextMatch.setSelection(true); btnContextMatch.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.contextMatch")); Label lbl = new Label(groupLockWhenPerTrans, SWT.NONE); lbl.setText(lockGrpText); lbl.setVisible(false); // 覆盖策略 Group groupHandleOldTarget = new Group(cmpPerTranParam, SWT.NONE); GridDataFactory.createFrom(new GridData(GridData.FILL_BOTH)).applyTo(groupHandleOldTarget); GridLayoutFactory.swtDefaults().numColumns(1).applyTo(groupHandleOldTarget); groupHandleOldTarget.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.handleTargetText")); btnKeepOld = new Button(groupHandleOldTarget, SWT.RADIO); btnKeepOld.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.keepOld")); btnKeepBestMatch = new Button(groupHandleOldTarget, SWT.RADIO); btnKeepBestMatch.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.keepBestMatch")); btnKeepNew = new Button(groupHandleOldTarget, SWT.RADIO); btnKeepNew.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.keepNew")); setDefaultValues(); } /** * 重设上次的状态; */ private void setDefaultValues() { if (dialogSettings.getBoolean("hasSetting")) { String tmp = null; tmp = dialogSettings.get("spinner"); spinner.setSelection(tmp == null ? 70 : Integer.valueOf(tmp)); btnIgnoreCase.setSelection(dialogSettings.getBoolean("btnIgnoreCase")); btnIgnoretag.setSelection(dialogSettings.getBoolean("btnIgnoretag")); setPanalty(!btnIgnoretag.getSelection()); tmp = dialogSettings.get("spinnnerPanalty"); spinnnerPanalty.setSelection(tmp == null ? 2 : Integer.valueOf(tmp)); btn101Match.setSelection(dialogSettings.getBoolean("btn101Match")); btnContextMatch.setSelection(dialogSettings.getBoolean("btnContextMatch")); tmp = dialogSettings.get("updateStrategy"); switch (tmp == null ? -11 : Integer.valueOf(tmp)) { case PreTransParameters.KEEP_BEST_MATCH_TARGET: btnKeepBestMatch.setSelection(true); break; case PreTransParameters.KEEP_NEW_TARGET: btnKeepNew.setSelection(true); break; case PreTransParameters.KEEP_OLD_TARGET: btnKeepOld.setSelection(true); break; default: btnKeepBestMatch.setSelection(true); break; } } else { btnIgnoreCase.setSelection(true); btnIgnoretag.setSelection(true); btn101Match.setSelection(true); btnContextMatch.setSelection(true); btnKeepBestMatch.setSelection(true); spinner.setSelection(70); spinnnerPanalty.setSelection(2); } } /** * 从当前的数据库获取需要显示到界面上的数据 * @return ; */ private String[][] getTableViewerInput() { String wPath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString(); Iterator<Entry<String, List<XliffBean>>> it = xliffInofs.entrySet().iterator(); List<String[]> rows = new ArrayList<String[]>(); int index = 1; while (it.hasNext()) { Entry<String, List<XliffBean>> entry = it.next(); String filePath = entry.getKey(); String iFilePath = filePath.replace(wPath, ""); // 获取到项目为根的路径 List<XliffBean> xliffBeans = entry.getValue(); // for (int i = 0; i < xliffBeans.size(); i++) { XliffBean xliffBean = xliffBeans.get(0); String srcLang = xliffBean.getSourceLanguage(); String tagLang = xliffBean.getTargetLanguage(); String[] rowValue = new String[] { (index++) + "", iFilePath, srcLang, tagLang }; rows.add(rowValue); // } } return rows.toArray(new String[][] {}); } /** * tableViewer的标签提供器 * @author Jason */ class TableViewerLabelProvider extends LabelProvider implements ITableLabelProvider { public Image getColumnImage(Object element, int columnIndex) { return null; } public String getColumnText(Object element, int columnIndex) { if (element instanceof String[]) { String[] array = (String[]) element; return array[columnIndex]; } return null; } } /** * 显示图片区 * @param parent */ public void createLogoArea(Composite parent) { new DialogLogoCmp(parent, SWT.NONE, Messages.getString("dialog.PreTranslationDialog.logoTitle"), Messages.getString("dialog.PreTranslationDialog.desc"), logoImage); } /** * 设置TableViewer 列属性 * @param viewer * @param title * 列标题 * @param bound * 列宽 * @param colNumber * 列序号 * @return {@link TableViewerColumn}; */ private TableViewerColumn createTableViewerColumn(TableViewer viewer, String title, int bound, final int colNumber) { final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE | SWT.Resize); final TableColumn column = viewerColumn.getColumn(); column.setText(title); column.setWidth(bound); column.setResizable(true); column.setMoveable(true); return viewerColumn; } @Override protected void okPressed() { // 填充预翻译换参数策 parameters.setIgnoreCase(btnIgnoreCase.getSelection()); parameters.setIgnoreTag(btnIgnoretag.getSelection()); if (spinner.getText().isEmpty()) { parameters.setLowestMatchPercent(0); } else { parameters.setLowestMatchPercent(Integer.valueOf(spinner.getText())); } if (spinnnerPanalty.getText().isEmpty()) { parameters.setPanalty(0); } else { parameters.setPanalty(Integer.valueOf(spinnnerPanalty.getText())); } parameters.setLockFullMatch(btn101Match.getSelection()); parameters.setLockContextMatch(btnContextMatch.getSelection()); if (btnKeepOld.getSelection()) { parameters.setUpdateStrategy(PreTransParameters.KEEP_OLD_TARGET); } else if (btnKeepBestMatch.getSelection()) { parameters.setUpdateStrategy(PreTransParameters.KEEP_BEST_MATCH_TARGET); } else if (btnKeepNew.getSelection()) { parameters.setUpdateStrategy(PreTransParameters.KEEP_NEW_TARGET); } dialogSettings.put("hasSetting", true); dialogSettings.put("btn101Match", parameters.isLockFullMatch()); dialogSettings.put("btnContextMatch", parameters.isLockContextMatch()); dialogSettings.put("btnIgnoreCase", parameters.getIgnoreCase()); dialogSettings.put("btnIgnoretag", parameters.getIgnoreTag()); dialogSettings.put("spinner", parameters.getLowestMatchPercent()); dialogSettings.put("spinnnerPanalty", parameters.getPanalty()); dialogSettings.put("updateStrategy", parameters.getUpdateStrategy()); setReturnCode(OK); close(); } @Override public boolean close() { if (logoImage != null && !logoImage.isDisposed()) { logoImage.dispose(); } return super.close(); } private void setPanalty(boolean enabled) { lblTagPenalty.setEnabled(enabled); spinnnerPanalty.setEnabled(enabled); } }
17,397
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
PromptDialog.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/dialog/PromptDialog.java
//package net.heartsome.cat.ts.pretranslation.dialog; // //import java.util.List; // //import net.heartsome.cat.ts.pretranslation.resource.Messages; // //import org.eclipse.jface.dialogs.Dialog; //import org.eclipse.jface.dialogs.IDialogConstants; //import org.eclipse.jface.dialogs.MessageDialog; //import org.eclipse.swt.SWT; //import org.eclipse.swt.events.SelectionAdapter; //import org.eclipse.swt.events.SelectionEvent; //import org.eclipse.swt.graphics.Point; //import org.eclipse.swt.layout.GridData; //import org.eclipse.swt.widgets.Button; //import org.eclipse.swt.widgets.Composite; //import org.eclipse.swt.widgets.Control; //import org.eclipse.swt.widgets.Label; //import org.eclipse.swt.widgets.Shell; // //public class PromptDialog extends Dialog { // // private List<String> toolIds; // private String choiceResult; // // /** // * Create the dialog. // * @param parentShell // */ // public PromptDialog(Shell parentShell, List<String> toolIds) { // super(parentShell); // this.toolIds = toolIds; // } // // @Override // protected boolean canHandleShellCloseEvent() { // return false; // } // // /** // * Create contents of the dialog. // * @param parent // */ // @Override // protected Control createDialogArea(Composite parent) { // Composite container = (Composite) super.createDialogArea(parent); // // Label label = new Label(container, SWT.NONE); // label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); // label.setText(Messages.getString("dialog.PromptDialog.label")); // // for (String toolId : toolIds) { // final Button btn = new Button(container, SWT.RADIO); // btn.setText(toolId); // btn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // btn.addSelectionListener(new SelectionAdapter() { // @Override // public void widgetSelected(SelectionEvent e) { // if (btn.getSelection()) { // choiceResult = btn.getText(); // } // } // }); // } // // return container; // } // // /** // * Create contents of the button bar. // * @param parent // */ // @Override // protected void createButtonsForButtonBar(Composite parent) { // createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); // } // // /** // * Return the initial size of the dialog. // */ // @Override // protected Point getInitialSize() { // return getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); // } // // @Override // protected void okPressed() { // if (choiceResult == null) { // MessageDialog.openInformation(getShell(), Messages.getString("dialog.PromptDialog.msgTitle"), // Messages.getString("dialog.PromptDialog.msg")); // return; // } // super.okPressed(); // } // // public String getChoiceResult() { // return choiceResult; // } //}
2,748
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
PreTranslationHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/handlers/PreTranslationHandler.java
/** * PreTranslationHandler.java * * Version information : * * Date:2012-5-8 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.pretranslation.handlers; import java.util.List; import net.heartsome.cat.common.resources.ResourceUtils; import net.heartsome.cat.common.ui.handlers.AbstractSelectProjectFilesHandler; import net.heartsome.cat.common.util.CommonFunction; import net.heartsome.cat.ts.pretranslation.PreTransUitls; import net.heartsome.cat.ts.ui.editors.IXliffEditor; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IFile; import org.eclipse.ui.IEditorReference; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.part.FileEditorInput; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author jason * @version * @since JDK1.6 */ public class PreTranslationHandler extends AbstractSelectProjectFilesHandler { public static final Logger logger = LoggerFactory.getLogger(PreTranslationHandler.class); private static final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor"; @Override public String[] getLegalFileExtensions() { return CommonFunction.xlfExtesionArray; } @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; } }
2,741
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ExecutePreTranslationImpl.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/converter/ExecutePreTranslationImpl.java
/** * ExecutePreTranslationImpl.java * * Version information : * * Date:2012-6-25 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.pretranslation.converter; import java.util.List; import org.eclipse.core.resources.IFile; import org.eclipse.swt.widgets.Display; import net.heartsome.cat.convert.extenstion.IExecutePretranslation; import net.heartsome.cat.ts.pretranslation.PreTransUitls; /** * @author jason * @version * @since JDK1.6 */ public class ExecutePreTranslationImpl implements IExecutePretranslation { /** * */ public ExecutePreTranslationImpl() { // TODO Auto-generated constructor stub } /** (non-Javadoc) * @see net.heartsome.cat.convert.extenstion.IExecutePretranslation#executePreTranslation(java.util.List) */ public void executePreTranslation(List<IFile> files) { PreTransUitls.executeTranslation(files, Display.getCurrent().getActiveShell()); } }
1,428
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
Messages.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.pretranslation/src/net/heartsome/cat/ts/pretranslation/resource/Messages.java
package net.heartsome.cat.ts.pretranslation.resource; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * 国际化工具类 * @author peason * @version * @since JDK1.6 */ public class Messages { private static final String BUNDLE_NAME = "net.heartsome.cat.ts.pretranslation.resource.message"; private static ResourceBundle BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); public static String getString(String key) { try { return BUNDLE.getString(key); } catch (MissingResourceException e) { return key; } } }
572
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
SimpleMatcherFactory.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.tm/src/net/heartsome/cat/ts/tm/simpleMatch/SimpleMatcherFactory.java
/** * SimpleMatcherFactory.java * * Version information : * * Date:2012-5-13 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.tm.simpleMatch; import java.util.ArrayList; import java.util.List; import net.heartsome.cat.ts.tm.resource.Messages; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.SafeRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author jason * @version * @since JDK1.6 */ public class SimpleMatcherFactory { public static final Logger logger = LoggerFactory.getLogger(SimpleMatcherFactory.class); private final String EXTENSION_ID = "net.heartsome.cat.ts.tm.simplematch.extension"; private List<ISimpleMatcher> matchers; private static SimpleMatcherFactory instance; public static SimpleMatcherFactory getInstance(){ if(instance == null){ instance = new SimpleMatcherFactory(); } return instance; } public List<ISimpleMatcher> getCuurentMatcher(){ return matchers; } private SimpleMatcherFactory() { matchers = new ArrayList<ISimpleMatcher>(); runExtension(); } /** * 加载记忆库匹配实现 ; */ private void runExtension() { IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID); try { for (IConfigurationElement e : config) { final Object o = e.createExecutableExtension("class"); if (o instanceof ISimpleMatcher) { ISafeRunnable runnable = new ISafeRunnable() { public void handleException(Throwable exception) { logger.error(Messages.getString("simpleMatch.SimpleMatcherFactory.logger1"), exception); } public void run() throws Exception { ISimpleMatcher simpleMatcher = (ISimpleMatcher) o; matchers.add(simpleMatcher); } }; SafeRunner.run(runnable); } } } catch (CoreException ex) { logger.error(Messages.getString("simpleMatch.SimpleMatcherFactory.logger1"), ex); } } }
2,624
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISimpleMatcher.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.tm/src/net/heartsome/cat/ts/tm/simpleMatch/ISimpleMatcher.java
/** * ISimpleMatcher.java * * Version information : * * Date:2012-5-13 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.tm.simpleMatch; import net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean; /** * 简单匹配接口定义<br> * 简单匹配是指,简单的传入需要翻译的内容和源语言代码、目标语言代码后,返回对应的译文 * @author jason * @version * @since JDK1.6 */ public interface ISimpleMatcher { /** * 获取匹配的类型简称,如机器翻译则近回MT,用于显示到匹配视图中 * @return ; */ String getMatcherType(); /** * 获取匹配的来源 * @return ; */ String getMathcerOrigin(); /** * 获取匹配算法来源,如google翻译,用于显示到匹配的属性中 * @return ; */ String getMathcerToolId(); /** * 检查当前翻译是否可用<br> * 如果当前没有通过验证,返回false<br> * 如果当前访问方式为手动,返回false * @return true可用,false不可以用; */ boolean matchChecker(); /** * 执行翻译 * @param tuInfo * 翻译时需要的翻译单元信息 * @return String 翻译结果 */ String executeMatch(TransUnitInfo2TranslationBean tuInfo); /** * 判断是否支持预翻译,如果当产翻译不可用,也将返回false * @return true 支持预翻译,false不支持预翻译 */ boolean isSuportPreTrans(); /** * 是否覆盖当前已经存在翻译<br> * 根据种简单翻译定义,一种匹配算法只会存在一个匹配,此方法用于确定是否覆盖上一次的匹配<br> * 如google翻译,是否进行二次请求 * @return ; */ boolean isOverwriteMatch(); }
2,218
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ComplexMatcherFactory.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.tm/src/net/heartsome/cat/ts/tm/complexMatch/ComplexMatcherFactory.java
/** * ComplexMatcherFactory.java * * Version information : * * Date:2012-6-20 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.tm.complexMatch; import java.util.ArrayList; import java.util.List; import net.heartsome.cat.ts.tm.resource.Messages; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.SafeRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author jason * @version * @since JDK1.6 */ public class ComplexMatcherFactory { public static final Logger logger = LoggerFactory.getLogger(ComplexMatcherFactory.class); private final String EXTENSION_ID = "net.heartsome.cat.ts.tm.complexmatch.extension"; private List<IComplexMatch> matchers; private static ComplexMatcherFactory instance; public static ComplexMatcherFactory getInstance() { if (instance == null) { instance = new ComplexMatcherFactory(); } return instance; } public List<IComplexMatch> getCuurentMatcher(){ return matchers; } private ComplexMatcherFactory(){ matchers = new ArrayList<IComplexMatch>(); runExtension(); } /** * load implement of complex matcher */ private void runExtension() { IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID); try { for (IConfigurationElement e : config) { final Object o = e.createExecutableExtension("class"); if (o instanceof IComplexMatch) { ISafeRunnable runnable = new ISafeRunnable() { public void handleException(Throwable exception) { logger.error(Messages.getString("complexMatch.ComplexMatcherFactory.logger1"), exception); } public void run() throws Exception { IComplexMatch simpleMatcher = (IComplexMatch) o; matchers.add(simpleMatcher); } }; SafeRunner.run(runnable); } } } catch (CoreException ex) { logger.error(Messages.getString("complexMatch.ComplexMatcherFactory.logger1"), ex); } } }
2,639
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
IComplexMatch.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.tm/src/net/heartsome/cat/ts/tm/complexMatch/IComplexMatch.java
/** * IComplexMatch.java * * Version information : * * Date:2012-6-19 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.tm.complexMatch; import java.util.Vector; import org.eclipse.core.resources.IProject; import net.heartsome.cat.ts.core.bean.AltTransBean; import net.heartsome.cat.ts.core.bean.TransUnitBean; /** * 复杂翻译,用于实现各种翻译相关的计算等,如快速翻译 * @author jason * @version * @since JDK1.6 */ public interface IComplexMatch { /** * 执行翻译 * @return 返回翻译结果 ; */ Vector<AltTransBean> executeTranslation(TransUnitBean transUnitBean,IProject currentProject); /** * 获取当前匹配器的toolId * @return ; */ String getToolId(); /** * 获取匹配的类型简称,如快速翻译QT * @return ; */ String getMatcherType(); /** * 获取匹配的来源 * @return ; */ String getMathcerOrigin(); }
1,440
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
TransUnitInfo2TranslationBean.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.tm/src/net/heartsome/cat/ts/tm/bean/TransUnitInfo2TranslationBean.java
/** * TransUnitInfoBean.java * * Version information : * * Date:2012-4-27 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.tm.bean; /** * 翻译单元信息封装,用于匹配时所需翻译单元信息的封装 * @author jason * @version * @since JDK1.5 */ public class TransUnitInfo2TranslationBean { private String srcFullText = ""; private String srcPureText = ""; // 翻译单元源文语言代码 private String srcLanguage = ""; // 翻译单元目标语言代码 private String tgtLangugage = ""; // 上文 private String preContext = ""; // 下文 private String nextContext = ""; /** * 重置当前翻译单元信息 * ; */ public void resetTuInfo(){ srcFullText = ""; srcPureText = ""; // 翻译单元源文语言代码 srcLanguage = ""; // 翻译单元目标语言代码 tgtLangugage = ""; // 上文 preContext = ""; // 下文 nextContext = ""; } /** @return the srcFullText */ public String getSrcFullText() { return srcFullText; } /** * @param srcFullText * 翻译单元完整的文本内容 */ public void setSrcFullText(String srcFullText) { this.srcFullText = srcFullText; } /** @return 翻译单元源文纯文本内容 */ public String getSrcPureText() { return srcPureText; } /** * @param srcPureText * the srcPureText to set */ public void setSrcPureText(String srcPureText) { this.srcPureText = srcPureText; } /** @return the srcLanguage */ public String getSrcLanguage() { return srcLanguage; } /** * @param srcLanguage * the srcLanguage to set */ public void setSrcLanguage(String srcLanguage) { this.srcLanguage = srcLanguage; } /** @return the tgtLangugage */ public String getTgtLangugage() { return tgtLangugage; } /** * @param tgtLangugage * the tgtLangugage to set */ public void setTgtLangugage(String tgtLangugage) { this.tgtLangugage = tgtLangugage; } /** @return the preContext */ public String getPreContext() { return preContext; } /** * @param preContext * the preContext to set */ public void setPreContext(String preContext) { this.preContext = preContext; } /** @return the nextContext */ public String getNextContext() { return nextContext; } /** * @param nextContext * the nextContext to set */ public void setNextContext(String nextContext) { this.nextContext = nextContext; } }
2,981
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
TmMatcher.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.tm/src/net/heartsome/cat/ts/tm/match/TmMatcher.java
/** * TmMatcher.java * * Version information : * * Date:2012-4-28 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.tm.match; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.Vector; import net.heartsome.cat.common.bean.FuzzySearchResult; import net.heartsome.cat.common.bean.TranslationUnitAnalysisResult; import net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean; import net.heartsome.cat.ts.tm.match.extension.ITmMatch; import net.heartsome.cat.ts.tm.resource.Messages; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.SafeRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * 记忆库匹配 * @author jason * @version * @since JDK1.6 */ public class TmMatcher { public static final Logger logger = LoggerFactory.getLogger(TmMatcher.class); private static final String TMMATCH_EXTENSION_ID = "net.heartsome.cat.ts.tm.match.extension"; private ITmMatch tmTranslation; /** * 构造方法 */ public TmMatcher() { runExtension(); } /** * 针对项目检查当前导入器是否可用,主要判断是否存在数据模块和当前项目是否设置了记忆库 * @param project * 当前项目 * @return true可用,false不可用 */ public boolean checkTmMatcher(IProject project) { if (tmTranslation == null) { return false; } return tmTranslation.checkTmMatcher(project); } /** * 查找匹配 * @param project * @param tuInfoBean * @return ; */ public Vector<Hashtable<String, String>> executeSearch(IProject project, TransUnitInfo2TranslationBean tuInfoBean) { Vector<Hashtable<String, String>> dbMatchsVector = new Vector<Hashtable<String, String>>(); if (tmTranslation != null) { tmTranslation.setProject(project); tmTranslation.setTransUnitInfo(tuInfoBean); dbMatchsVector.addAll(tmTranslation.findMatch()); } return dbMatchsVector; } /** * 使用当前项目的记忆库分析翻译单元 * @param project * 当前项目 * @param tuInfoBean * 翻译单元 * @return ; */ public List<TranslationUnitAnalysisResult> analysTranslationUnit(IProject project, TransUnitInfo2TranslationBean tuInfoBean) { if (tmTranslation != null) { tmTranslation.setProject(project); tmTranslation.setTransUnitInfo(tuInfoBean); return tmTranslation.translationUnitAnalysis(); } return new ArrayList<TranslationUnitAnalysisResult>(); } public List<FuzzySearchResult> executeFuzzySearch(IProject project, TransUnitInfo2TranslationBean tuInfoBean) { if (tmTranslation != null) { tmTranslation.setProject(project); tmTranslation.setTransUnitInfo(tuInfoBean); return tmTranslation.fuzzySearch(); } return new ArrayList<FuzzySearchResult>(); } /** * 设置自定义参数,一日设置将不会从首选项中读取关于记忆库的参数 * @param maxMatchSize * 最大匹配个数 * @param isIgnoreTag * 是否忽略标记 * @param minSimilarity * 最小匹配率 * @param isCaseSensitive * 是否区分大小写 * @param contextSize * 上下文个数 ; */ public void setCustomeMatchParameters(int maxMatchSize, boolean isIgnoreTag, int minSimilarity, boolean isCaseSensitive, int contextSize, int tagPenalty) { if (tmTranslation != null) { tmTranslation.setCustomeMatchParameters(maxMatchSize, isIgnoreTag, minSimilarity, isCaseSensitive, contextSize, tagPenalty); } } /** * 设置自定义参数,其他参数将默认取记忆库首选项中的配置 * @param maxMatchSize * 最大匹配个数 * @param minSimilarity * 最大匹配率; */ public void setCustomeMatchParameters(int maxMatchSize, int minSimilarity) { if (tmTranslation != null) { tmTranslation.setCustomeMatchParameters(maxMatchSize, minSimilarity); } } /** * 获取最大匹配个数,如果当前版本不存在数据模块则返回0 * @return ; */ public int getMaxMatchSize() { if (tmTranslation != null) { return tmTranslation.getMaxMatchSize(); } return 0; } public int getTagPenalty() { if (tmTranslation != null) { return tmTranslation.getTagPenalty(); } else { return 2;//默认罚分为2 } } /** * 获取最低匹配率 * @return ; */ public int getMinMatchQuality() { if (tmTranslation != null) { return tmTranslation.getMinMatchQuality(); } return 0; } /** * 查询匹配时,是否忽略标记 * @return ; */ public boolean isIgnoreTag() { if (tmTranslation != null) { return tmTranslation.isIgnoreTag(); } return false; } /** * 获取匹配时检查上下文个数,如果当前版本不存在数据模块则返回0 * @return ; */ public int getContextSize() { if (tmTranslation != null) { return tmTranslation.getContextSize(); } return 0; } /** * 加哉记忆库匹配实现 ; */ private void runExtension() { IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor( TMMATCH_EXTENSION_ID); try { for (IConfigurationElement e : config) { final Object o = e.createExecutableExtension("class"); if (o instanceof ITmMatch) { ISafeRunnable runnable = new ISafeRunnable() { public void handleException(Throwable exception) { logger.error(Messages.getString("match.TmMatcher.logger1"), exception); } public void run() throws Exception { tmTranslation = (ITmMatch) o; } }; SafeRunner.run(runnable); } } } catch (CoreException ex) { logger.error(Messages.getString("match.TmMatcher.logger1"), ex); } } /** * 清理当前翻译实例中的所有资源 * @return ; */ public void clearResources() { if (tmTranslation != null) { tmTranslation.clearResource(); } } /** * 清除当前翻译实例中的数据库资源 ; */ public void clearDbResources() { if (tmTranslation != null) { tmTranslation.clearDbResource(); } } /** * 删除当前匹配面板中显示的数据库及时匹配。<br> * 如果 TU 是多语言对,则只删除当前这个语言的TUV,如果是单语言对则直接删除当前 TU 在记忆库中所有内容 * @param fr 从记忆库中查询出来的匹配结果 * @throws Exception * ; */ public void deleteFuzzyResult(FuzzySearchResult fr) throws Exception { tmTranslation.deleteFuzzyResult(fr); } /** * 更新当前匹配面板中显示数据库及时匹配,只修改源文译文。 * @param fr 从记忆库中查询出来的匹配结果 * @throws Exception * ; */ public void updateFuzzResult(FuzzySearchResult fr) throws Exception { tmTranslation.updateFuzzyResult(fr); } }
7,502
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ITmMatch.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.tm/src/net/heartsome/cat/ts/tm/match/extension/ITmMatch.java
/** * ITmTranslation.java * * Version information : * * Date:2012-4-27 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.tm.match.extension; import java.util.Hashtable; import java.util.List; import java.util.Vector; import net.heartsome.cat.common.bean.FuzzySearchResult; import net.heartsome.cat.common.bean.TranslationUnitAnalysisResult; import net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean; import org.eclipse.core.resources.IProject; /** * @author jason * @version * @since JDK1.6 */ public interface ITmMatch { /** * 查找匹配 * @return ; */ Vector<Hashtable<String, String>> findMatch(); List<FuzzySearchResult> fuzzySearch(); List<TranslationUnitAnalysisResult> translationUnitAnalysis(); /** * 针对当前项目检查当前匹配器是否可用 * @param project * 当前项目 * @return ; */ boolean checkTmMatcher(IProject project); /** * 设置自定义参数 * @param maxMatchSize * @param isIgnoreTag * @param minSimilarity * @param isCaseSensitive * @param contextSize * ; */ void setCustomeMatchParameters(int maxMatchSize, boolean isIgnoreTag, int minSimilarity, boolean isCaseSensitive, int contextSize, int tagPenalty); /** * 设置自定义参数 * @param maxMatchSize * @param minSimilarity * ; */ void setCustomeMatchParameters(int maxMatchSize, int minSimilarity); /** * 设置翻译单元数据 * @param tuInfoBean * ; */ void setTransUnitInfo(TransUnitInfo2TranslationBean tuInfoBean); /** * 设置当前处理的项目 * @param project * ; */ void setProject(IProject project); /** * 获取最大匹配个数 * @return ; */ int getMaxMatchSize(); /** * 获取上下文个数 * @return ; */ int getContextSize(); /** * 获取最小的匹配率 * @return ; */ int getMinMatchQuality(); /** * 获取罚分 * @return ; */ int getTagPenalty(); /** 匹配时,是否忽略标记 */ boolean isIgnoreTag(); /** * 清除当前所有资源 ; */ void clearResource(); /** * 只清除当前数据库资源 * 另参考:{@link #clearResource()} * ; */ public void clearDbResource(); void deleteFuzzyResult(FuzzySearchResult fr) throws Exception; void updateFuzzyResult(FuzzySearchResult fr) throws Exception; }
2,885
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AbstractTmMatch.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.tm/src/net/heartsome/cat/ts/tm/match/extension/AbstractTmMatch.java
/** * AbstractTmTranslation.java * * Version information : * * Date:2012-4-27 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.tm.match.extension; import net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * 记忆库匹配抽象 * @author jason * @version * @since JDK1.6 */ public abstract class AbstractTmMatch implements ITmMatch { public static final Logger logger = LoggerFactory.getLogger(AbstractTmMatch.class); protected TransUnitInfo2TranslationBean tuInfoBean; public AbstractTmMatch() { tuInfoBean = new TransUnitInfo2TranslationBean(); } public void setTransUnitInfo(TransUnitInfo2TranslationBean tuInfoBean) { this.tuInfoBean = tuInfoBean; } }
1,279
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
TmImporter.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.tm/src/net/heartsome/cat/ts/tm/importer/TmImporter.java
/** * TmImporter.java * * Version information : * * Date:2012-5-4 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.tm.importer; import net.heartsome.cat.common.core.exception.ImportException; import net.heartsome.cat.ts.tm.importer.extension.ITmImporter; import net.heartsome.cat.ts.tm.resource.Messages; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.SafeRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * TMX导入器,用于导入符合TMX标准的字符串到当前项目的默认记忆库中<br> * 此类的对象可以重用,重用时需要重新设置当前项目信息{@link #setProject(IProject)}<br> * 当确定此类的对象不需要再用时,需要释放资源{@link #clearResources()}<br> * 释放的资源包括项目记忆库的连接、参数获取对象、项目配置的监听等,当释放资源后,此对象的生命周期方可视为结束 * @author jason * @version * @since JDK1.6 */ public class TmImporter { public static final Logger logger = LoggerFactory.getLogger(TmImporter.class); private final String TMIMPORTER_EXTENSION_ID = "net.heartsome.cat.ts.tm.importer.extension"; private ITmImporter tmImporter; private static TmImporter instance; public static TmImporter getInstance(){ if(instance == null){ instance = new TmImporter(); } return instance; } /** * 检查当前导入器是否可用 * @return true 可用,false不可用 */ public boolean checkImporter(){ if(tmImporter != null && tmImporter.checkImporter()){ return true; } return false; } /** * 构造器 */ private TmImporter() { runExtension(); } /** * 重复设置将不会产生效率问题<br> * 设置当前项目,此信息将用于获取项目的配置信息 * @param project ; */ public void setProject(IProject project){ if(tmImporter != null){ tmImporter.setProject(project); } } public int getContextSize(){ if(tmImporter != null){ return tmImporter.getContextSize(); } return 1; } /** * 清除资源,结束当前导入器的生命周期 * ; */ public void clearResources(){ if(tmImporter != null){ tmImporter.clearResources(); } instance = null; } /** * 执行导入 * @param tmxContent 符合TMX标准的字符串 * @param srcLang 源语言 * @param monitor 进度条,可以为null * @return ; * @throws ImportException */ public int executeImport(String tmxContent, String srcLang, IProgressMonitor monitor) throws ImportException { if (tmImporter != null) { return tmImporter.executeImport(tmxContent, srcLang, monitor); } return ITmImporter.IMPORT_STATE_NONE; } /** * 加载记忆库匹配实现 ; */ private void runExtension() { IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor( TMIMPORTER_EXTENSION_ID); try { for (IConfigurationElement e : config) { final Object o = e.createExecutableExtension("class"); if (o instanceof ITmImporter) { ISafeRunnable runnable = new ISafeRunnable() { public void handleException(Throwable exception) { logger.error(Messages.getString("importer.TmImporter.logger1"), exception); } public void run() throws Exception { tmImporter = (ITmImporter) o; } }; SafeRunner.run(runnable); } } } catch (CoreException ex) { logger.error(Messages.getString("importer.TmImporter.logger1"), ex); } } }
4,254
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ITmImporter.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.tm/src/net/heartsome/cat/ts/tm/importer/extension/ITmImporter.java
/** * ITmImporter.java * * Version information : * * Date:2012-5-4 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.tm.importer.extension; import net.heartsome.cat.common.core.exception.ImportException; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; /** * @author jason * @version * @since JDK1.6 */ public interface ITmImporter { /** 没有执行导入 */ int IMPORT_STATE_NONE = 0; /** 导入成功 */ int IMPORT_STATE_SUCCESSED=1; /** 导入失败 */ int IMPORT_STATE_FAILED= 2; /** 没有数据库 */ int IMPORT_STATE_NODB= 3; /** * 执行导入 * @param tmxContent 符合TMX标准的字符 * @return 1 成功,2 失败; */ int executeImport(String tmxContent,String srcLang, IProgressMonitor monitor) throws ImportException; /** * 设置当前项目 * @param project */ void setProject(IProject project); /** * 释放资源 */ void clearResources(); /** * 获取上下文个数 * @return ; */ int getContextSize(); /** * 检查导入器是否可用,主要针对当前系统是否有库相关插件或者是否设置了默认库 * @return ; */ boolean checkImporter(); }
1,725
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
Messages.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.tm/src/net/heartsome/cat/ts/tm/resource/Messages.java
package net.heartsome.cat.ts.tm.resource; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * 国际化工具类 * @author peason * @version * @since JDK1.6 */ public class Messages { private static final String BUNDLE_NAME = "net.heartsome.cat.ts.tm.resource.message"; private static ResourceBundle BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); public static String getString(String key) { try { return BUNDLE.getString(key); } catch (MissingResourceException e) { return key; } } }
548
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
Activator.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/Activator.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ public class Activator extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable"; // The shared instance private static Activator plugin; /** * The constructor */ public Activator() { } /* * (non-Javadoc) * * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } /* * (non-Javadoc) * * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } /** * Returns the shared instance * @return the shared instance */ public static Activator getDefault() { return plugin; } /** * 提供一个图片文件对插件的相对路径,返回该图片的描述信息。 * @param path * 图片资源对插件的相对路径。 * @return the image descriptor */ public static ImageDescriptor getImageDescriptor(String path) { return imageDescriptorFromPlugin(PLUGIN_ID, path); } }
1,443
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
MixUndoBean.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/MixUndoBean.java
/** * MixUndoBean.java * * Version information : * * Date:2013-5-15 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable; /** * 由于原来的版本中有两种模式,显示模式、编辑模式,造成了每种模式使用独立的方案。后来版本中<br> * 取消了显示模式,要求在编辑模式中就能撤销用户做过的所有更改,此类用于联合两种撤销模式,主<br> * 要作用是缓存重做过程信息。 * @author austen * @version 8.2.3 */ public class MixUndoBean { /** * 未保存的单元格 row */ private int unSaveRow; /** * 未保存的单元格内容 */ private String unSaveText; /** * 跨越焦点的重做的步数,默认为 0 */ private int crosseStep = 0; /** 没有全部保存情况下重做 * 0 未初始化 * 1 未保存 * -1 已保存 * */ private int saveStatus = 0; public int getUnSaveRow() { return unSaveRow; } public void setUnSaveRow(int unSaveRow) { this.unSaveRow = unSaveRow; } public String getUnSaveText() { return unSaveText; } public void setUnSaveText(String unSaveText) { this.unSaveText = unSaveText; } public int getCrosseStep() { return crosseStep; } public void setCrosseStep(int crosseStep) { this.crosseStep = crosseStep; } public int getSaveStatus() { return saveStatus; } public void setSaveStatus(int saveStatus) { this.saveStatus = saveStatus; } }
2,070
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UpdateDataBean.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/UpdateDataBean.java
/** * UpdateDataBean.java * * Version information : * * Date:2012-6-27 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable; /** * @author jason * @version * @since JDK1.6 */ public class UpdateDataBean { private String text; private String matchType; private String quality; public UpdateDataBean() { this.text = ""; this.matchType = null; this.quality = null; } public UpdateDataBean(String text, String matchType, String quality) { this.text = text; this.matchType = matchType; this.quality = quality; } /** @return the text */ public String getText() { return text; } /** * @param text * the text to set */ public void setText(String text) { this.text = text; } /** @return the matchType */ public String getMatchType() { return matchType; } /** * @param matchType * the matchType to set */ public void setMatchType(String matchType) { this.matchType = matchType; } /** @return the quality */ public String getQuality() { return quality; } /** * @param quality * the quality to set */ public void setQuality(String quality) { this.quality = quality; } @Override public String toString() { return text; } }
1,780
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
BodyMenuConfiguration.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/menu/BodyMenuConfiguration.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.menu; import java.util.Collections; import java.util.HashMap; import java.util.Map; import net.heartsome.cat.common.util.CommonFunction; import net.heartsome.cat.ts.ui.xliffeditor.nattable.Activator; import net.heartsome.cat.ts.ui.xliffeditor.nattable.actions.PopupMenuAction; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.ImageConstant; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import net.sourceforge.nattable.NatTable; import net.sourceforge.nattable.config.AbstractUiBindingConfiguration; import net.sourceforge.nattable.grid.GridRegion; import net.sourceforge.nattable.ui.binding.UiBindingRegistry; import net.sourceforge.nattable.ui.matcher.MouseEventMatcher; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.widgets.Menu; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.menus.CommandContributionItem; import org.eclipse.ui.menus.CommandContributionItemParameter; /** * BODY区域右键菜单配置 * @author Leakey,Weachy * @version * @since JDK1.5 */ public class BodyMenuConfiguration extends AbstractUiBindingConfiguration { /** BODY区域的右键菜单. */ private Menu bodyMenu; /** natTable. */ private NatTable table; /** * 得到NatTable对象 * @return ; */ public NatTable getNatTable() { return table; } /** * @param table */ public BodyMenuConfiguration(final XLIFFEditorImplWithNatTable xliffEditor) { this.table = xliffEditor.getTable(); createMenu(); // 将 Menu 保存到 NatTable 中,方便获取(可使用 NatTable.getData(Menu.class.getName()) 获取) table.setData(Menu.class.getName(), bodyMenu); table.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { table.setData(Menu.class.getName(), null); if (bodyMenu != null && !bodyMenu.isDisposed()) { bodyMenu.dispose(); } } }); } /** * (non-Javadoc) * @see net.sourceforge.nattable.config.IConfiguration#configureUiBindings(net.sourceforge.nattable.ui.binding.UiBindingRegistry) */ public void configureUiBindings(UiBindingRegistry uiBindingRegistry) { uiBindingRegistry.registerMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(bodyMenu)); uiBindingRegistry.unregisterMouseDragMode(new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON)); } /** * 编辑界面右键菜单 * @param menu * ; */ private void createMenu() { MenuManager menuMgr = new MenuManager(); bodyMenu = menuMgr.createContextMenu(table.getShell()); if (!CommonFunction.checkEdition("L")) { menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.database.ui.tm.command.ConcordanceSearch", Collections.EMPTY_MAP, Activator.getImageDescriptor(ImageConstant.TU_STATE_SEARCHTM), null, null, Messages.getString("menu.BodyMenuConfiguration.searchTM"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.database.ui.tb.command.TermBaseSearch", Collections.EMPTY_MAP, Activator.getImageDescriptor(ImageConstant.TU_STATE_SEARCHTB), null, null, Messages.getString("menu.BodyMenuConfiguration.searchTermItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new Separator()); } // add by yule -webSearch menuMgr.add(new Separator()); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.websearch.search", Collections.EMPTY_MAP, Activator.getImageDescriptor(ImageConstant.WEB_SEARCH), null, null, Messages.getString("menu.BodyMenuConfiguration.webSearch"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new Separator()); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, ActionFactory.CUT.getCommandId(), Collections.EMPTY_MAP, null, null, null, Messages.getString("menu.BodyMenuConfiguration.cut"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, ActionFactory.COPY.getCommandId(), Collections.EMPTY_MAP, null, null, null, Messages.getString("menu.BodyMenuConfiguration.copy"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, ActionFactory.PASTE.getCommandId(), Collections.EMPTY_MAP, null, null, null, Messages.getString("menu.BodyMenuConfiguration.paste"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new Separator()); // 此处显示出来不做任何事情,是因为用户可以通过右键看到当前状态列中显示的图标是什么含义 // 在状态列中,是无法知道某一图标的具体含义的 menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.nattable.command.untranslated", Collections.EMPTY_MAP, Activator.getImageDescriptor("images/state/not-translated.png"), null, null, Messages.getString("menu.BodyMenuConfiguration.emptyTranslationItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.nattable.command.draft", Collections.EMPTY_MAP, Activator.getImageDescriptor("images/state/draft.png"), null, null, Messages.getString("menu.BodyMenuConfiguration.draftItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); Map<String, String> mapParameter = new HashMap<String, String>(); mapParameter.put("addSegmentToTM", "addToTM"); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.menu.translation.command.completeTranslation", mapParameter, Activator.getImageDescriptor("images/state/translated.png"), null, null, Messages.getString("menu.BodyMenuConfiguration.translatedItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); mapParameter = new HashMap<String, String>(); mapParameter.put("approveSegment", "approveSelectSegment"); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.nattable.command.ApproveSelectSegment", mapParameter, Activator.getImageDescriptor("images/state/approved.png"), null, null, Messages.getString("menu.BodyMenuConfiguration.approveItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.nattable.command.signedOff", Collections.EMPTY_MAP, Activator.getImageDescriptor("images/state/sign-off.png"), null, null, Messages.getString("menu.BodyMenuConfiguration.signItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new Separator()); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.menu.translation.lockSegment.command.lockSegment", Collections.EMPTY_MAP, Activator.getImageDescriptor("images/state/locked.png"), null, null, Messages.getString("menu.BodyMenuConfiguration.isLockItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.nattable.command.needReview", Collections.EMPTY_MAP, Activator.getImageDescriptor("images/state/questioning.png"), null, null, Messages.getString("menu.BodyMenuConfiguration.problemItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.nattable.command.notSendToTM", Collections.EMPTY_MAP, Activator.getImageDescriptor("images/state/not-sent-db.png"), null, null, Messages.getString("menu.BodyMenuConfiguration.disAddToTMItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new Separator()); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.nattable.command.AddNote", Collections.EMPTY_MAP, Activator.getImageDescriptor(ImageConstant.TU_STATE_ADDNOTE), null, null, Messages.getString("menu.BodyMenuConfiguration.addNoteItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.nattable.command.EditNote", Collections.EMPTY_MAP, Activator.getImageDescriptor(ImageConstant.TU_STATE_EDITNOTE), null, null, Messages.getString("menu.BodyMenuConfiguration.editNoteItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.menu.translateContent.command.deleteCurrentSegmentNotes", Collections.EMPTY_MAP, Activator.getImageDescriptor(ImageConstant.TU_STATE_DELETENOTE), null, null, Messages.getString("menu.BodyMenuConfiguration.deleteNoteItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new Separator()); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.menu.translateContent.command.deleteCurrentSegmentTranslations", Collections.EMPTY_MAP, Activator.getImageDescriptor(ImageConstant.TU_STATE_DELETETRANS), null, null, Messages.getString("menu.BodyMenuConfiguration.deleteTransItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); if (CommonFunction.checkEdition("F") || CommonFunction.checkEdition("U")) { menuMgr.add(new Separator()); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.handlexlf.commands.setSplitPointByWordNumCommand", Collections.EMPTY_MAP, null, null, null, Messages.getString("menu.BodyMenuConfiguration.setSplitPointByWordNum"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.handlexlf.commands.nextSplitPointCommand", Collections.EMPTY_MAP, null, null, null, Messages.getString("menu.BodyMenuConfiguration.nextSplitPoint"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); menuMgr.add(new CommandContributionItem( new CommandContributionItemParameter(PlatformUI .getWorkbench(), null, "net.heartsome.cat.ts.ui.xliffeditor.nattable.command.splitXLIFFPoint", Collections.EMPTY_MAP, Activator.getImageDescriptor("images/state/cut-point.png"), null, null, Messages.getString("menu.BodyMenuConfiguration.splitPointItem"), null, null, CommandContributionItem.STYLE_PUSH, null, false))); } } public Menu getMenu() { return bodyMenu; } }
12,700
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
HeaderMenuConfiguration.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/menu/HeaderMenuConfiguration.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.menu; import net.heartsome.cat.ts.ui.xliffeditor.nattable.config.VerticalNatTableConfig; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.sourceforge.nattable.NatTable; import net.sourceforge.nattable.config.AbstractUiBindingConfiguration; import net.sourceforge.nattable.grid.GridRegion; import net.sourceforge.nattable.ui.NatEventData; import net.sourceforge.nattable.ui.binding.UiBindingRegistry; import net.sourceforge.nattable.ui.matcher.MouseEventMatcher; import net.sourceforge.nattable.ui.menu.PopupMenuAction; import net.sourceforge.nattable.ui.menu.PopupMenuBuilder; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.MenuEvent; import org.eclipse.swt.events.MenuListener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.ui.PlatformUI; /** * 基于 NatTable 的 XLIFF Editor 表头、列表的菜单设置 * @author cheney * @since JDK1.6 */ public class HeaderMenuConfiguration extends AbstractUiBindingConfiguration { private final Menu colHeaderMenu; public HeaderMenuConfiguration(NatTable natTable) { // colHeaderMenu = new PopupMenuBuilder(natTable) // .withHideColumnMenuItem() // .withShowAllColumnsMenuItem() // .withCreateColumnGroupsMenuItem() // .withUngroupColumnsMenuItem() // .withColumnChooserMenuItem() // .withAutoResizeSelectedColumnsMenuItem() // .withColumnStyleEditor("Edit styles") // .withColumnRenameDialog("Rename column") // .withCategoriesBasesColumnChooser("Choose columns") // .withClearAllFilters("Clear all filters") // .build(); // 需要隐藏和显示特定列的功能 colHeaderMenu = new PopupMenuBuilder(natTable) /* * 第一项为“隐藏该列”的菜单项,如果以后菜单顺序做了修改,MenuListener中取出此菜单项的索引也要相应改变 */ .withHideColumnMenuItem().withShowAllColumnsMenuItem().build(); colHeaderMenu.addMenuListener(new MenuListener() { public void menuShown(MenuEvent event) { if (colHeaderMenu.getItemCount() > 0) { NatEventData data = (NatEventData) colHeaderMenu.getData(); int columnPosition = data.getColumnPosition(); int columnIndex = data.getNatTable().getColumnIndexByPosition(columnPosition); MenuItem item = colHeaderMenu.getItem(0 /* “隐藏该列”的菜单项的索引 */); XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage().getActiveEditor(); if (xliffEditor == null) { return; } if (xliffEditor.isHorizontalLayout()) { if (columnIndex == 1 || columnIndex == 3) { item.setEnabled(false); } else { item.setEnabled(true); } } else { if (columnIndex == VerticalNatTableConfig.SOURCE_COL_INDEX) { item.setEnabled(false); } else { item.setEnabled(true); } } } } public void menuHidden(MenuEvent e) { } }); // rowHeaderMenu = new PopupMenuBuilder(natTable).withAutoResizeSelectedRowsMenuItem().build(); // cornerHeaderMenu = new PopupMenuBuilder(natTable).withMenuItemProvider(new // AutoResizeALLRowMenuItemProvider()) // .build(); natTable.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { colHeaderMenu.dispose(); // rowHeaderMenu.dispose(); } }); } public void configureUiBindings(UiBindingRegistry uiBindingRegistry) { uiBindingRegistry.registerMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 3), new PopupMenuAction(colHeaderMenu)); // uiBindingRegistry.registerMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 3), // new PopupMenuAction(rowHeaderMenu)); // // uiBindingRegistry.registerMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.CORNER, 3), // new PopupMenuAction(cornerHeaderMenu)); } /** * 重新计算所有行的菜单提供类 * @author cheney * @since JDK1.6 */ // private static final class AutoResizeALLRowMenuItemProvider implements IMenuItemProvider { // // @Override // public void addMenuItem(final NatTable natTable, final Menu popupMenu) { // MenuItem autoResizeRows = new MenuItem(popupMenu, SWT.PUSH); // autoResizeRows.setText("Auto resize all rows"); // autoResizeRows.setEnabled(true); // // autoResizeRows.addSelectionListener(new SelectionAdapter() { // @Override // public void widgetSelected(SelectionEvent event) { // int rowPosition = MenuItemProviders.getNatEventData(event).getRowPosition(); // natTable.doCommand(new InitializeAutoResizeAllRowsCommand(natTable, rowPosition, natTable // .getConfigRegistry(), new GC(natTable))); // } // }); // } // } }
4,927
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
XLIFFEditorCompositeLayerConfiguration.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/config/XLIFFEditorCompositeLayerConfiguration.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.config; import net.heartsome.cat.ts.ui.xliffeditor.nattable.actions.KeyEditAction; import net.heartsome.cat.ts.ui.xliffeditor.nattable.actions.MouseEditAction; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.sourceforge.nattable.config.AggregateConfiguration; import net.sourceforge.nattable.edit.config.DefaultEditBindings; import net.sourceforge.nattable.grid.GridRegion; import net.sourceforge.nattable.grid.cell.AlternatingRowConfigLabelAccumulator; import net.sourceforge.nattable.grid.layer.config.DefaultRowStyleConfiguration; import net.sourceforge.nattable.layer.CompositeLayer; import net.sourceforge.nattable.style.CellStyleAttributes; import net.sourceforge.nattable.style.IStyle; import net.sourceforge.nattable.ui.binding.UiBindingRegistry; import net.sourceforge.nattable.ui.matcher.IKeyEventMatcher; import net.sourceforge.nattable.ui.matcher.KeyEventMatcher; import net.sourceforge.nattable.ui.matcher.LetterOrDigitKeyEventMatcher; import net.sourceforge.nattable.ui.matcher.MouseEventMatcher; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyEvent; /** * 基于 NatTable 的 xliff 编辑中 Grid Layer 的默认 configuration,去除一些不必要 configuration,如单击可编辑单元格就进入编辑状态。 * @author cheney * @since JDK1.5 */ public class XLIFFEditorCompositeLayerConfiguration extends AggregateConfiguration { private IStyle oddStyle; private IStyle evenStyle; private XLIFFEditorImplWithNatTable xliffEditor; /** * Grid Layer 的默认 configuration * @param gridLayer * Grid Layer 对象 */ public XLIFFEditorCompositeLayerConfiguration(CompositeLayer compositeLayer, IStyle oddStyle, IStyle evenStyle, XLIFFEditorImplWithNatTable xliffEditor) { this.xliffEditor = xliffEditor; this.oddStyle = oddStyle; this.evenStyle = evenStyle; addAlternateRowColoringConfig(compositeLayer); addEditingHandlerConfig(); addEditingUIConfig(); } /** * 激活可编辑单元格的 UI 层配置 ; */ protected void addEditingUIConfig() { addConfiguration(new DefaultEditBindings() { KeyEditAction action = new KeyEditAction(); public void configureUiBindings(UiBindingRegistry uiBindingRegistry) { // 在用户点击 Enter 键时,进入编辑状态 uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.NONE, SWT.CR), action); // 在用户点击小键盘的 Enter 键时,进入编辑状态 uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.NONE, SWT.KEYPAD_CR), action); // // 在用户点击 F2 时,进入编辑状态 // uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.NONE, SWT.F2), action); // 在用户点击 whitespace 键时,进入编辑状态 uiBindingRegistry.registerKeyBinding(new IKeyEventMatcher() { public boolean matches(KeyEvent event) { return event.character == ' '; } }, action); // 在用户输入字母或数字时,进入编辑状态 uiBindingRegistry.registerKeyBinding(new LetterOrDigitKeyEventMatcher(), action); // 在用户单击时,进入编辑状态 uiBindingRegistry.registerFirstMouseDownBinding(MouseEventMatcher.bodyLeftClick(SWT.NONE), new MouseEditAction()); uiBindingRegistry.unregisterMouseDragMode(MouseEventMatcher.bodyLeftClick(SWT.NONE)); } }); } /** * Editing Handler 配置 ; */ protected void addEditingHandlerConfig() { addConfiguration(new XLIFFEditorEditConfiguration(xliffEditor)); } /** * 表格中的每行数据以不同的颜色轮流显示的配置 * @param gridLayer * Grid Layer 对象 ; */ protected void addAlternateRowColoringConfig(CompositeLayer compositeLayer) { DefaultRowStyleConfiguration configuration = new DefaultRowStyleConfiguration(); configuration.oddRowBgColor = oddStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); configuration.evenRowBgColor = evenStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); addConfiguration(configuration); compositeLayer.setConfigLabelAccumulatorForRegion(GridRegion.BODY, new AlternatingRowConfigLabelAccumulator()); } }
4,220
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
VerticalNatTableConfig.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/config/VerticalNatTableConfig.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.config; public class VerticalNatTableConfig { /** 行号的列索引 */ public static int ID_COL_INDEX = 0; /** 状态的列索引 */ public static int STATUS_COL_INDEX = 1; /** 源的列索引 */ public static int SOURCE_COL_INDEX = 2; /** 目标的列索引 */ public static int TARGET_COL_INDEX = 2; /** 跨行数 */ public static int ROW_SPAN = 2; /** 在所跨行中,源所占的行 */ public static int SOURCE_INDEX_PER_SPAN = 0; /** 在所跨行中,目标所占的行 */ public static int TARGET_INDEX_PER_SPAN = 1; /** * 是否是“目标”内容 * @param columnIndex * @param rowIndex * @return ; */ public static boolean isSource(int columnIndex, int rowIndex) { return columnIndex == SOURCE_COL_INDEX && rowIndex % VerticalNatTableConfig.ROW_SPAN == SOURCE_INDEX_PER_SPAN; } /** * 是否是“目标”内容 * @param columnIndex * @param rowIndex * @return ; */ public static boolean isTarget(int columnIndex, int rowIndex) { return columnIndex == TARGET_COL_INDEX && rowIndex % VerticalNatTableConfig.ROW_SPAN == TARGET_INDEX_PER_SPAN; } /** * 得到实际的行索引(由于垂直布局下一个翻译单元跨N行,NatTable的行索引也被放大了N倍,通过此方法可以得到相当于水平布局下的行索引) * @param rowIndex * NatTable中的行索引 * @return ; */ public static int getRealRowIndex(int rowIndex) { return rowIndex / ROW_SPAN; } /** * 得到 Source 所在行 * @param realRowIndex * @return ; */ public static int getSourceRowIndex(int realRowIndex) { return realRowIndex * ROW_SPAN; } /** * 得到 Target 所在行 * @param realRowIndex * @return ; */ public static int getTargetRowIndex(int realRowIndex) { return realRowIndex * ROW_SPAN; } }
1,865
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
XLIFFEditorSelectionLayerConfiguration.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/config/XLIFFEditorSelectionLayerConfiguration.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.config; import net.sourceforge.nattable.config.AggregateConfiguration; import net.sourceforge.nattable.config.IConfigRegistry; import net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum; import net.sourceforge.nattable.selection.action.MoveSelectionAction; import net.sourceforge.nattable.selection.action.MoveToFirstRowAction; import net.sourceforge.nattable.selection.action.MoveToLastRowAction; import net.sourceforge.nattable.selection.action.PageDownAction; import net.sourceforge.nattable.selection.action.PageUpAction; import net.sourceforge.nattable.selection.action.SelectCellAction; import net.sourceforge.nattable.selection.config.DefaultMoveSelectionConfiguration; import net.sourceforge.nattable.selection.config.DefaultSelectionBindings; import net.sourceforge.nattable.selection.config.DefaultSelectionStyleConfiguration; import net.sourceforge.nattable.tickupdate.config.DefaultTickUpdateConfiguration; import net.sourceforge.nattable.ui.action.IKeyAction; import net.sourceforge.nattable.ui.action.IMouseAction; import net.sourceforge.nattable.ui.binding.UiBindingRegistry; import net.sourceforge.nattable.ui.matcher.KeyEventMatcher; import net.sourceforge.nattable.ui.matcher.MouseEventMatcher; import net.sourceforge.nattable.util.GUIHelper; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; public class XLIFFEditorSelectionLayerConfiguration extends AggregateConfiguration{ public XLIFFEditorSelectionLayerConfiguration() { addSelectionStyleConfig(); addSelectionUIBindings(); addTickUpdateConfig(); addMoveSelectionConfig(); } protected void addSelectionStyleConfig() { // 去掉表头选中样式和选中单元格样式 DefaultSelectionStyleConfiguration configure = new DefaultSelectionStyleConfiguration(){ @Override protected void configureHeaderHasSelectionStyle(IConfigRegistry configRegistry) { } @Override protected void configureHeaderFullySelectedStyle(IConfigRegistry configRegistry) { } @Override protected void configureSelectionAnchorStyle(IConfigRegistry configRegistry) { } }; configure.selectionBgColor=GUIHelper.getColor(210, 210, 240);//Display.getCurrent().getSystemColor(SWT.COLOR_LIST_SELECTION); configure.selectionFgColor=Display.getCurrent().getSystemColor(SWT.COLOR_BLACK); addConfiguration(configure); } /** * * @see XLIFFEditorCompositeLayerConfiguration#addEditingUIConfig() * ; */ protected void addSelectionUIBindings() { addConfiguration(new DefaultSelectionBindings() { public void configureUiBindings(UiBindingRegistry uiBindingRegistry) { // Move up configureMoveUpBindings(uiBindingRegistry, new MoveSelectionAction(MoveDirectionEnum.UP)); // Move down configureMoveDownBindings(uiBindingRegistry, new MoveSelectionAction(MoveDirectionEnum.DOWN)); // // Move left // configureMoveLeftBindings(uiBindingRegistry, new MoveSelectionAction(MoveDirectionEnum.LEFT)); // // // Move right // configureMoveRightBindings(uiBindingRegistry, new MoveSelectionAction(MoveDirectionEnum.RIGHT)); // Page Up PageUpAction pageUpAction = new PageUpAction(); uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.NONE, SWT.PAGE_UP), pageUpAction); // Page down PageDownAction pageDownAction = new PageDownAction(); uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.NONE, SWT.PAGE_DOWN), pageDownAction); // Home - Move to first column // configureHomeButtonBindings(uiBindingRegistry, new MoveToFirstColumnAction()); // End - Move to last column // configureEndButtonBindings(uiBindingRegistry, new MoveToLastColumnAction()); // Select all // uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.CONTROL, 'a'), new SelectAllAction()); // Copy // uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.CONTROL, 'c'), new CopyDataAction()); // Mouse bindings - select Cell configureBodyMouseClickBindings(uiBindingRegistry); // Mouse bindings - select columns configureColumnHeaderMouseClickBindings(uiBindingRegistry); // Mouse bindings - select rows configureRowHeaderMouseClickBindings(uiBindingRegistry); // Mouse bindings - Drag configureBodyMouseDragMode(uiBindingRegistry); } @Override protected void configureMoveUpBindings(UiBindingRegistry uiBindingRegistry, IKeyAction action) { uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.NONE, SWT.ARROW_UP), action); uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.CONTROL, SWT.HOME), new MoveToFirstRowAction()); } @Override protected void configureMoveDownBindings(UiBindingRegistry uiBindingRegistry, IKeyAction action) { uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.NONE, SWT.ARROW_DOWN), action); uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.CONTROL, SWT.END), new MoveToLastRowAction()); } @Override protected void configureBodyMouseClickBindings(UiBindingRegistry uiBindingRegistry) { // (1)按下 Ctrl 键、Shift 键或者同时按下两者,则执行选中该行。 // (2)只鼠标单击则进入编辑模式:见 XLIFFEditorCompositeLayerConfiguration#addEditingUIConfig() IMouseAction action = new SelectCellAction(); uiBindingRegistry.registerFirstSingleClickBinding(MouseEventMatcher.bodyLeftClick(SWT.SHIFT), action); uiBindingRegistry.registerFirstSingleClickBinding(MouseEventMatcher.bodyLeftClick(SWT.CTRL), action); // uiBindingRegistry.registerFirstSingleClickBinding(MouseEventMatcher.bodyLeftClick(SWT.SHIFT | SWT.CONTROL), action); } @Override protected void configureBodyMouseDragMode(UiBindingRegistry uiBindingRegistry) { // CellSelectionDragMode dragMode = new CellSelectionDragMode(); // uiBindingRegistry.registerMouseDragMode(MouseEventMatcher.bodyLeftClick(SWT.NONE), dragMode); // uiBindingRegistry.registerMouseDragMode(MouseEventMatcher.bodyLeftClick(SWT.SHIFT), dragMode); // uiBindingRegistry.registerMouseDragMode(MouseEventMatcher.bodyLeftClick(SWT.CONTROL), dragMode); // uiBindingRegistry.registerMouseDragMode(MouseEventMatcher.bodyLeftClick(SWT.SHIFT | SWT.CONTROL), dragMode); } }); } protected void addTickUpdateConfig() { addConfiguration(new DefaultTickUpdateConfiguration()); } protected void addMoveSelectionConfig() { addConfiguration(new DefaultMoveSelectionConfiguration()); } }
6,537
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
XLIFFEditorEditConfiguration.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/config/XLIFFEditorEditConfiguration.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.config; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.sourceforge.nattable.config.AbstractLayerConfiguration; import net.sourceforge.nattable.config.IConfigRegistry; import net.sourceforge.nattable.config.IEditableRule; import net.sourceforge.nattable.data.validate.DefaultDataValidator; import net.sourceforge.nattable.edit.EditConfigAttributes; import net.sourceforge.nattable.edit.command.EditCellCommandHandler; import net.sourceforge.nattable.layer.CompositeLayer; public class XLIFFEditorEditConfiguration extends AbstractLayerConfiguration<CompositeLayer> { // private XLIFFEditorImplWithNatTable xliffEditor; public XLIFFEditorEditConfiguration(XLIFFEditorImplWithNatTable xliffEditor) { // this.xliffEditor = xliffEditor; } @Override public void configureTypedLayer(CompositeLayer compositeLayer) { compositeLayer.registerCommandHandler(new EditCellCommandHandler()); } @Override public void configureRegistry(IConfigRegistry configRegistry) { configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE); // configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new StyledTextCellEditor(xliffEditor)); configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DefaultDataValidator()); } }
1,418
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
NatTableSortModel.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/sort/NatTableSortModel.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.sort; import java.util.ArrayList; import java.util.List; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.config.VerticalNatTableConfig; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiCellEditorControl; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.sourceforge.nattable.sort.ISortModel; import net.sourceforge.nattable.sort.SortDirectionEnum; /** * 控制排序的模型 * @author weachy * @version * @since JDK1.5 */ public class NatTableSortModel implements ISortModel { private List<Integer> sortedColumnIndexes; private List<Integer> sortOrders; private List<SortDirectionEnum> sortDirections; private XLFHandler handler; public NatTableSortModel(XLFHandler handler) { sortedColumnIndexes = new ArrayList<Integer>(); sortOrders = new ArrayList<Integer>(); sortDirections = new ArrayList<SortDirectionEnum>(); this.handler = handler; } public SortDirectionEnum getSortDirection(int columnIndex) { if (sortedColumnIndexes.contains(columnIndex)) { return sortDirections.get(sortOrders.indexOf(columnIndex)); } return SortDirectionEnum.NONE; } public int getSortOrder(int columnIndex) { if (sortedColumnIndexes.contains(columnIndex)) { return sortOrders.indexOf(columnIndex); } return -1; } public boolean isColumnIndexSorted(int columnIndex) { return sortedColumnIndexes.contains(columnIndex); } public void sort(int columnIndex, SortDirectionEnum direction, boolean accumulate) { String columnName = null; XLIFFEditorImplWithNatTable xliffEditor = XLIFFEditorImplWithNatTable.getCurrent(); if (xliffEditor == null) { return; } if (xliffEditor.isHorizontalLayout()) { if (columnIndex == xliffEditor.getSrcColumnIndex()) { columnName = "source"; } else if (columnIndex == xliffEditor.getTgtColumnIndex()) { columnName = "target"; } } else { if (columnIndex == VerticalNatTableConfig.SOURCE_COL_INDEX) { columnName = "source"; } } if (columnName == null) { return; } HsMultiActiveCellEditor.commit(true); clear(); sortedColumnIndexes.add(columnIndex); sortOrders.add(columnIndex); sortDirections.add(direction); switch (direction) { case NONE: handler.resetRowIdsToUnsorted(); break; case ASC: handler.sort(columnName, true); break; case DESC: handler.sort(columnName, false); break; default: break; } xliffEditor.autoResize(); // Bug #2317:选中文本段后排序,不会刷新状态栏中的序号 xliffEditor.updateStatusLine(); HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor); } public void clear() { sortedColumnIndexes.clear(); sortOrders.clear(); sortDirections.clear(); } }
2,932
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AddOrUpdateNoteDialog.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/dialog/AddOrUpdateNoteDialog.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog; import java.util.ArrayList; import java.util.List; import java.util.Map; import net.heartsome.cat.common.util.DateUtils; import net.heartsome.cat.common.util.TextUtil; import net.heartsome.cat.ts.core.file.RowIdUtil; import net.heartsome.cat.ts.ui.Activator; import net.heartsome.cat.ts.ui.preferencepage.IPreferenceConstants; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.NatTableConstant; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; /** * Nattable 右键菜单中添加批注对话框 * @author peason * @version * @since JDK1.6 */ public class AddOrUpdateNoteDialog extends Dialog { public static final int DIALOG_ADD = 0; public static final int DIALOG_EDIT = 1; private XLIFFEditorImplWithNatTable xliffEditor; /** 应用范围下拉框 */ private Combo cmbRange; /** 属性 */ private Text txtNote; private int addOrEditDialog; private String[] noteItem; public AddOrUpdateNoteDialog(Shell parentShell, XLIFFEditorImplWithNatTable xliffEditor, int addOrEditDialog, String[] noteItem) { super(parentShell); this.xliffEditor = xliffEditor; this.addOrEditDialog = addOrEditDialog; this.noteItem = noteItem; } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); if (addOrEditDialog == DIALOG_ADD) { newShell.setText(Messages.getString("dialog.AddOrUpdateNoteDialog.title1")); } else if (addOrEditDialog == DIALOG_EDIT) { newShell.setText(Messages.getString("dialog.AddOrUpdateNoteDialog.title2")); } } @Override protected Control createDialogArea(Composite parent) { Composite tparent = (Composite) super.createDialogArea(parent); GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).extendedMargins(5, 5, 5, 5).applyTo(tparent); GridDataFactory.fillDefaults().hint(400, 170).grab(true, true).applyTo(tparent); if (addOrEditDialog == DIALOG_ADD) { new Label(tparent, SWT.None).setText(Messages.getString("dialog.AddOrUpdateNoteDialog.label")); cmbRange = new Combo(tparent, SWT.READ_ONLY); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(cmbRange); cmbRange.setItems(new String[] { NatTableConstant.CURRENT_TEXT, NatTableConstant.ALL_TEXT }); cmbRange.select(0); } Group noteGroup = new Group(tparent, SWT.None); noteGroup.setText(Messages.getString("dialog.AddOrUpdateNoteDialog.noteGroup")); GridDataFactory.fillDefaults().span(2, 1).grab(true, true).applyTo(noteGroup); // noteGroup.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE)); noteGroup.setLayout(new GridLayout()); txtNote = new Text(noteGroup, SWT.BORDER | SWT.WRAP | SWT.MULTI); GridDataFactory.fillDefaults().grab(true, true).applyTo(txtNote); if (addOrEditDialog == DIALOG_EDIT) { txtNote.setText(noteItem[3]); } txtNote.forceFocus(); return tparent; } @Override protected void okPressed() { String strNote = txtNote.getText(); if (strNote == null || strNote.equals("")) { MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddOrUpdateNoteDialog.msgTitle"), Messages.getString("dialog.AddOrUpdateNoteDialog.msg")); return; } String systemUser = Activator.getDefault().getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER); String date = DateUtils.getStringDateShort(); List<String> lstRowId = new ArrayList<String>(); // Bug #2334:添加批注包含特殊字符保存失败 strNote = TextUtil.cleanSpecialString(strNote); if (addOrEditDialog == DIALOG_ADD) { int index = cmbRange.getSelectionIndex(); boolean blnIsApplyCurrent = false; if (index == 0) { lstRowId = xliffEditor.getSelectedRowIds(); blnIsApplyCurrent = true; } else { lstRowId = xliffEditor.getXLFHandler().getRowIds(); } Map<String, List<String>> tmpGroup = RowIdUtil.groupRowIdByFileName(lstRowId); xliffEditor.getXLFHandler().addNote(tmpGroup, DateUtils.getStringDateShort() + ":" + strNote, systemUser, blnIsApplyCurrent); } else if (addOrEditDialog == DIALOG_EDIT) { if (noteItem[4].equalsIgnoreCase(NatTableConstant.CURRENT_TEXT)) { lstRowId.add(xliffEditor.getSelectedRowIds().get(0)); } else if (noteItem[4].equalsIgnoreCase(NatTableConstant.ALL_TEXT)) { lstRowId = xliffEditor.getXLFHandler().getRowIds(); } StringBuffer oldNote = new StringBuffer(); if (noteItem[2] != null && !noteItem[2].equals("")) { oldNote.append(noteItem[2]).append(":"); } oldNote.append(noteItem[3]); Map<String, List<String>> tmpGroup = RowIdUtil.groupRowIdByFileName(lstRowId); StringBuffer sbText = new StringBuffer(date); sbText.append(":").append(strNote); xliffEditor.getXLFHandler().updateNote(tmpGroup, noteItem[1], oldNote.toString(), systemUser, sbText.toString()); } close(); } }
5,494
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
TagNumberRequest.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/dialog/TagNumberRequest.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Dialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; /** * @author Rodolfo M. Raya copyright (c) 2002 - 2003 Heartsome Holdings Pte. Ltd. http://www.heartsome.net */ public class TagNumberRequest extends Dialog { Shell shell; Shell _parent; Text text; Button okButton; int maxValue; int value; Display display; /** * Method numberRequest. * @param display */ public TagNumberRequest(Shell parent, int maxTag) { super(parent, SWT.NONE); _parent = parent; maxValue = maxTag; value = 0; shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); shell.setText(Messages.getString("dialog.TagNumberRequest.title")); shell.setLayout(new GridLayout(1, false)); display = shell.getDisplay(); Composite composite = new Composite(shell, SWT.NONE); composite.setLayout(new GridLayout(2, false)); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); Label label = new Label(composite, SWT.NONE); label.setText(Messages.getString("dialog.TagNumberRequest.lblNumber")); text = new Text(composite, SWT.BORDER); GridData textData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); textData.widthHint = 100; text.setLayoutData(textData); Composite composite2 = new Composite(shell, SWT.BORDER); composite2.setLayout(new GridLayout(2, false)); composite2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); okButton = new Button(composite2, SWT.PUSH); okButton.setText(IDialogConstants.OK_LABEL); okButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); okButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String number = text.getText(); try { int i = Integer.parseInt(number); value = i; if (value < 1 || value > maxValue) { text.setText(""); text.setFocus(); return; } } catch (java.lang.NumberFormatException nfe) { value = 0; text.setText(""); text.setFocus(); return; } shell.close(); } }); Button cancelButton = new Button(composite2, SWT.PUSH | SWT.CANCEL); cancelButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); cancelButton.setText(IDialogConstants.CANCEL_LABEL); cancelButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { value = 0; shell.close(); } }); shell.pack(); text.setFocus(); shell.setDefaultButton(okButton); } /** * Method show. */ public void show() { Rectangle bounds = _parent.getBounds(); shell.setLocation(bounds.x + bounds.width / 3 - shell.getSize().x / 2, bounds.y + bounds.height / 3); shell.open(); shell.forceActive(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } /** * Returns the number. * @return String */ public int getNumber() { return value; } }
3,670
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
CustomFilterDialog.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/dialog/CustomFilterDialog.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; import net.heartsome.cat.ts.core.file.IPreferenceConstants; import net.heartsome.cat.ts.core.file.PreferenceStore; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorReference; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; /** * 定义自定义条件,生成动态的自定义条件的Xpath * @author Leakey * @version * @since JDK1.6 */ public class CustomFilterDialog extends Dialog { /** 自定义过滤器列表. */ private List customFilterList; /** 过滤器列表. */ private Combo cmbFilter; /** 对话框内容区域. */ private Composite tParent; /** 自定义控件滚动条容器. */ private ScrolledComposite scroll; /** 自定义控件容器. */ private Composite dynaComp; /** 过滤器名称文本框. */ private Text filterNameTxt; /** 满足所有条件按钮. */ private Button andBtn; /** 满足任一条件按钮. */ private Button orBtn; /** 灰色. */ private Color gray; /** 黑色. */ private Color black; /** 属性名提醒. */ private final String initPropName = Messages.getString("dialog.CustomFilterDialog.initPropName"); /** 属性值提醒. */ private final String initPropValue = Messages.getString("dialog.CustomFilterDialog.initPropValue"); /** 一般文本框输入提醒. */ private final String initValue = Messages.getString("dialog.CustomFilterDialog.initValue"); /** 验证失败. */ private static final String RESULT_FAILED = "FAILED"; /** 首选项中保存的已有的自定义过滤条件. */ private LinkedHashMap<String, String> customFilters = XLFHandler.getCustomFilterMap(); /** 首选项中保存的已有的自定义过滤条件附加信息. */ private LinkedHashMap<String, String> customFiltersAddition = XLFHandler.getCustomFilterAdditionMap(); /** 首选项中保存的已有的自定义过滤条件(刷新界面使用). */ private LinkedHashMap<String, ArrayList<String[]>> customFiltersIndex = XLFHandler.getCustomFilterIndexMap(); /** * @param shell * @param cmbFilter */ public CustomFilterDialog(Shell shell, Combo cmbFilter) { super(shell); this.cmbFilter = cmbFilter; } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(Messages.getString("dialog.CustomFilterDialog.title")); } @Override protected Control createDialogArea(Composite parent) { gray = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY); black = parent.getDisplay().getSystemColor(SWT.COLOR_BLACK); tParent = (Composite) super.createDialogArea(parent); GridLayoutFactory.swtDefaults().extendedMargins(5, 5, 10, 0).numColumns(2).equalWidth(false).applyTo(tParent); tParent.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite cmpLeft = new Composite(tParent, SWT.BORDER); cmpLeft.setLayout(new GridLayout(2, false)); GridDataFactory.swtDefaults().applyTo(cmpLeft); Composite cmpList = new Composite(cmpLeft, SWT.NONE); cmpList.setLayout(new GridLayout(1, true)); cmpList.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(cmpList, SWT.NONE).setText(Messages.getString("dialog.CustomFilterDialog.c1Lbl")); initCustomFilterList(cmpList); Composite cmpBtn = new Composite(cmpLeft, SWT.None); cmpBtn.setLayout(new GridLayout()); cmpBtn.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); Button addCustom = new Button(cmpBtn, SWT.PUSH); addCustom.setText(Messages.getString("dialog.CustomFilterDialog.addCustom")); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(addCustom); addCustom.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (isChange()) { if (!MessageDialog.openConfirm(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg1"))) { return; } } refresh(); } }); Button delCustom = new Button(cmpBtn, SWT.PUSH); delCustom.setText(Messages.getString("dialog.CustomFilterDialog.delCustom")); GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).applyTo(delCustom); delCustom.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String[] filters = customFilterList.getSelection(); if (filters != null && filters.length > 0) { if (MessageDialog.openConfirm(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg2"))) { for (int i = 0; i < filters.length; i++) { customFilters.remove(filters[i]); customFiltersAddition.remove(filters[i]); customFiltersIndex.remove(filters[i]); IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { IEditorReference[] editors = page.getEditorReferences(); for(IEditorReference ef : editors){ IEditorPart editor = ef.getEditor(false); if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) { Combo cb = ((XLIFFEditorImplWithNatTable) editor).getFilterCombo(); if(cb != null && !cb.isDisposed()){ cb.remove(filters[i]); } } } } } // cmbFilter.remove(filters[i]); customFilterList.remove(filters[i]); XLFHandler.getFilterMap().remove(filters[i]); } PreferenceStore.saveMap(IPreferenceConstants.FILTER_CONDITION, customFilters); PreferenceStore.saveCustomCondition(IPreferenceConstants.FILTER_CONDITION_INDEX, customFiltersIndex); } } else { MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg3")); } } }); Button editCustom = new Button(cmpBtn, SWT.PUSH); editCustom.setText(Messages.getString("dialog.CustomFilterDialog.editCustom")); GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).applyTo(editCustom); editCustom.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { edit(); } }); Composite cmpRight = new Composite(tParent, SWT.NONE); cmpRight.setLayout(new GridLayout(1, true)); cmpRight.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite top = new Composite(cmpRight, SWT.NONE); top.setLayout(new GridLayout(2, false)); top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(top, SWT.NONE).setText(Messages.getString("dialog.CustomFilterDialog.topLbl")); filterNameTxt = new Text(top, SWT.BORDER); filterNameTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); filterNameTxt.forceFocus(); top = new Composite(cmpRight, SWT.NONE); top.setLayout(new GridLayout(2, false)); top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); andBtn = new Button(top, SWT.RADIO); andBtn.setText(Messages.getString("dialog.CustomFilterDialog.andBtn")); andBtn.setSelection(true); orBtn = new Button(top, SWT.RADIO); orBtn.setText(Messages.getString("dialog.CustomFilterDialog.orBtn")); scroll = new ScrolledComposite(cmpRight, SWT.V_SCROLL | SWT.BORDER); scroll.setAlwaysShowScrollBars(true); scroll.setLayoutData(new GridData(GridData.FILL_BOTH)); scroll.setExpandHorizontal(true); scroll.setExpandVertical(true); // scroll.setSize(500, 200); dynaComp = new Composite(scroll, SWT.None); scroll.setContent(dynaComp); dynaComp.setLayout(new GridLayout(1, true)); new DynaComposite(dynaComp, SWT.NONE); return parent; } /** * 编辑 */ private void edit() { String[] filters = customFilterList.getSelection(); if (filters.length > 0) { if (isChange()) { if (!MessageDialog.openConfirm(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg1"))) { return; } } String key = filters[0]; filterNameTxt.setText(key); String link = XLFHandler.getCustomFilterAdditionMap().get(key); if (link.indexOf("and") != -1) { andBtn.setSelection(true); orBtn.setSelection(false); } else { andBtn.setSelection(false); orBtn.setSelection(true); } for (Control ctl : conditionList) { if (!ctl.isDisposed()) { ctl.dispose(); } } conditionList.clear(); ArrayList<String[]> tmpList = XLFHandler.getCustomFilterIndexMap().get(key); for (String[] tempIndex : tmpList) { String filterIndex = tempIndex[0]; DynaComposite dyna = new DynaComposite(dynaComp, SWT.NONE); dyna.getFilterName().select(Integer.parseInt(filterIndex)); dyna.getFilterName().notifyListeners(SWT.Selection, null); if ("0".equals(filterIndex) || "1".equals(filterIndex)) { // 关键字、批注 dyna.getConditions().select(Integer.parseInt(tempIndex[1])); dyna.getValue().setText(tempIndex[2].replace("0x0020", " ")); dyna.getValue().setForeground(black); } else if ("2".equals(filterIndex)) { // 属性 dyna.getPropName().setText(tempIndex[1]); dyna.getPropValue().setText(tempIndex[2]); dyna.getPropName().setForeground(black); dyna.getPropValue().setForeground(black); } } scroll.setMinSize(dynaComp.computeSize(SWT.DEFAULT, SWT.DEFAULT)); dynaComp.layout(); } else { MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg4")); } } /** * 查看当前状态是否为新增 * @return 当前状态是否为新增 */ private boolean isAdd() { return !XLFHandler.getCustomFilterMap().containsKey(filterNameTxt.getText()); } /** * 刷新过滤器设置组件 */ private void refresh() { filterNameTxt.setText(""); andBtn.setSelection(true); orBtn.setSelection(false); for (Control ctl : conditionList) { if (!ctl.isDisposed()) { ctl.dispose(); } } conditionList.clear(); new DynaComposite(dynaComp, SWT.NONE); scroll.setMinSize(dynaComp.computeSize(SWT.DEFAULT, SWT.DEFAULT)); dynaComp.layout(); } /** * 初始化自定义过滤器列表 * @param comp * 父容器 */ private void initCustomFilterList(Composite comp) { customFilterList = new List(comp, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); gridData.widthHint = 110; gridData.heightHint = 250; customFilterList.setLayoutData(gridData); setListData(customFilterList, customFilters); customFilterList.addMouseListener(new MouseAdapter() { @Override public void mouseDoubleClick(MouseEvent e) { edit(); } }); } @Override protected void createButtonsForButtonBar(Composite parent) { super.createButtonsForButtonBar(parent); Button okBtn = getButton(IDialogConstants.OK_ID); okBtn.setText(Messages.getString("dialog.CustomFilterDialog.okBtn")); Button cancelBtn = getButton(IDialogConstants.CANCEL_ID); cancelBtn.setText(Messages.getString("dialog.CustomFilterDialog.cancelBtn")); } @Override protected void cancelPressed() { close(); } @Override public boolean close() { if (isChange()) { if (MessageDialog.openConfirm(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg5"))) { return super.close(); } } else { return super.close(); } return false; } /** * 查看在新增和编辑状态下内容是否有变化 * @return 内容是否有变化 */ private boolean isChange() { boolean result = false; if (isAdd()) { if (!filterNameTxt.getText().trim().equals("")) { result = true; } if (andBtn.getSelection()) { if (conditionList.size() > 1) { result = true; } else { DynaComposite comp = conditionList.get(0); if (comp.getFilterName().getSelectionIndex() != 0) { result = true; } else { if (comp.getConditions().getSelectionIndex() != 0) { result = true; } else { if (!comp.getValue().getText().equals(initValue)) { result = true; } } } } } else { result = true; } } else { String orignXpath = XLFHandler.getCustomFilterMap().get(filterNameTxt.getText()); StringBuilder xpath = new StringBuilder(); String link = andBtn.getSelection() ? " and " : " or "; for (DynaComposite comp : conditionList) { // 得到所有自定义条件组合的xpath String tempXpath = comp.getXpath(false); if (RESULT_FAILED.equals(tempXpath)) { result = true; } xpath.append(tempXpath).append(link); } if (xpath.length() > 0) { xpath.delete(xpath.length() - link.length(), xpath.length()); result = !orignXpath.equals(xpath.toString()); } } return result; } @Override protected void okPressed() { String filterNameStr = filterNameTxt.getText(); if (filterNameStr == null || "".equals(filterNameStr)) { MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg6")); return; } StringBuilder xpath = new StringBuilder(); String link = andBtn.getSelection() ? " and " : " or "; ArrayList<String[]> tempValue = new ArrayList<String[]>(); for (DynaComposite comp : conditionList) { // 得到所有自定义条件组合的xpath String tempXpath = comp.getXpath(true); if (RESULT_FAILED.equals(tempXpath)) { return; } xpath.append(tempXpath).append(link); tempValue.add(comp.getTempIndex()); } if (xpath.length() > 0) { if (isAdd()) { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { IEditorReference[] editors = page.getEditorReferences(); for(IEditorReference e : editors){ IEditorPart editor = e.getEditor(false); if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) { Combo cb = ((XLIFFEditorImplWithNatTable) editor).getFilterCombo(); if(cb != null && !cb.isDisposed()){ cb.add(filterNameTxt.getText()); } } } } } // cmbFilter.add(filterNameTxt.getText()); } else { XLFHandler.getFilterMap().put(filterNameTxt.getText(), xpath.substring(0, xpath.lastIndexOf(link))); } customFilters.put(filterNameStr, xpath.substring(0, xpath.lastIndexOf(link))); customFiltersAddition.put(filterNameStr, link.trim()); customFiltersIndex.put(filterNameStr, tempValue); PreferenceStore.saveMap(IPreferenceConstants.FILTER_CONDITION, new TreeMap<String, String>(customFilters)); PreferenceStore.saveMap(IPreferenceConstants.FILTER_CONDITION_ADDITION, customFiltersAddition); PreferenceStore.saveCustomCondition(IPreferenceConstants.FILTER_CONDITION_INDEX, customFiltersIndex); reload(); } } /** * 重新加载自定义过滤器列表数据和刷新右侧过滤器设置组件 */ private void reload() { setListData(customFilterList, XLFHandler.getCustomFilterMap()); refresh(); } /** 自定义条件组件列表. */ private ArrayList<DynaComposite> conditionList = new ArrayList<DynaComposite>(); /** 过滤器条件数据. */ static LinkedHashMap<Integer, String> filterNameData = new LinkedHashMap<Integer, String>(); /** 条件数据. */ static LinkedHashMap<Integer, String> conditionsData = new LinkedHashMap<Integer, String>(); /** 只包含相等与不相等的条件数据. */ static LinkedHashMap<Integer, String> equalsConditionsData = new LinkedHashMap<Integer, String>(); static { String[] tmpValue = new String[] { Messages.getString("dialog.CustomFilterDialog.tmpValue1"), Messages.getString("dialog.CustomFilterDialog.tmpValue2"), Messages.getString("dialog.CustomFilterDialog.tmpValue3") }; for (int i = 0; i < tmpValue.length; i++) { filterNameData.put(i, tmpValue[i]); } conditionsData.put(0, Messages.getString("dialog.CustomFilterDialog.contain")); conditionsData.put(1, Messages.getString("dialog.CustomFilterDialog.uncontain")); conditionsData.put(2, Messages.getString("dialog.CustomFilterDialog.eq")); conditionsData.put(3, Messages.getString("dialog.CustomFilterDialog.neq")); equalsConditionsData.put(0, Messages.getString("dialog.CustomFilterDialog.eq")); equalsConditionsData.put(1, Messages.getString("dialog.CustomFilterDialog.neq")); // String[] states = { "new", "final", "translated", "signed-off", "needs-adaptation", // "needs-review-adaptation", // "needs-l10n", "needs-review-l10n", "needs-translation", "needs-review-translation" }; // for (int i = 0; i < states.length; i++) { // stateData.put(i, states[i]); // } } /** * 动态自定义条件组件 * @author Leakey * @version * @since JDK1.6 */ class DynaComposite extends Composite { /** 过滤器列表控件. */ private Combo filterName; /** 判断条件列表控件. */ private Combo conditions; /** 一般文本框. */ private Text value; /** +按钮. */ private Button addBtn; /** -按钮. */ private Button reduceBtn; /** 属性名与值文本框容器. */ private Composite propComp; /** 属性名文本框. */ private Text propName; /** 属性值文本框. */ private Text propValue; /** 当前选中的过滤器是否是(关键字、批注等). */ private boolean isOther = true; /** 当前选中的过滤器是否是属性. */ private boolean isProp = false; private String[] tempIndex = null; /** * 获取当前设置情况(用来保存在首选项中刷新时候用) */ public String[] getTempIndex() { return tempIndex; } /** * 获取子过滤器名称列表组件 */ public Combo getFilterName() { return filterName; } /** * 获取条件组合 */ public Combo getConditions() { return conditions; } /** * 获取属性名组件 */ public Text getPropName() { return propName; } /** * 获取属性值组件 */ public Text getPropValue() { return propValue; } /** * 获取一般值组件 */ public Text getValue() { return value; } /** * @param parent * @param style */ public DynaComposite(Composite parent, int style) { super(parent, style); init(); conditionList.add(this); } /** * 销毁除了“过滤器列表控件”之外的其它控件 */ private void disposeChild() { for (Control ctl : this.getChildren()) { if (!"filterName".equals(ctl.getData()) && ctl != null && !ctl.isDisposed()) { ctl.dispose(); } } } /** * 初始化自定义条件组件 */ private void init() { this.setLayout(new GridLayout(5, false)); this.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); initFilterName(); initConditions(true); initTxt(); initBtn(); } /** * 初始化“+”,“-”按钮 */ private void initBtn() { addBtn = new Button(this, SWT.None); addBtn.setText("+"); addBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { new DynaComposite(dynaComp, SWT.NONE); scroll.setMinSize(dynaComp.computeSize(SWT.DEFAULT, SWT.DEFAULT)); dynaComp.layout(); } }); reduceBtn = new Button(this, SWT.None); reduceBtn.setText("-"); reduceBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { conditionList.remove(DynaComposite.this); DynaComposite.this.dispose(); scroll.setMinSize(dynaComp.computeSize(SWT.DEFAULT, SWT.DEFAULT)); dynaComp.layout(); } }); if (conditionList.size() > 0) { if (conditionList.get(0).equals(this)) { reduceBtn.setEnabled(false); } else { reduceBtn.setEnabled(true); } } else { reduceBtn.setEnabled(false); } } /** * 初始化一般文本框 */ private void initTxt() { value = new Text(this, SWT.BORDER); if(filterName.getSelectionIndex() == 1){ setGray(value, initValue); value.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); return; } value.setForeground(gray); value.setText(initValue); value.addFocusListener(new FocusListener() { public void focusLost(FocusEvent arg0) { if (value.getText().equals("")) { if (!value.getForeground().equals(gray)) { value.setForeground(gray); } value.setText(initValue); } else { if (!value.getForeground().equals(black)) { value.setForeground(black); } } } public void focusGained(FocusEvent arg0) { if (value.getText().equals(initValue)) { value.setText(""); value.setForeground(black); } else { if (!value.getForeground().equals(black)) { value.setForeground(black); } } } }); value.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } /** * 初始化属性名和属性值两个文本框 * @param comp * 文本框父容器 */ private void initPropTxt(Composite comp) { propName = new Text(comp, SWT.BORDER); GridData data = new GridData(115, SWT.DEFAULT); propName.setLayoutData(data); setGray(propName, initPropName); propValue = new Text(comp, SWT.BORDER); setGray(propValue, initPropValue); propValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } /** * 初始化判断条件列表控件 * @param isContain * 是否具有包含与不包含条件 */ private void initConditions(boolean isContain) { conditions = new Combo(this, SWT.READ_ONLY); conditions.setLayoutData(new GridData(100, 35)); if (isContain) { setComboData(conditions, conditionsData); } else { setComboData(conditions, equalsConditionsData); } conditions.select(0); } /** * 初始化过滤器列表控件 */ private void initFilterName() { filterName = new Combo(this, SWT.READ_ONLY); filterName.setLayoutData(new GridData(80, 35)); setComboData(filterName, filterNameData); filterName.setData("filterName"); filterName.select(0); filterName.addSelectionListener(new SelectionAdapter() { private boolean isState() { return filterName.getSelectionIndex() == 1; } private boolean isProp() { return filterName.getSelectionIndex() == 2; } private boolean isOther() { return !isState() && !isProp(); } private void createProp() { disposeChild(); initTempComp(); initPropTxt(propComp); initBtn(); } private void createOther() { disposeChild(); initConditions(true); initTxt(); initBtn(); } private void initTempComp() { propComp = new Composite(DynaComposite.this, SWT.READ_ONLY); GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; propComp.setLayoutData(gd); GridLayoutFactory.fillDefaults().numColumns(2).applyTo(propComp); } @Override public void widgetSelected(SelectionEvent e) { if (!isProp && isProp()) { createProp(); isProp = true; isOther = false; } else/* if (!isOther && isOther())*/ { createOther(); isOther = true; isProp = false; } DynaComposite.this.layout(); } }); } /** * 取得xpath查询语句 * @return xpath查询语句 */ public String getXpath(boolean withNotice) { StringBuilder re = new StringBuilder(); int contain = 0; int notContain = 1; int equal = 2; int notEqual = 3; int condition = -1; if (conditions != null && !conditions.isDisposed()) { String temp = conditions.getItem(conditions.getSelectionIndex()); // if (temp.indexOf("不") != -1) { // if (temp.indexOf("包含") != -1) { // condition = notContain; // } else { // condition = notEqual; // } // } else { // if (temp.indexOf("包含") != -1) { // condition = contain; // } else { // condition = equal; // } // } // modify by peason --->2012-07-07 if (temp.equals(Messages.getString("dialog.CustomFilterDialog.uncontain"))) { condition = notContain; } else if (temp.equals(Messages.getString("dialog.CustomFilterDialog.neq"))) { condition = notEqual; } else if (temp.equals(Messages.getString("dialog.CustomFilterDialog.contain"))) { condition = contain; } else if (temp.equals(Messages.getString("dialog.CustomFilterDialog.eq"))) { condition = equal; } } if (isOther) { String txt = value.getText().trim(); if (filterName.getSelectionIndex() == 0) { // 关键字 txt = value.getText(); if (txt.equals("") || txt.equals(initValue)) { if (withNotice) { MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg7")); } return RESULT_FAILED; } if (condition == contain) { re.append("contains(source/text(), '").append(txt).append("')"); } else if (condition == notContain) { re.append("not(contains(source/text(), '").append(txt).append("'))"); } else if (condition == equal) { re.append("source/text()='").append(txt).append("'"); } else if (condition == notEqual) { re.append("source/text()!='").append(txt).append("'"); } txt = txt.replace(" ", "0x0020"); } else if (filterName.getSelectionIndex() == 1) { // 批注 if (txt.equals("") || txt.equals(initValue)) { if (withNotice) { MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg8")); } return RESULT_FAILED; } if (condition == contain) { re.append("contains(note/text(), '").append(txt).append("')"); } else if (condition == notContain) { re.append("not(contains(note/text(), '").append(txt).append("'))"); } else if (condition == equal) { re.append("note/text()='").append(txt).append("'"); } else if (condition == notEqual) { re.append("not(note/text()='").append(txt).append("'))"); } } tempIndex = new String[] { filterName.getSelectionIndex() + "", conditions.getSelectionIndex() + "", txt }; } else if (isProp) { // 属性 String propNameStr = propName.getText().trim(); String propValueStr = propValue.getText().trim(); if (propNameStr.equals("") || propNameStr.equals(initPropName)) { if (withNotice) { MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.initPropName")); } return RESULT_FAILED; } if (propValueStr.equals("") || propValueStr.equals(initPropValue)) { if (withNotice) { MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.initPropValue")); } return RESULT_FAILED; } re.append("hs:prop-group/hs:prop[@prop-type='").append(propNameStr).append("']='").append(propValueStr) .append("'"); tempIndex = new String[] { filterName.getSelectionIndex() + "", propNameStr, propValueStr }; } return re.toString(); } } /** * 设置Combo下拉列表中的数据 * @param combo * 下拉列表 * @param data * 数据、key=索引,value=显示的文字 */ private void setComboData(Combo combo, Map<Integer, String> data) { for (Entry<Integer, String> entry : data.entrySet()) { combo.add(entry.getValue(), entry.getKey()); } } /** * 为List组件设置数据 * @param list * @param data */ private void setListData(List list, Map<String, String> data) { list.removeAll(); if (data == null || data.size() == 0) { return; } for (Entry<String, String> entry : data.entrySet()) { list.add(entry.getKey()); } } /** * 为Text控件增加灰色提醒,获得焦点时自动清除灰色提醒 * @param text * Text控件 * @param initTxt * 灰色提醒字符串 */ private void setGray(final Text text, final String initTxt) { text.setForeground(gray); text.setText(initTxt); text.addFocusListener(new FocusListener() { public void focusLost(FocusEvent arg0) { if (text.getText().trim().equals("")) { if (!text.getForeground().equals(gray)) { text.setForeground(gray); } text.setText(initTxt); } else { if (!text.getForeground().equals(black)) { text.setForeground(black); } } } public void focusGained(FocusEvent arg0) { if (text.getText().trim().equals(initTxt)) { text.setText(""); text.setForeground(black); } else { if (!text.getForeground().equals(black)) { text.setForeground(black); } } } }); } }
29,983
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
CustomMatchConditionDialog.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/dialog/CustomMatchConditionDialog.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; import net.heartsome.cat.ts.core.bean.Constants; import net.heartsome.cat.ts.core.file.IPreferenceConstants; import net.heartsome.cat.ts.core.file.PreferenceStore; import net.heartsome.cat.ts.core.file.XLFHandler; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; /** * 定制匹配条件对话框(此类未使用,因此未做国际化) * @author Leakey * @version * @since JDK1.5 */ public class CustomMatchConditionDialog extends Dialog { /** 自定义过滤器列表. */ private List customFilterList; /** 对话框内容区域. */ private Composite tParent; /** 自定义控件滚动条容器. */ private ScrolledComposite scroll; /** 自定义控件容器. */ private Composite dynaComp; /** 过滤器名称文本框. */ private Text filterNameTxt; /** 满足所有条件按钮. */ private Button andBtn; /** 满足任一条件按钮. */ private Button orBtn; /** 首选项中保存的已有的自定义过滤条件. */ private LinkedHashMap<String, String> customFilters = XLFHandler.getCustomMatchFilterMap(); /** 首选项中保存的已有的自定义过滤条件(附加信息). */ LinkedHashMap<String, ArrayList<String[]>> customFiltersAddtion = XLFHandler.getCustomMatchFilterAdditionMap(); /** 首选项中保存的已有的自定义过滤条件(刷新界面使用). */ private LinkedHashMap<String, ArrayList<String[]>> customFiltersIndex = XLFHandler.getCustomMatchFilterIndexMap(); /** 标记的匹配按钮. */ private Button btnIsTagged; /** 快速翻译匹配按钮. */ private Button btnQT; /** 自动繁殖翻译匹配按钮. */ private Button btnPT; /** 从来源中删除按钮. */ private Button btnIsRemoveFromSrc; /** 选中“标记的匹配按钮”的值. */ private int btnIsTaggedCheck = 1 << 1; /** 选中“快速翻译匹配按钮”的值. */ private int btnQTCheck = 1 << 2; /** 选中“自动繁殖翻译匹配按钮”的值. */ private int btnPTCheck = 1 << 3; /** 选中“从来源中删除按钮”的值. */ private int btnIsRemoveFromSrcCheck = 1 << 4; /** * 得到标记的匹配、快速翻译匹配、自动繁殖翻译匹配、从来源中删除四个按钮的选择情况 * @return 选择组合的结果 */ private int getCheck() { int result = 1 << 5; if (btnIsTagged != null && btnIsTagged.getSelection()) { result = result | btnIsTaggedCheck; } if (btnQT != null && btnQT.getSelection()) { result = result | btnQTCheck; } if (btnPT != null && btnPT.getSelection()) { result = result | btnPTCheck; } if (btnIsRemoveFromSrc != null && btnIsRemoveFromSrc.getSelection()) { result = result | btnIsRemoveFromSrcCheck; } return result; } /** 灰色. */ private Color gray; /** 黑色. */ private Color black; /** 自定义条件组件列表. */ private ArrayList<DynaComposite> conditionList = new ArrayList<DynaComposite>(); /** 一般文本框输入提醒. */ private final String initValue = "请输入值"; /** 验证失败. */ private static final String RESULT_FAILED = "FAILED"; /** * @param shell */ public CustomMatchConditionDialog(Shell shell) { super(shell); } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText("自定义删除匹配条件"); } @Override protected void createButtonsForButtonBar(Composite parent) { super.createButtonsForButtonBar(parent); Button okBtn = getButton(IDialogConstants.OK_ID); okBtn.setText("保存"); Button cancelBtn = getButton(IDialogConstants.CANCEL_ID); cancelBtn.setText("关闭"); } /** * 删除保存在首选项中的所有与指定条件相关的数据 * @param key 条件名 */ private void deletePreference(String[] key) { if (key == null || key.length == 0) { return; } for (int i = 0; i < key.length; i++) { customFilters.remove(key[i]); customFiltersAddtion.remove(key[i]); customFiltersIndex.remove(key[i]); customFilterList.remove(key[i]); } PreferenceStore.saveMap(IPreferenceConstants.MATCH_CONDITION, customFilters); PreferenceStore.saveCustomCondition(IPreferenceConstants.MATCH_CONDITION_ADDITION, customFiltersAddtion); PreferenceStore.saveCustomCondition(IPreferenceConstants.MATCH_CONDITION_INDEX, customFiltersIndex); } @Override protected Control createDialogArea(Composite parent) { gray = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY); black = parent.getDisplay().getSystemColor(SWT.COLOR_BLACK); tParent = (Composite) super.createDialogArea(parent); tParent.setLayout(new GridLayout(2, false)); tParent.setLayoutData(new GridData(720, 410)); Composite c = new Composite(tParent, SWT.BORDER); c.setLayout(new GridLayout(2, false)); c.setLayoutData(new GridData(200, 388)); Composite c1 = new Composite(c, SWT.NONE); c1.setLayout(new GridLayout(1, true)); c1.setLayoutData(new GridData(150, 380)); new Label(c1, SWT.NONE).setText("自定义过滤器:"); initCustomFilterList(c1); Composite c2 = new Composite(c, SWT.NONE); RowLayout rowLayout = new RowLayout(SWT.VERTICAL); rowLayout.marginLeft = 0; rowLayout.marginTop = 150; rowLayout.spacing = 5; c2.setLayout(rowLayout); c2.setLayoutData(new GridData(50, 380)); Button addCustom = new Button(c2, SWT.PUSH); addCustom.setText("新增"); addCustom.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // 新增自定义过滤器方法 if (isChange()) { if (!MessageDialog.openConfirm(getShell(), "", "不保存当前内容吗?")) { return; } } refresh(); } }); Button delCustom = new Button(c2, SWT.PUSH); delCustom.setText("删除"); delCustom.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // 删除已保存的自定义过滤器方法 String[] filters = customFilterList.getSelection(); if (filters != null && filters.length > 0) { if (MessageDialog.openConfirm(getShell(), "", "确定要删除选中的自定义过滤器吗?")) { deletePreference(filters); } } else { MessageDialog.openInformation(getShell(), "", "请选择要删除的自定义过滤器。"); } } }); Button editCustom = new Button(c2, SWT.PUSH); editCustom.setText("编辑"); editCustom.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // 编辑已有的自定义过滤器方法 edit(); } }); Composite c3 = new Composite(tParent, SWT.NONE); c3.setLayout(new GridLayout(1, true)); c3.setLayoutData(new GridData(500, 400)); Composite top = new Composite(c3, SWT.NONE); top.setLayout(new GridLayout(2, false)); new Label(top, SWT.NONE).setText("过滤器名称:"); filterNameTxt = new Text(top, SWT.BORDER); filterNameTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); andBtn = new Button(top, SWT.RADIO); andBtn.setText("满足所有条件"); andBtn.setSelection(true); orBtn = new Button(top, SWT.RADIO); orBtn.setText("满足以下任一条件"); scroll = new ScrolledComposite(c3, SWT.V_SCROLL | SWT.BORDER); scroll.setAlwaysShowScrollBars(true); scroll.setLayoutData(new GridData(470, 250)); scroll.setExpandHorizontal(true); scroll.setExpandVertical(true); dynaComp = new Composite(scroll, SWT.BORDER); scroll.setContent(dynaComp); dynaComp.setLayout(new GridLayout(1, true)); new DynaComposite(dynaComp, SWT.NONE); Composite c4 = new Composite(c3, SWT.BORDER); c4.setLayout(new GridLayout(2, true)); c4.setLayoutData(new GridData(470,60)); btnIsTagged = new Button(c4, SWT.CHECK); btnIsTagged.setText("标记的匹配"); btnQT = new Button(c4, SWT.CHECK); btnQT.setText("快速翻译匹配"); btnPT = new Button(c4, SWT.CHECK); // propagate translation btnPT.setText("自动繁殖翻译匹配"); if (isTEInstalled()) { btnIsRemoveFromSrc = new Button(c4, SWT.CHECK); btnIsRemoveFromSrc.setText("从来源中删除"); } return parent; } /** * 编辑 */ private void edit() { String[] filters = customFilterList.getSelection(); if (filters.length > 0) { if (isChange()) { if (!MessageDialog.openConfirm(getShell(), "", "不保存当前内容吗?")) { return; } } String key = filters[0]; filterNameTxt.setText(key); String[] tempArray = XLFHandler.getCustomMatchFilterAdditionMap().get(key).get(0); if (tempArray[0].indexOf("and") != -1) { andBtn.setSelection(true); orBtn.setSelection(false); } else { andBtn.setSelection(false); orBtn.setSelection(true); } int check = Integer.parseInt(tempArray[1]); if (btnIsTagged != null) { if ((check & btnIsTaggedCheck) != 0) { btnIsTagged.setSelection(true); } else { btnIsTagged.setSelection(false); } } if (btnQT != null) { if ((check & btnQTCheck) != 0) { btnQT.setSelection(true); } else { btnQT.setSelection(false); } } if (btnPT != null) { if ((check & btnPTCheck) != 0) { btnPT.setSelection(true); } else { btnPT.setSelection(false); } } if (btnIsRemoveFromSrc != null) { if ((check & btnIsRemoveFromSrcCheck) != 0) { btnIsRemoveFromSrc.setSelection(true); } else { btnIsRemoveFromSrc.setSelection(false); } } for (Control ctl : conditionList) { if (!ctl.isDisposed()) { ctl.dispose(); } } conditionList.clear(); ArrayList<String[]> tmpList = XLFHandler.getCustomMatchFilterIndexMap().get(key); for (String[] tempIndex : tmpList) { String filterIndex = tempIndex[0]; DynaComposite dyna = new DynaComposite(dynaComp, SWT.NONE); dyna.getFilterName().select(Integer.parseInt(filterIndex)); dyna.getFilterName().notifyListeners(SWT.Selection, null); if ("0".equals(filterIndex)) { // 匹配率 dyna.getConditions().select(Integer.parseInt(tempIndex[1])); dyna.getValue().setText(tempIndex[2]); } else if ("1".equals(filterIndex)) { // 关键字 dyna.getConditions().select(Integer.parseInt(tempIndex[1])); dyna.getValue().setText(tempIndex[2]); } else if ("2".equals(filterIndex)) { // 来源 dyna.getValue().setText(tempIndex[1]); } dyna.getValue().setForeground(black); } scroll.setMinSize(dynaComp.computeSize(SWT.DEFAULT, SWT.DEFAULT)); dynaComp.layout(); } else { MessageDialog.openInformation(getShell(), "", "请选择一个自定义过滤器。"); } } /** * 初始化已保存的条件列表 * @param comp 父容器 */ private void initCustomFilterList(Composite comp) { customFilterList = new List(comp, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); customFilterList.setLayoutData(new GridData(GridData.FILL_BOTH)); setListData(customFilterList, customFilters); customFilterList.addMouseListener(new MouseAdapter() { @Override public void mouseDoubleClick(MouseEvent e) { // 调编辑的方法 edit(); } }); } /** * 是否是UE版本 * @return ; */ private boolean isUEVersion() { // TODO 实现是否是UE版本的判断 return false; } /** * 是否安装TE * @return ; */ private boolean isTEInstalled() { // TODO 实现是否安装TE的判断 return true; } /** * (non-Javadoc) * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ @Override protected void okPressed() { // 保存自定义条件 String filterNameStr = filterNameTxt.getText(); if (filterNameStr == null || "".equals(filterNameStr)) { MessageDialog.openInformation(getShell(), "", "请输入过滤器名称!"); return; } if (btnIsRemoveFromSrc != null) { // 未安装TE时,该功能被屏蔽,按钮未被初始化。 if (btnIsRemoveFromSrc.getSelection()) { // TODO 将符合条件的匹配从可连接的记忆库中同时删除。该功能在与匹配来源的记忆库无法连接时禁用。 } } StringBuilder xpath = new StringBuilder(); String link = andBtn.getSelection() ? " and " : " or "; ArrayList<String[]> tempValue = new ArrayList<String[]>(); for (DynaComposite comp : conditionList) { // 得到所有自定义条件组合的xpath String tempXpath = comp.getXpath(true); if (RESULT_FAILED.equals(tempXpath)) { return; } xpath.append(link).append(tempXpath); tempValue.add(comp.getTempIndex()); } appendCheckCondition(xpath); if (xpath.length() > 0) { xpath.delete(0, xpath.indexOf(link) + link.length()); customFilters.put(filterNameStr, xpath.toString()); String[] additions = { link.trim(), "" + getCheck() }; customFiltersIndex.put(filterNameStr, tempValue); ArrayList<String[]> tempValue1 = new ArrayList<String[]>(); tempValue1.add(additions); customFiltersAddtion.put(filterNameStr, tempValue1); PreferenceStore.saveMap(IPreferenceConstants.MATCH_CONDITION, new TreeMap<String, String>(customFilters)); PreferenceStore.saveCustomCondition(IPreferenceConstants.MATCH_CONDITION_INDEX, customFiltersIndex); PreferenceStore.saveCustomCondition(IPreferenceConstants.MATCH_CONDITION_ADDITION, customFiltersAddtion); reload(); } } /** * 追加标记的匹配、快速翻译匹配、自动繁殖翻译匹配、从来源中删除四个按钮组合的xpath * @param xpath 需要追加的xpath */ private void appendCheckCondition(StringBuilder xpath) { if (btnIsTagged.getSelection()) { // 是否是带标记的匹配 if (xpath.length() > 0) { xpath.append(" and "); } xpath.append("(source/* or target/*)"); } if (btnQT.getSelection()) { // 是否是快速翻译匹配 if (xpath.length() > 0) { xpath.append(" and "); } xpath.append("@tool-id='").append(Constants.QT_TOOLID).append("'"); } if (btnPT.getSelection()) { // 是否是繁殖翻译匹配 if (xpath.length() > 0) { xpath.append(" and "); } xpath.append("contains(@origin, 'autoFuzzy_')"); } } /** * 重新加载自定义过滤器列表数据和刷新右侧过滤器设置组件 */ private void reload() { setListData(customFilterList, XLFHandler.getCustomMatchFilterMap()); refresh(); } /** * 刷新过滤器设置组件 */ private void refresh() { filterNameTxt.setText(""); andBtn.setSelection(true); orBtn.setSelection(false); btnIsTagged.setSelection(false); btnQT.setSelection(false); btnPT.setSelection(false); if (btnIsRemoveFromSrc != null) { btnIsRemoveFromSrc.setSelection(false); } for (Control ctl : conditionList) { if (!ctl.isDisposed()) { ctl.dispose(); } } conditionList.clear(); new DynaComposite(dynaComp, SWT.NONE); scroll.setMinSize(dynaComp.computeSize(SWT.DEFAULT, SWT.DEFAULT)); dynaComp.layout(); } /** * 查看当前状态是否为新增 * @return 当前状态是否为新增 */ private boolean isAdd() { return !XLFHandler.getCustomMatchFilterMap().containsKey(filterNameTxt.getText()); } @Override protected void cancelPressed() { close(); } @Override public boolean close() { if (isChange()) { if (MessageDialog.openConfirm(getShell(), "", "确定不保存就关闭吗?")) { return super.close(); } } else { return super.close(); } return false; } /** * 查看在新增和编辑状态下内容是否有变化 * @return 内容是否有变化 */ private boolean isChange() { boolean result = false; if (isAdd()) { if (!filterNameTxt.getText().trim().equals("")) { result = true; } if (andBtn.getSelection()) { if (conditionList.size() > 1) { result = true; } else { DynaComposite comp = conditionList.get(0); if (comp.getFilterName().getSelectionIndex() != 0) { result = true; } else { if (comp.getConditions().getSelectionIndex() != 0) { result = true; } else { if (!comp.getValue().getText().equals(initValue)) { result = true; } } } } } else { result = true; } } else { String orignXpath = XLFHandler.getCustomMatchFilterMap().get(filterNameTxt.getText()); StringBuilder xpath = new StringBuilder(); String link = andBtn.getSelection() ? " and " : " or "; for (DynaComposite comp : conditionList) { // 得到所有自定义条件组合的xpath String tempXpath = comp.getXpath(false); if (RESULT_FAILED.equals(tempXpath)) { result = true; } xpath.append(link).append(tempXpath); } appendCheckCondition(xpath); if (xpath.length() > 0) { xpath.delete(0, xpath.indexOf(link) + link.length()); result = !orignXpath.equals(xpath.toString()); } } return result; } /** * @param args ; */ public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new GridLayout(1, false)); final Combo combo = new Combo(shell, SWT.READ_ONLY); combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Button button = new Button(shell, SWT.PUSH); button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); button.setText("OK"); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { CustomMatchConditionDialog dialog = new CustomMatchConditionDialog(shell); int res = dialog.open(); if (res == CustomMatchConditionDialog.OK) { } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } private static String[] filterData = new String[] { "匹配率", "关键字", "来源" }; private static String[] conditionData1 = new String[] { "小于", "大于", "等于", "不等于" }; private static String[] conditionData2 = new String[] { "包含", "不包含", "开始于", "结束于", "等于", "不等于", "匹配正则" }; private static LinkedHashMap<String, String> mqOperators = new LinkedHashMap<String, String>(); { mqOperators.put("小于", "<"); mqOperators.put("大于", ">"); mqOperators.put("等于", "="); mqOperators.put("不等于", "!="); } /** * 动态条件组合 * @author Leakey * @version * @since JDK1.6 */ private class DynaComposite extends Composite { /** 过滤器列表控件. */ private Combo filterName; /** 判断条件列表控件. */ private Combo conditions; /** 一般文本框. */ private Text value; /** +按钮. */ private Button addBtn; /** -按钮. */ private Button reduceBtn; /** 当前选中的过滤器是否是(来源). */ private boolean isSource = false; /** 当前选中的过滤器是否是匹配率. */ private boolean isMatchQt = true; /** 当前选中的过滤器是否是关键字. */ private boolean isKeyword = false; private String[] tempIndex = null; /** * 取得xpath查询语句 * @return xpath查询语句 */ public String getXpath(boolean withNotice) { StringBuilder re = new StringBuilder(); String txt = value.getText().trim(); if (isSource) { // 来源 if (txt.equals("") || txt.equals(initValue)) { if (withNotice) { MessageDialog.openInformation(getShell(), "", "请输入来源!"); } return RESULT_FAILED; } re.append("@origin='").append(txt).append("'"); tempIndex = new String[] { filterName.getSelectionIndex() + "", txt }; } else if (isMatchQt) { // 匹配率 if (txt.equals("") || txt.equals(initValue)) { if (withNotice) { MessageDialog.openInformation(getShell(), "", "请输入匹配率!"); } return RESULT_FAILED; } String operator = conditions.getText().trim(); if (operator != null && !"".equals(operator)) { operator = mqOperators.get(operator); re.append("translate(@match-quality, '%', '')").append(operator).append(txt); } tempIndex = new String[] { filterName.getSelectionIndex() + "", conditions.getSelectionIndex() + "", txt }; } else if (isKeyword) { // 关键字 if (txt.equals("") || txt.equals(initValue)) { if (withNotice) { MessageDialog.openInformation(getShell(), "", "请输入关键字!"); } return RESULT_FAILED; } String operator = conditions.getText().trim(); if (operator != null && !"".equals(operator)) { if ("包含".equals(operator)) { re.append("(contains(source, '").append(txt).append("') or contains(target, '").append(txt) .append("'))"); } else if ("不包含".equals(operator)) { re.append("not(contains(source, '").append(txt).append("') or contains(target, '").append(txt) .append("'))"); } else if ("开始于".equals(operator)) { re.append("(starts-with(source, '").append(txt).append("') or starts-with(target, '") .append(txt).append("'))"); } else if ("结束于".equals(operator)) { re.append("(ends-with(source, '").append(txt).append("') or ends-with(target, '").append(txt) .append("'))"); } else if ("等于".equals(operator)) { re.append("(source='").append(txt).append("' or target='").append(txt).append("')"); } else if ("不等于".equals(operator)) { re.append("not(source='").append(txt).append("' or target='").append(txt).append("')"); } // else if ("匹配正则".equals(operator)) { // re.append("(matches(source, '").append(keyWord).append("') or matches(target, '").append(keyWord) // .append("'))"); // } tempIndex = new String[] { filterName.getSelectionIndex() + "", conditions.getSelectionIndex() + "", txt }; } } return re.toString(); } /** * 得到选择的索引或者文本框的值 */ public String[] getTempIndex() { return tempIndex; } /** * 当前选择是否为“来源” */ private boolean isSource() { if (filterName.getSelectionIndex() == 2) { isMatchQt = false; isKeyword = false; isSource = true; } else { isSource = false; } return isSource; } /** * 当前选择是否为“匹配率” */ private boolean isMatchQt() { if (filterName.getSelectionIndex() == 0) { isSource = false; isKeyword = false; isMatchQt = true; } else { isMatchQt = false; } return isMatchQt; } /** * 当前选择是否为“关键字” */ private boolean isKeyword() { if (filterName.getSelectionIndex() == 1) { isSource = false; isMatchQt = false; isKeyword = true; } else { isKeyword = false; } return isKeyword; } /** * 获取过滤器指定名称下拉框控件 */ public Combo getFilterName() { return filterName; } /** * 获取过滤器指定条件下拉框控件 */ public Combo getConditions() { return conditions; } /** * 获取文本框控件 */ public Text getValue() { return value; } /** * @param parent * @param style */ public DynaComposite(Composite parent, int style) { super(parent, style); init(); conditionList.add(this); } /** * 初始化 */ public void init() { this.setLayout(new GridLayout(5, false)); this.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); initFilterName(); initConditions(conditionData1); initTxt(1); initMatchQtTextListener(); initBtn(); } /** * 初始化“+”,“-”按钮 */ private void initBtn() { addBtn = new Button(this, SWT.BORDER); addBtn.setText("+"); addBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { new DynaComposite(dynaComp, SWT.NONE); scroll.setMinSize(dynaComp.computeSize(SWT.DEFAULT, SWT.DEFAULT)); dynaComp.layout(); } }); reduceBtn = new Button(this, SWT.BORDER); reduceBtn.setText("-"); reduceBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { conditionList.remove(DynaComposite.this); DynaComposite.this.dispose(); scroll.setMinSize(dynaComp.computeSize(SWT.DEFAULT, SWT.DEFAULT)); dynaComp.layout(); } }); if (conditionList.size() > 0) { if (conditionList.get(0).equals(this)) { reduceBtn.setEnabled(false); } else { reduceBtn.setEnabled(true); } } else { reduceBtn.setEnabled(false); } } /** * 初始化一般文本框 */ private void initTxt(int span) { value = new Text(this, SWT.BORDER); setGray(value, initValue); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = span; value.setLayoutData(data); } /** * 初始化条件下拉框 */ private void initConditions(String[] data) { conditions = new Combo(this, SWT.BORDER); conditions.setLayoutData(new GridData(100, 35)); if (data == null || data.length == 0) { return; } setComboData(conditions, data); conditions.select(0); } /** * 销毁除了“过滤器列表控件”之外的其它控件 */ private void disposeChild() { for (Control ctl : this.getChildren()) { if (!"filterName".equals(ctl.getData()) && ctl != null && !ctl.isDisposed()) { ctl.dispose(); } } } /** * 初始化匹配率文本框的监听,只允许输入数字,最大值为100或者101 */ private void initMatchQtTextListener() { value.addVerifyListener(new VerifyListener() { public void verifyText(VerifyEvent event) { if (!value.getText().equals(initValue)) { if (event.keyCode == 0 && event.stateMask == 0) { // 文本框得到焦点时 } else if (Character.isDigit(event.character) || event.character == '\b' || event.keyCode == 127) { // 输入数字,或者按下Backspace、Delete键 Text txt = (Text) event.widget; if ("0".equals(txt.getText().trim()) && event.character == '0') { event.doit = false; return; } event.doit = true; } else { event.doit = false; } } } }); value.addModifyListener(new ModifyListener() { final int max = isUEVersion() ? 101 : 100; // 最大值 public void modifyText(ModifyEvent e) { if (!value.getText().equals(initValue) && !value.getText().equals("")) { Text txt = (Text) e.widget; String text = txt.getText().trim(); if (text.length() == 2 && text.charAt(0) == '0') { txt.setText(text.charAt(1) + ""); txt.setSelection(1); } else if (Integer.parseInt(text) > max) { txt.setText("100"); txt.setSelection(3); } } } }); } /** * 初始化过滤器列表控件 */ private void initFilterName() { filterName = new Combo(this, SWT.BORDER); filterName.setLayoutData(new GridData(80, 35)); setComboData(filterName, filterData); filterName.setData("filterName"); filterName.select(0); filterName.addSelectionListener(new SelectionAdapter() { private void createSource() { disposeChild(); initTxt(2); initBtn(); } private void createKeyword() { disposeChild(); initConditions(conditionData2); initTxt(1); initBtn(); } private void createMatchQt() { disposeChild(); initConditions(conditionData1); initTxt(1); initMatchQtTextListener(); initBtn(); } @Override public void widgetSelected(SelectionEvent e) { if (isMatchQt()) { createMatchQt(); } if (isKeyword()) { createKeyword(); } if (isSource()) { createSource(); } DynaComposite.this.layout(); } }); } } /** * 为Text控件增加灰色提醒,获得焦点时自动清除灰色提醒 * @param text * Text控件 * @param initTxt * 灰色提醒字符串 */ private void setGray(final Text text, final String initTxt) { text.setForeground(gray); text.setText(initTxt); text.addFocusListener(new FocusListener() { public void focusLost(FocusEvent arg0) { if (text.getText().trim().equals("")) { if (!text.getForeground().equals(gray)) { text.setForeground(gray); } text.setText(initTxt); } else { if (!text.getForeground().equals(black)) { text.setForeground(black); } } } public void focusGained(FocusEvent arg0) { if (text.getText().trim().equals(initTxt)) { text.setText(""); text.setForeground(black); } else { if (!text.getForeground().equals(black)) { text.setForeground(black); } } } }); } /** * 设置Combo下拉列表中的数据 */ private void setComboData(Combo combo, String[] data) { if (combo == null || data == null || data.length == 0) { return; } combo.clearSelection(); combo.removeAll(); int i = 0; for (String temp : data) { combo.add(temp, i++); } } /** * 为List组件设置数据 * @param list * @param data */ private void setListData(List list, Map<String, String> data) { list.removeAll(); if (data == null) { return; } for (Entry<String, String> entry : data.entrySet()) { list.add(entry.getKey()); } } }
30,427
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UpdateNoteDialog.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/dialog/UpdateNoteDialog.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog; import java.util.HashMap; import java.util.Vector; import net.heartsome.cat.common.util.TextUtil; import net.heartsome.cat.ts.core.bean.NoteBean; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.NatTableConstant; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; /** * 编辑批注对话框 * @author peason * @version * @since JDK1.6 */ public class UpdateNoteDialog extends Dialog { private XLIFFEditorImplWithNatTable xliffEditor; private TableViewer tableViewer; // private String rowId; private int rowIndex; private Button btnAdd; private Button btnEdit; private Button btnDelete; public UpdateNoteDialog(Shell parentShell, XLIFFEditorImplWithNatTable xliffEditor, int rowIndex) { super(parentShell); // this.rowId = rowId; this.rowIndex = rowIndex; this.xliffEditor = xliffEditor; } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(Messages.getString("dialog.UpdateNoteDialog.title")); } @Override protected Control createDialogArea(Composite parent) { Composite tparent = (Composite) super.createDialogArea(parent); GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).extendedMargins(5, 5, 5, 5).applyTo(tparent); GridDataFactory.fillDefaults().hint(620, 250).grab(true, true).applyTo(tparent); Group noteGroup = new Group(tparent, SWT.None); noteGroup.setText(Messages.getString("dialog.UpdateNoteDialog.noteGroup")); GridDataFactory.fillDefaults().grab(true, true).applyTo(noteGroup); noteGroup.setLayout(new GridLayout()); tableViewer = new TableViewer(noteGroup, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); Table table = tableViewer.getTable(); table.setLayoutData(new GridData(GridData.FILL_BOTH)); table.setHeaderVisible(true); table.setLinesVisible(true); String[] arrColName = new String[] { Messages.getString("dialog.UpdateNoteDialog.tableColumn1"), Messages.getString("dialog.UpdateNoteDialog.tableColumn2"), Messages.getString("dialog.UpdateNoteDialog.tableColumn3"), Messages.getString("dialog.UpdateNoteDialog.tableColumn4"), Messages.getString("dialog.UpdateNoteDialog.tableColumn5") }; int[] arrColWidth = new int[] { 40, 100, 100, 150, 120 }; for (int i = 0; i < arrColName.length; i++) { TableColumn column = new TableColumn(table, SWT.LEFT); column.setWidth(arrColWidth[i]); column.setText(arrColName[i]); } tableViewer.setLabelProvider(new TableViewerLabelProvider()); tableViewer.setContentProvider(new ArrayContentProvider()); Composite cmpBtn = new Composite(tparent, SWT.None); // cmpBtn.setLayout(new GridLayout()); GridLayoutFactory.fillDefaults().numColumns(1).extendedMargins(0, 0, 35, 5).applyTo(cmpBtn); cmpBtn.setLayoutData(new GridData(GridData.FILL_VERTICAL)); btnAdd = new Button(cmpBtn, SWT.NONE); btnAdd.setText(Messages.getString("dialog.UpdateNoteDialog.btnAdd")); btnAdd.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); btnEdit = new Button(cmpBtn, SWT.NONE); btnEdit.setText(Messages.getString("dialog.UpdateNoteDialog.btnEdit")); btnEdit.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); btnDelete = new Button(cmpBtn, SWT.NONE); btnDelete.setText(Messages.getString("dialog.UpdateNoteDialog.btnDelete")); btnDelete.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); initTable(); initListener(); return tparent; } private void initTable() { Vector<NoteBean> noteBeans = xliffEditor.getRowTransUnitBean(rowIndex).getNotes(); if (noteBeans != null && noteBeans.size() > 0) { String[][] arrTableItem = new String[noteBeans.size()][]; for (int i = 0; i < noteBeans.size(); i++) { NoteBean bean = noteBeans.get(i); String strNote = bean.getNoteText(); String date = ""; String strText = ""; if (strNote != null) { // Bug #2334:添加批注包含特殊字符保存失败 strNote = TextUtil.resetSpecialString(strNote); if (strNote.indexOf(":") != -1) { date = strNote.substring(0, strNote.indexOf(":")); if (validData(date)) { strText = strNote.substring(strNote.indexOf(":") + 1); }else { date = ""; strText = strNote; } } else { strText = strNote; } } String strCurrent = bean.getApplyCurrent(); if (strCurrent == null || strCurrent.equals("Yes")) { strCurrent = NatTableConstant.CURRENT_TEXT; } else { strCurrent = NatTableConstant.ALL_TEXT; } arrTableItem[i] = new String[] { String.valueOf(i + 1), bean.getFrom(), date, strText, strCurrent }; } tableViewer.setInput(arrTableItem); } else { tableViewer.setInput(null); } } private void initListener() { btnAdd.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { AddOrUpdateNoteDialog dialog = new AddOrUpdateNoteDialog(getShell(), xliffEditor, AddOrUpdateNoteDialog.DIALOG_ADD, null); if (dialog.open() == Window.OK) { initTable(); } } public void widgetDefaultSelected(SelectionEvent e) { } }); btnEdit.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { if (tableViewer.getTable().getSelectionCount() != 1) { MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateNoteDialog.msgTitle1"), Messages.getString("dialog.UpdateNoteDialog.msg2")); return; } TableItem item = tableViewer.getTable().getSelection()[0]; String[] arrNoteItem = new String[] { item.getText(0), item.getText(1), item.getText(2), item.getText(3), item.getText(4) }; AddOrUpdateNoteDialog dialog = new AddOrUpdateNoteDialog(getShell(), xliffEditor, AddOrUpdateNoteDialog.DIALOG_EDIT, arrNoteItem); if (dialog.open() == Window.OK) { initTable(); } } public void widgetDefaultSelected(SelectionEvent e) { } }); btnDelete.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { TableItem[] items = tableViewer.getTable().getSelection(); if (items.length == 0) { MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateNoteDialog.msgTitle1"), Messages.getString("dialog.UpdateNoteDialog.msg3")); return; } if (MessageDialog.openConfirm(getShell(), Messages.getString("dialog.UpdateNoteDialog.msgTitle2"), Messages.getString("dialog.UpdateNoteDialog.msg4"))) { Vector<NoteBean> lstBeans = new Vector<NoteBean>(); for (TableItem item : items) { String date = item.getText(2); String noteText = ""; if (date != null && !date.equals("")) { noteText += date + ":"; } NoteBean bean = new NoteBean(noteText + item.getText(3)); bean.setFrom(item.getText(1)); String strApplyCurrent = item.getText(4); strApplyCurrent = strApplyCurrent.equals(NatTableConstant.CURRENT_TEXT) ? "Yes" : "No"; bean.setApplyCurrent(strApplyCurrent); lstBeans.add(bean); } HashMap<String, Vector<NoteBean>> mapNote = new HashMap<String, Vector<NoteBean>>(); mapNote.put(xliffEditor.getXLFHandler().getRowId(rowIndex), lstBeans); xliffEditor.getXLFHandler().deleteNote(mapNote); initTable(); } } public void widgetDefaultSelected(SelectionEvent e) { } }); } // @Override // protected Control createButtonBar(Composite parent) { // Control btnBar = super.createButtonBar(parent); // getButton(IDialogConstants.OK_ID).dispose(); // getButton(IDialogConstants.CANCEL_ID).dispose(); // parent.layout(); // return btnBar; // } @Override protected void createButtonsForButtonBar(Composite parent) { Composite cmp = parent.getParent(); parent.dispose(); cmp.layout(); } /** * 验证批注里面的时间是否合法。如果不合法返回false。--robert 2012-06-29 * @param date * @return */ private boolean validData(String date){ String regex = "\\d{4}-\\d{1,2}-\\d{1,2}"; return date.matches(regex); } class TableViewerLabelProvider extends LabelProvider implements ITableLabelProvider { public Image getColumnImage(Object element, int columnIndex) { // TODO Auto-generated method stub return null; } public String getColumnText(Object element, int columnIndex) { if (element instanceof String[]) { String[] array = (String[]) element; return array[columnIndex]; } return null; } } }
9,658
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
NattableUtil.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/utils/NattableUtil.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.utils; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import net.heartsome.cat.common.core.exception.ImportException; import net.heartsome.cat.common.util.CommonFunction; import net.heartsome.cat.ts.core.file.ProjectConfigerFactory; import net.heartsome.cat.ts.core.file.RowIdUtil; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.tb.importer.TbImporter; import net.heartsome.cat.ts.tm.importer.TmImporter; import net.heartsome.cat.ts.tm.importer.extension.ITmImporter; import net.heartsome.cat.ts.ui.Activator; import net.heartsome.cat.ts.ui.preferencepage.IPreferenceConstants; import net.heartsome.cat.ts.ui.util.IntelligentTagPrcessor; import net.heartsome.cat.ts.ui.view.IMatchViewPart; import net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean; import net.heartsome.cat.ts.ui.xliffeditor.nattable.config.VerticalNatTableConfig; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiCellEditorControl; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.propertyTester.AddSegmentToTMPropertyTester; import net.heartsome.cat.ts.ui.xliffeditor.nattable.propertyTester.SignOffPropertyTester; import net.heartsome.cat.ts.ui.xliffeditor.nattable.propertyTester.UnTranslatedPropertyTester; import net.heartsome.cat.ts.ui.xliffeditor.nattable.qa.AutomaticQATrigger; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.MergeSegmentOperation; import net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.NeedsReviewOperation; import net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.SendTOTmOperation; import net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.StateOperation; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.operations.IOperationHistory; import org.eclipse.core.commands.operations.OperationHistoryFactory; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.custom.BusyIndicator; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.services.IEvaluationService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * 用于对 Nattable 中的文本段进行处理的工具类 * @author peason * @version * @since JDK1.6 */ public class NattableUtil { public static final Logger LOGGER = LoggerFactory.getLogger(NattableUtil.class); private static NattableUtil instance; private XLIFFEditorImplWithNatTable xliffEditor; private TmImporter importer; // /** 首选项存取器 */ // private IPreferenceStore store = net.heartsome.cat.ts.ui.Activator // .getDefault().getPreferenceStore(); public static synchronized NattableUtil getInstance(XLIFFEditorImplWithNatTable xliffEditor) { if (instance == null) { instance = new NattableUtil(xliffEditor); } else { if (xliffEditor != instance.xliffEditor) { instance.importer.clearResources(); } instance.xliffEditor = xliffEditor; } return instance; } private NattableUtil(XLIFFEditorImplWithNatTable xliffEditor) { this.xliffEditor = xliffEditor; this.importer = TmImporter.getInstance(); } /** * 批准或取消批准文本段 * @param selectedRowIds1 * 选中行的rowId集合 * @param approve * true:批准;false:取消批准; */ public void approveTransUnits(boolean isJumpNext) { List<String> selectedRowIds = xliffEditor.getSelectedRowIds(); if (selectedRowIds.size() == 0) { return; } final Map<String, List<String>> tmpGroup = RowIdUtil.groupRowIdByFileName(selectedRowIds); boolean hasEmpty = false; XLFHandler handler = xliffEditor.getXLFHandler(); for (Entry<String, List<String>> entry : tmpGroup.entrySet()) { // 目标文本为空不能执行批准,将要跳过 List<String> rowIds = entry.getValue(); int size = rowIds.size(); handler.removeNullTgtContentRowId(rowIds); if (rowIds.size() != size) { hasEmpty = true; } handler.removeLockedRowIds(rowIds); } // 入库前进行品质检查 --robert int i = 0; final AutomaticQATrigger auto = new AutomaticQATrigger(xliffEditor.getXLFHandler()); for (Entry<String, List<String>> entry : tmpGroup.entrySet()) { List<String> rowIdList = tmpGroup.get(entry.getKey()); for (Iterator<String> it = rowIdList.iterator(); it.hasNext();) { String rowId = it.next(); String result = auto.beginAutoQa(false, rowId, i == 0 ? true : false); if (result == null) { return; } if (result.length() > 1) { boolean respons = MessageDialog.openConfirm(xliffEditor.getSite().getShell(), Messages.getString("translation.ApproveSegmentHandler.msgTitle"), result); // 若选择ok,则继续操作 if (!respons) { auto.bringQAResultViewerToTop(); it.remove(); selectedRowIds.remove(rowId); } } i++; } } auto.informQAEndFlag(); String message = null; if (hasEmpty) { message = Messages.getString("utils.NattableUtil.msg1"); } if (message != null) { if (!MessageDialog.openConfirm(xliffEditor.getTable().getShell(), Messages.getString("utils.NattableUtil.msgTitle"), message)) { return; } } if (selectedRowIds.size() == 0) { return; } HsMultiActiveCellEditor.commit(true); // 将选中的文本段添加记忆库,在生成TMX的过程中会过滤掉标记不添加到记忆库的文本段 final IProject project = ((FileEditorInput) (xliffEditor.getEditorInput())).getFile().getProject(); this.importer.setProject(project); final int contextSize = importer.getContextSize(); BusyIndicator.showWhile(xliffEditor.getSite().getShell().getDisplay(), new Runnable() { public void run() { // monitor.beginTask(Messages.getString("utils.NattableUtil.task1"), 8); if (!CommonFunction.checkEdition("L")) { if (!importer.checkImporter() && ProjectConfigerFactory.getProjectConfiger(project).getDefaultTMDb() != null) { final boolean[] state = new boolean[] { true }; Display.getDefault().syncExec(new Runnable() { public void run() { state[0] = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle2"), Messages.getString("utils.NattableUtil.msg.cantConnDefaultDb")); } }); if (!state[0]) { return; } } } final List<String> addToTmResultRowIds = new ArrayList<String>(); for (Entry<String, List<String>> entry : tmpGroup.entrySet()) { List<String> rowIdList = tmpGroup.get(entry.getKey()); if (importer.checkImporter()) { String systemUser = Activator.getDefault().getPreferenceStore() .getString(IPreferenceConstants.SYSTEM_USER); StringBuffer fileContent = xliffEditor.getXLFHandler().generateTMXFileContent(systemUser, rowIdList, xliffEditor.getSrcColumnName(), xliffEditor.getTgtColumnName(), /* new SubProgressMonitor(monitor, 3) */null, contextSize, project); // if (monitor.isCanceled()) { // return; // } if (fileContent != null) { int state = -1; try { state = importer.executeImport(fileContent.toString(), xliffEditor.getSrcColumnName(), /* monitor */null); } catch (ImportException e) { final String msg = e.getMessage(); Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle"), msg); } }); return; } if (state == ITmImporter.IMPORT_STATE_FAILED) { Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle"), Messages.getString("utils.NattableUtil.msg2")); } }); return; } else if (state == ITmImporter.IMPORT_STATE_NODB) { Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle"), Messages.getString("utils.NattableUtil.msg3")); } }); } } } addToTmResultRowIds.addAll(rowIdList); } // monitor.setTaskName(Messages.getString("utils.NattableUtil.task2")); Display.getDefault().syncExec(new Runnable() { public void run() { // 修改文本段状态,目前没有取消批准的功能,所以直接传入true,即所有的操作都是批准 List<String> rowIds = xliffEditor.getXLFHandler().approveTransUnits(addToTmResultRowIds, true); if (rowIds.size() > 0) { String message; if (addToTmResultRowIds != null && addToTmResultRowIds.size() == 1) { message = Messages.getString("utils.NattableUtil.msg4"); } else { message = MessageFormat.format(Messages.getString("utils.NattableUtil.msg5"), rowIds.size()); } boolean res = MessageDialog.openQuestion(xliffEditor.getTable().getShell(), null, message); if (res) { xliffEditor.getXLFHandler().approveTransUnits(rowIds, true, false); } } xliffEditor.updateStatusLine(); xliffEditor.getTable().redraw(); } }); // monitor.worked(2); // if (monitor.isCanceled()) { // return; // } // // // 批准时需要进行繁殖翻译 // // propagateTranslations(addToTmResultRowIds, new // // SubProgressMonitor(monitor, 2)); // monitor.done(); } }); // try { // new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, // runnable); if (isJumpNext) { int[] selectedRows = xliffEditor.getSelectedRows(); Arrays.sort(selectedRows); xliffEditor.jumpToRow(selectedRows[selectedRows.length - 1] + 1); } else { IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .findView("net.heartsome.cat.ts.ui.translation.view.matchview"); int[] selected = xliffEditor.getSelectedRows(); if (viewPart != null && viewPart instanceof IMatchViewPart && selected.length != 0) { ((IMatchViewPart) viewPart).reLoadMatches(xliffEditor, selected[selected.length - 1]); } HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor); } // } catch (InvocationTargetException e) { // e.printStackTrace(); // } catch (InterruptedException e) { // e.printStackTrace(); // } } /** * 锁定或取消锁定文本段 * @param selectedRowIds * 选中行的rowId集合 * @param lock * true:锁定;false:取消锁定; */ public void lockTransUnits(List<String> selectedRowIds, boolean lock) { xliffEditor.getXLFHandler().lockTransUnits(selectedRowIds, lock); xliffEditor.getTable().redraw(); // IOperationHistory operationHistory = // OperationHistoryFactory.getOperationHistory(); // try { // operationHistory // .execute( // new LockOperation("Lock", xliffEditor.getTable(), selectedRowIds, // xliffEditor // .getXLFHandler(), lock), null, null); // } catch (ExecutionException e) { // e.printStackTrace(); // } } /** * 改变Target的状态,signed-off需要修改approved=yes,改为new或translated需要删除approved=yes属性 * @param state * 状态值("new", "final", "translated", "signed-off", "needs-adaptation", "needs-review-adaptation", * "needs-l10n", "needs-review-l10n", "needs-translation", "needs-review-translation"); */ public void changeTgtState(List<String> selectedRowIds, String state) { if (selectedRowIds != null && selectedRowIds.size() > 0) { xliffEditor.getXLFHandler().changeTransUnitState(selectedRowIds, state); xliffEditor.updateStatusLine(); xliffEditor.getTable().redraw(); NattableUtil.refreshCommand(AddSegmentToTMPropertyTester.PROPERTY_NAMESPACE, AddSegmentToTMPropertyTester.PROPERTY_ENABLED); NattableUtil.refreshCommand(SignOffPropertyTester.PROPERTY_NAMESPACE, SignOffPropertyTester.PROPERTY_ENABLED); NattableUtil.refreshCommand(UnTranslatedPropertyTester.PROPERTY_NAMESPACE, UnTranslatedPropertyTester.PROPERTY_ENABLED); } } /** * 添加或者取消疑问 * @param selectedRowIds * @param state * ; */ public void changIsQuestionState(List<String> selectedRowIds, String state) { IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory(); try { operationHistory.execute(new NeedsReviewOperation("need-review", xliffEditor.getTable(), selectedRowIds, xliffEditor.getXLFHandler(), state), null, null); } catch (ExecutionException e) { LOGGER.error("", e); MessageDialog.openError(xliffEditor.getSite().getShell(), Messages.getString("utils.NattableUtil.msgTitle2"), e.getMessage()); e.printStackTrace(); } } /** * 设置是否添加到记忆库 * @param selectedRowIds * @param state * "yes" or "no"; */ public void changeSendToTmState(List<String> selectedRowIds, String state) { IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory(); try { operationHistory.execute(new SendTOTmOperation("send-to-tm", xliffEditor.getTable(), selectedRowIds, xliffEditor.getXLFHandler(), state), null, null); } catch (ExecutionException e) { LOGGER.error("", e); MessageDialog.openError(xliffEditor.getSite().getShell(), Messages.getString("utils.NattableUtil.msgTitle2"), e.getMessage()); e.printStackTrace(); } } /** * 改变Target的状态 * @param state * 状态值("new", "final", "translated", "signed-off", "needs-adaptation", "needs-review-adaptation", * "needs-l10n", "needs-review-l10n", "needs-translation", "needs-review-translation"); */ public void changeTgtState(final List<String> selectedRowIds, final String state, IProgressMonitor monitor) { if (monitor == null) { monitor = new NullProgressMonitor(); } monitor.beginTask(Messages.getString("utils.NattableUtil.task4"), 1); monitor.worked(1); final IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory(); final IProgressMonitor monitor2 = monitor; Display.getDefault().syncExec(new Runnable() { public void run() { try { operationHistory.execute(new StateOperation("State", xliffEditor.getTable(), selectedRowIds, xliffEditor.getXLFHandler(), state), monitor2, null); } catch (ExecutionException e) { LOGGER.error("", e); MessageDialog.openError(xliffEditor.getSite().getShell(), Messages.getString("utils.NattableUtil.msgTitle2"), e.getMessage()); e.printStackTrace(); } } }); monitor.done(); } /** * 添加选中文本段到记忆库 * @param modelBean * 数据库元数据 * @return boolean true : 完成入库 false 不完成入库 */ public boolean addSelectSegmentToTM() { List<String> selectedRowIds = xliffEditor.getSelectedRowIds(); if (selectedRowIds.size() == 0) { return false; } final Map<String, List<String>> tmpGroup = RowIdUtil.groupRowIdByFileName(selectedRowIds); boolean hasEmpty = false; XLFHandler handler = xliffEditor.getXLFHandler(); for (Entry<String, List<String>> entry : tmpGroup.entrySet()) { // 目标文本为空不添加到记忆库 List<String> rowIds = entry.getValue(); int size = rowIds.size(); handler.removeNullTgtContentRowId(rowIds); if (rowIds.size() != size) { hasEmpty = true; } handler.removeLockedRowIds(rowIds); } // 入库前进行品质检查 --robert final AutomaticQATrigger auto = new AutomaticQATrigger(xliffEditor.getXLFHandler()); int i = 0; for (Entry<String, List<String>> entry : tmpGroup.entrySet()) { List<String> rowIdList = tmpGroup.get(entry.getKey()); for (Iterator<String> it = rowIdList.iterator(); it.hasNext();) { String rowId = it.next(); String result = auto.beginAutoQa(true, rowId, i == 0 ? true : false); if (result == null) { return false; } if (result.length() > 1) { boolean respons = MessageDialog.openConfirm(xliffEditor.getTable().getShell(), Messages.getString("utils.NattableUtil.msgTitle3"), result); // 若选择ok,则继续操作 if (!respons) { auto.bringQAResultViewerToTop(); it.remove(); selectedRowIds.remove(rowId); } } i++; } } auto.informQAEndFlag(); if (selectedRowIds.size() <= 0) { return false; } String message = null; if (hasEmpty) { message = Messages.getString("utils.NattableUtil.msg1"); } if (message != null) { if (!MessageDialog.openConfirm(xliffEditor.getTable().getShell(), Messages.getString("utils.NattableUtil.msgTitle"), message)) { return false; } } final ArrayList<String> lstRowId = new ArrayList<String>(); final IProject project = ((FileEditorInput) (xliffEditor.getEditorInput())).getFile().getProject(); this.importer.setProject(project); final int contextSize = importer.getContextSize(); // IRunnableWithProgress runnable = new IRunnableWithProgress() { // public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { BusyIndicator.showWhile(xliffEditor.getSite().getShell().getDisplay(), new Runnable() { public void run() { // monitor.setTaskName(Messages.getString("utils.NattableUtil.task5")); // monitor.beginTask(Messages.getString("utils.NattableUtil.task5"), 2); if (!CommonFunction.checkEdition("L")) { if (!importer.checkImporter() && ProjectConfigerFactory.getProjectConfiger(project).getDefaultTMDb() != null) { final boolean[] state = new boolean[] { true }; Display.getDefault().syncExec(new Runnable() { public void run() { state[0] = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle2"), Messages.getString("utils.NattableUtil.msg.cantConnDefaultDb")); } }); if (!state[0]) { return; } } } for (Entry<String, List<String>> entry : tmpGroup.entrySet()) { List<String> rowIdList = tmpGroup.get(entry.getKey()); if (importer.checkImporter()) { String systemUser = Activator.getDefault().getPreferenceStore() .getString(IPreferenceConstants.SYSTEM_USER); StringBuffer fileContent = xliffEditor.getXLFHandler().generateTMXFileContent(systemUser, rowIdList, xliffEditor.getSrcColumnName(), xliffEditor.getTgtColumnName(), /* new SubProgressMonitor(monitor, 1) */null, contextSize, project); // if (monitor.isCanceled()) { // monitor.setTaskName(Messages.getString("utils.NattableUtil.task6")); // throw new OperationCanceledException(); // } if (fileContent != null) { int state = -1; try { state = importer.executeImport(fileContent.toString(), xliffEditor.getSrcColumnName(), /* monitor */null); } catch (ImportException e) { final String msg = e.getMessage(); Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle"), msg); } }); return; } if (state == ITmImporter.IMPORT_STATE_FAILED) { Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog.openInformation(xliffEditor.getTable().getShell(), Messages.getString("utils.NattableUtil.msgTitle"), Messages.getString("utils.NattableUtil.msg6")); } }); return; } else if (state == ITmImporter.IMPORT_STATE_NODB) { Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog.openInformation(xliffEditor.getTable().getShell(), Messages.getString("utils.NattableUtil.msgTitle"), Messages.getString("utils.NattableUtil.msg7")); } }); } } } // Bug #2306:文本段添加不入库标记后不能改变为完成翻译状态 lstRowId.addAll(rowIdList); } Display.getDefault().asyncExec(new Runnable() { public void run() { changeTgtState(lstRowId, "translated"); // xliffEditor.updateStatusLine(); } }); // monitor.done(); } }); // try { // new ProgressMonitorDialog(xliffEditor.getTable().getShell()).run(true, true, runnable); // } catch (InvocationTargetException e) { // e.printStackTrace(); // } catch (InterruptedException e) { // e.printStackTrace(); // } return true; } // /** // * 获得记忆库更新策略 // * @return ; // */ // public int getTmxImportStrategy() { // IPreferenceStore ps = Activator.getDefault().getPreferenceStore(); // return ps.getInt(PreferenceConstants.TM_UPDATE); // } /** * 繁殖翻译 robert * @param rowIdsMap * @param monitor * @return */ public IStatus propagateTranslations(Map<String, List<String>> rowIdsMap, IProgressMonitor monitor) { if (monitor == null) { monitor = new NullProgressMonitor(); } IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK); subMonitor.beginTask(Messages.getString("utils.NattableUtil.task7"), rowIdsMap.keySet().size()); Iterator<Entry<String, List<String>>> it = rowIdsMap.entrySet().iterator(); final XLFHandler handler = xliffEditor.getXLFHandler(); while (it.hasNext()) { Entry<String, List<String>> entry = it.next(); // 这是源文本,也就是繁殖翻译中的父 String rootRowId = entry.getKey(); // 这是要被繁殖的所有rowIds,其源文与rootRowId的源文一致 final List<String> rowIds = entry.getValue(); // TransUnitBean tu = handler.getTransUnit(rootRowId); // String tgtContent = tu.getTgtContent(); final String rootTgtPureText = handler.getTUPureTextByRowId(rootRowId, false); String rootSrcFullText = handler.getTUFullTextByRowId(rootRowId, true); String rootTgtFullText = handler.getTUFullTextByRowId(rootRowId, false); for (String rowId : rowIds) { String temp = rootTgtPureText; String srcFullText = handler.getTUFullTextByRowId(rowId, true); if (srcFullText.trim().equals(rootSrcFullText.trim())) { temp = rootTgtFullText; } else { temp = IntelligentTagPrcessor.intelligentAppendTag(srcFullText, rootTgtFullText); } handler.changeTgtTextValue(rowId, temp, null, null); } // 下面这是处理处于获得焦点状态的文本段。无法繁殖翻译的情况 Display.getDefault().syncExec(new Runnable() { public void run() { int focusRowIndex = HsMultiActiveCellEditor.sourceRowIndex; if (focusRowIndex == -1) { return; } if (!XLIFFEditorImplWithNatTable.getCurrent().isHorizontalLayout()) { focusRowIndex = VerticalNatTableConfig.getRealRowIndex(focusRowIndex); } String focusRowId = handler.getRowId(focusRowIndex); if (rowIds.contains(focusRowId)) { HsMultiActiveCellEditor.getTargetStyledEditor().setCanonicalValue( new UpdateDataBean(rootTgtPureText, null, null)); } } }); if (subMonitor.isCanceled()) { return Status.OK_STATUS; } subMonitor.worked(1); } subMonitor.done(); return Status.OK_STATUS; } /** * 刷新 Command 的可用状态 * @param nameSpace * @param properties * ; */ public static void refreshCommand(String nameSpace, String properties) { if (nameSpace != null && properties != null) { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IEvaluationService evaluationService = (IEvaluationService) window.getService(IEvaluationService.class); if (evaluationService != null) { evaluationService.requestEvaluation(nameSpace + "." + properties); } } } /** * 合并文本段 ; */ public void mergeSegment() { XLFHandler handler = xliffEditor.getXLFHandler(); List<String> lstRowId = xliffEditor.getSelectedRowIds(); List<String> lstAllRowId = xliffEditor.getXLFHandler().getAllRowIds(); Shell shell = xliffEditor.getSite().getShell(); if (lstRowId.size() < 2) { MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg1")); return; } Collections.sort(lstRowId, new SortRowIdComparator()); Collections.sort(lstAllRowId, new SortRowIdComparator()); String rowId1 = lstRowId.get(0); String fileName = RowIdUtil.getFileNameByRowId(rowId1); if (fileName == null) { return; } if (handler.isLocked(rowId1)) { MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg3")); return; } for (int i = 1; i < lstRowId.size(); i++) { String rowId = lstRowId.get(i); if (handler.isLocked(rowId)) { MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg3")); return; } String fileName2 = RowIdUtil.getFileNameByRowId(rowId); // 数组集合必须在一个文件中才能合并 if (fileName2 == null || !fileName.equals(fileName2)) { MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg4")); return; } // 判断所选文本段是否连续 String strCurTuId = RowIdUtil.getTUIdByRowId(rowId); String strPreTuId = RowIdUtil.getTUIdByRowId(lstRowId.get(i - 1)); if (strCurTuId == null || strPreTuId == null) { return; } if ((lstAllRowId.indexOf(rowId) - lstAllRowId.indexOf(lstRowId.get(i - 1))) != 1) { MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg5")); return; } else { String curOriginal = RowIdUtil.getOriginalByRowId(rowId); String preOriginal = RowIdUtil.getOriginalByRowId(lstRowId.get(i - 1)); if (!curOriginal.equals(preOriginal)) { MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg5")); return; } } } // Bug #2373:选择全部文本段合并后,无显示内容 if (lstRowId.size() == xliffEditor.getXLFHandler().getRowIds().size()) { xliffEditor.jumpToRow(0); } MergeSegmentOperation mergeOper = new MergeSegmentOperation("merge segment", xliffEditor, handler, lstRowId); IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory(); try { operationHistory.execute(mergeOper, null, null); } catch (Exception e) { LOGGER.error("", e); } } /** * 对 RowId 进行排序的类 * @author peason * @version * @since JDK1.6 */ private class SortRowIdComparator implements Comparator<String> { public int compare(String arg0, String arg1) { String pre0 = arg0.substring(0, arg0.lastIndexOf(RowIdUtil.SPLIT_MARK)); String pre1 = arg1.substring(0, arg1.lastIndexOf(RowIdUtil.SPLIT_MARK)); if (pre0.equals(pre1)) { String tuId0 = RowIdUtil.getTUIdByRowId(arg0); String tuId1 = RowIdUtil.getTUIdByRowId(arg1); if (tuId0 != null && tuId1 != null) { String[] arr0 = tuId0.split("-"); String[] arr1 = tuId1.split("-"); for (int i = 0; i < Math.min(arr0.length, arr1.length); i++) { int value0 = Integer.parseInt(arr0[i]); int value1 = Integer.parseInt(arr1[i]); if (value0 == value1) { continue; } else if (value0 > value1) { return 1; } else { return -1; } } return 0; } else if (tuId0 == null && tuId1 == null) { return 0; } else if (tuId0 != null) { return 1; } else { return -1; } } else { return pre0.compareTo(pre1); } } } /** * 对选中文本段执行签发操作 ; */ public void changeToSignedOffState() { List<String> selectedRowIds = getRowIdsNoEmptyTranslate(true); for (int i = 0; i < selectedRowIds.size(); i++) { String rowId = selectedRowIds.get(i); String tgtContent = xliffEditor.getXLFHandler().getTgtContent(rowId); boolean isDraft = xliffEditor.getXLFHandler().isDraft(rowId); if (tgtContent == null || tgtContent.trim().equals("") || isDraft) { selectedRowIds.remove(i); i--; } } if (selectedRowIds.size() > 0) { changeTgtState(selectedRowIds, "signed-off"); } } /** * 对选中的文本段进行过滤 * @param isSignedOff * @return ; */ public List<String> getRowIdsNoEmptyTranslate(boolean isSignedOff) { List<String> selRowIds = xliffEditor.getSelectedRowIds(); int oldSize = selRowIds.size(); XLFHandler handler = xliffEditor.getXLFHandler(); handler.removeNullTgtContentRowId(selRowIds); boolean hasEmpty = false; boolean hasDraft = false; if (oldSize != selRowIds.size()) { hasEmpty = true; } if (isSignedOff) { // 判断执行签发时是否有草稿状态的文本段 for (int i = 0; i < selRowIds.size(); i++) { String rowId = selRowIds.get(i); if (handler.isDraft(rowId)) { selRowIds.remove(i); i--; hasDraft = true; } } } String message = null; if (hasEmpty && hasDraft) { message = Messages.getString("utils.NattableUtil.msg8"); } else if (hasDraft) { message = Messages.getString("utils.NattableUtil.msg9"); } else if (hasEmpty) { message = Messages.getString("utils.NattableUtil.msg1"); } if (message != null) { if (!MessageDialog.openConfirm(xliffEditor.getTable().getShell(), Messages.getString("utils.NattableUtil.msgTitle"), message)) { selRowIds.clear(); } } return selRowIds; } public void releaseResource() { importer.setProject(null); TbImporter.getInstance().setProject(null); } }
31,212
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AutoResizeCurrentRowsCommandHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/AutoResizeCurrentRowsCommandHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.sourceforge.nattable.command.ILayerCommandHandler; import net.sourceforge.nattable.config.CellConfigAttributes; import net.sourceforge.nattable.config.IConfigRegistry; import net.sourceforge.nattable.config.IConfiguration; import net.sourceforge.nattable.layer.CompositeLayer; import net.sourceforge.nattable.layer.ILayer; import net.sourceforge.nattable.layer.cell.LayerCell; import net.sourceforge.nattable.painter.cell.ICellPainter; import net.sourceforge.nattable.print.command.TurnViewportOffCommand; import net.sourceforge.nattable.print.command.TurnViewportOnCommand; import net.sourceforge.nattable.resize.MaxCellBoundsHelper; import net.sourceforge.nattable.resize.command.MultiRowResizeCommand; import org.eclipse.swt.graphics.GC; /** * 自适应当前显示行的高度的处理 Handler * @author weachy * @version * @since JDK1.5 */ public class AutoResizeCurrentRowsCommandHandler implements ILayerCommandHandler<AutoResizeCurrentRowsCommand> { private final CompositeLayer layer; public AutoResizeCurrentRowsCommandHandler(CompositeLayer compositeLayer) { this.layer = compositeLayer; } public boolean doCommand(ILayer targetLayer, AutoResizeCurrentRowsCommand command) { // Need to resize selected rows even if they are outside the viewport targetLayer.doCommand(new TurnViewportOffCommand()); int[] gridRowPositions = command.getRows(); int[] gridRowHeights = getPreferedRowHeights(command.getConfigRegistry(), layer, gridRowPositions); layer.doCommand(new MultiRowResizeCommand(layer, gridRowPositions, gridRowHeights)); targetLayer.doCommand(new TurnViewportOnCommand()); return true; } public Class<AutoResizeCurrentRowsCommand> getCommandClass() { return AutoResizeCurrentRowsCommand.class; } /** * @see MaxCellBoundsHelper#getPreferedColumnWidths(IConfiguration, GC, ILayer, int[]) */ private int[] getPreferedRowHeights(IConfigRegistry configRegistry, ILayer layer, int[] rows) { int[] rowHeights = new int[rows.length]; // 获取编辑区高度(编辑器中,去除corner的高度) int clientAreaHeight = layer.getClientAreaProvider().getClientArea().height; for (int i = 0; i < rows.length; i++) { rowHeights[i] = getPreferredRowHeight(layer, rows[i], configRegistry, null, clientAreaHeight); } return rowHeights; } private int getPreferredRowHeight(ILayer layer, int rowPosition, IConfigRegistry configRegistry, GC gc, int clientAreaHeight) { int maxHeight = 0; ICellPainter painter; LayerCell cell; for (int columnPosition = 0; columnPosition < layer.getColumnCount(); columnPosition++) { cell = layer.getCellByPosition(columnPosition, rowPosition); if (cell != null) { painter = configRegistry.getConfigAttribute(CellConfigAttributes.CELL_PAINTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels()); if (painter != null) { int preferedHeight = painter.getPreferredHeight(cell, gc, configRegistry); maxHeight = (preferedHeight > maxHeight) ? preferedHeight : maxHeight; } } } if (maxHeight > clientAreaHeight) { return clientAreaHeight; } return maxHeight; } }
3,206
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UpdateDataAndAutoResizeCommandHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/UpdateDataAndAutoResizeCommandHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import java.text.MessageFormat; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.UpdateDataOperation; import net.sourceforge.nattable.NatTable; import net.sourceforge.nattable.command.AbstractLayerCommandHandler; import net.sourceforge.nattable.layer.DataLayer; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.operations.IOperationHistory; import org.eclipse.core.commands.operations.OperationHistoryFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * 修改后保存内容并自适应大小的处理 handler * @author weachy * @version 1.0 * @since JDK1.5 */ public class UpdateDataAndAutoResizeCommandHandler extends AbstractLayerCommandHandler<UpdateDataAndAutoResizeCommand> { private static final Logger LOGGER = LoggerFactory.getLogger(UpdateDataAndAutoResizeCommandHandler.class); private final NatTable table; private final DataLayer dataLayer; public UpdateDataAndAutoResizeCommandHandler(NatTable table, DataLayer dataLayer) { this.table = table; this.dataLayer = dataLayer; } @Override protected boolean doCommand(UpdateDataAndAutoResizeCommand command) { try { // int columnPosition = command.getColumnPosition(); // int rowPosition = command.getRowPosition(); // dataLayer.getDataProvider().setDataValue(columnPosition, rowPosition, command.getNewValue()); // dataLayer.fireLayerEvent(new CellVisualChangeEvent(dataLayer, columnPosition, rowPosition)); // // int currentRow = command.getRowPosition() + 1; // 修改行在当前一屏显示的几行中的相对位置 // table.doCommand(new AutoResizeCurrentRowsCommand(table, new int[] { currentRow }, // table.getConfigRegistry(), new GC(table))); IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory(); operationHistory.execute(new UpdateDataOperation(table, dataLayer, command), null, null); return true; } catch (UnsupportedOperationException e) { LOGGER.error( MessageFormat.format(Messages.getString("handler.UpdateDataAndAutoResizeCommandHandler.logger1"), command.getNewValue()), e); e.printStackTrace(System.err); System.err.println("Failed to update value to: " + command.getNewValue()); } catch (ExecutionException e) { LOGGER.error("", e); e.printStackTrace(); } return false; } public Class<UpdateDataAndAutoResizeCommand> getCommandClass() { // TODO Auto-generated method stub return UpdateDataAndAutoResizeCommand.class; } }
2,639
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
CopySourceHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/CopySourceHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import java.util.HashMap; import java.util.List; import java.util.Map; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 复制来源到目标 * @author weachy * @version * @since JDK1.5 */ public class CopySourceHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor instanceof XLIFFEditorImplWithNatTable) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; XLFHandler handler = xliffEditor.getXLFHandler(); List<String> rowIds = xliffEditor.getSelectedRowIds(); boolean locked = false; Map<String,String> map = new HashMap<String, String>(); for (int i = 0; i < rowIds.size(); i++) { String rowId = rowIds.get(i); if (handler.isLocked(rowId)) { // 已经批准或者已锁定,则不进行修改。 locked = true; continue; } String srcContent = handler.getSrcContent(rowId); String newValue = srcContent == null ? "" : srcContent; map.put(rowId, newValue); } if (locked) { if (!MessageDialog.openConfirm(xliffEditor.getSite().getShell(), Messages.getString("handler.CopySourceHandler.msgTitle"), Messages.getString("handler.CopySourceHandler.msg"))) { return null; } } StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor(); if(cellEditor != null){ HsMultiActiveCellEditor.setCellEditorForceFocus(cellEditor.getColumnPosition(), cellEditor.getRowPosition()); } xliffEditor.updateSegments(map, xliffEditor.getTgtColumnIndex(), null, null); } return null; } }
2,338
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
MergeSegmentHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/MergeSegmentHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 合并文本段的 Handler * @author peason * @version * @since JDK1.6 */ public class MergeSegmentHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (!(editor instanceof XLIFFEditorImplWithNatTable)) { return null; } XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; NattableUtil util = NattableUtil.getInstance(xliffEditor); util.mergeSegment(); return null; } }
1,002
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AutoResizeCurrentRowsCommand.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/AutoResizeCurrentRowsCommand.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.sourceforge.nattable.command.AbstractMultiRowCommand; import net.sourceforge.nattable.command.ILayerCommand; import net.sourceforge.nattable.config.IConfigRegistry; import net.sourceforge.nattable.layer.ILayer; /** * 自适应当前显示行的高度的Command * @author weachy * @version * @since JDK1.5 */ public class AutoResizeCurrentRowsCommand extends AbstractMultiRowCommand { private final IConfigRegistry configRegistry; private int[] rows; protected AutoResizeCurrentRowsCommand(AutoResizeCurrentRowsCommand command) { super(command); this.configRegistry = command.configRegistry; } public AutoResizeCurrentRowsCommand(ILayer layer, int[] rowPositions, IConfigRegistry configRegistry) { super(layer); this.configRegistry = configRegistry; this.rows = rowPositions; } public ILayerCommand cloneCommand() { return new AutoResizeCurrentRowsCommand(this); } public IConfigRegistry getConfigRegistry() { return configRegistry; } public int[] getRows() { return rows; } }
1,094
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
CopyAllSourceHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/CopyAllSourceHandler.java
/** * CopyAllSourceCommand.java * * Version information : * * Date:2012-8-26 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiCellEditorControl; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.swt.custom.BusyIndicator; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * @author Jason * @version * @since JDK1.6 */ public class CopyAllSourceHandler extends AbstractHandler { /** * (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { final IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor instanceof XLIFFEditorImplWithNatTable) { BusyIndicator.showWhile(HandlerUtil.getActiveWorkbenchWindow(event).getShell().getDisplay(), new Runnable() { public void run() { // fixed Bug #2638 XLIFF 编辑器:复制所有源文到目标时,译文处于编辑模式的文本段“未能”正确复制 HsMultiActiveCellEditor.commit(true); XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; XLFHandler handler = xliffEditor.getXLFHandler(); handler.copyAllSource2Target(); xliffEditor.redraw(); HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor); } }); } return null; } }
2,333
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ClickColumnCommandHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/ClickColumnCommandHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.sourceforge.nattable.command.ILayerCommandHandler; import net.sourceforge.nattable.layer.ILayer; import net.sourceforge.nattable.selection.SelectionLayer; import net.sourceforge.nattable.selection.command.SelectColumnCommand; /** * @author weachy * @version * @since JDK1.5 */ public class ClickColumnCommandHandler implements ILayerCommandHandler<SelectColumnCommand> { private final SelectionLayer selectionLayer; public ClickColumnCommandHandler(SelectionLayer selectionLayer) { this.selectionLayer = selectionLayer; } public boolean doCommand(ILayer targetLayer, SelectColumnCommand command) { if (command.convertToTargetLayer(selectionLayer)) { // TODO 点击列头时触发,后面可以在这里处理排序 return true; } return false; } public Class<SelectColumnCommand> getCommandClass() { return SelectColumnCommand.class; } }
946
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
EditCurrentSourceTextHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/EditCurrentSourceTextHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.EditableManager; import net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.SourceEditMode; /** * 编辑当前源文本的 Handler * @author peason * @version * @since JDK1.6 */ public class EditCurrentSourceTextHandler extends ChangeSourceEditableHandler { @Override public SourceEditMode getSourceEditMode(EditableManager editableManager) { editableManager.getSourceEditMode(); return SourceEditMode.ONCE_EDITABLE; } }
569
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ChangeSourceEditableHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/ChangeSourceEditableHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.EditableManager; import net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.SourceEditMode; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.NatTableConstant; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.sourceforge.nattable.edit.EditConfigAttributes; import net.sourceforge.nattable.edit.editor.ICellEditor; import net.sourceforge.nattable.style.DisplayMode; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 设置“是否允许编辑源文本”状态 * @author weachy * @since JDK1.5 */ public abstract class ChangeSourceEditableHandler extends AbstractHandler { private Listener listener = new Listener() { public void handleEvent(Event event) { StyledTextCellEditor sce = (StyledTextCellEditor) event.data; if (sce.getCellType().equals(NatTableConstant.SOURCE)) { EditableManager editableManager = sce.getEditableManager(); if (editableManager.getSourceEditMode() == SourceEditMode.ONCE_EDITABLE) { editableManager.setSourceEditMode(SourceEditMode.DISEDITABLE); // TODO 设置默认模式图片 // element.setIcon(Activator.getImageDescriptor(SourceEditMode.DISEDITABLE.getImagePath())); } } } }; public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; ICellEditor cellEditor = xliffEditor.getTable().getConfigRegistry().getConfigAttribute( EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL); if (cellEditor == null || !(cellEditor instanceof StyledTextCellEditor)) { return null; } HsMultiActiveCellEditor.commit(false); StyledTextCellEditor sce = (StyledTextCellEditor) cellEditor; EditableManager editableManager = sce.getEditableManager(); // SourceEditMode nextMode = editableManager.getSourceEditMode().getNextMode(); SourceEditMode nextMode = getSourceEditMode(editableManager); editableManager.setSourceEditMode(nextMode); // element.setIcon(Activator.getImageDescriptor(nextMode.getImagePath())); if (!sce.isClosed()) { editableManager.judgeEditable(); // 更新全局 Action 的可用状态,主要是更新编辑-删除功能的可用状态。 sce.getActionHandler().updateActionsEnableState(); } sce.addClosingListener(listener); } return null; } public abstract SourceEditMode getSourceEditMode(EditableManager editableManager); }
3,181
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
DeleteAllSegmentNoteHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/DeleteAllSegmentNoteHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; /** * 删除所有文本段的全部批注(此类未使用,因此未做国际化) * @author weachy * @version * @since JDK1.5 */ public class DeleteAllSegmentNoteHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (!(editor instanceof XLIFFEditorImplWithNatTable)) { return null; } IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); boolean res = MessageDialog.openConfirm(window.getShell(), "删除确认", "确定要删除所有文本段的全部批注吗?"); if (res) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; XLFHandler handler = xliffEditor.getXLFHandler(); handler.deleteAllSegmentNote(); } return null; } }
1,358
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
SplitSegmentHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/SplitSegmentHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.NatTableConstant; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.SplitSegmentOperation; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.operations.IOperationHistory; import org.eclipse.core.commands.operations.OperationHistoryFactory; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 分割文本段 * @author weachy * @version * @since JDK1.5 */ public class SplitSegmentHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (!(editor instanceof XLIFFEditorImplWithNatTable)) { return null; } XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor(); if (cellEditor == null) { return null; } if (!cellEditor.getCellType().equals(NatTableConstant.SOURCE)) { showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1")); return null; } int rowIndex = cellEditor.getRowIndex(); // 如果是垂直布局,那么 rowIndex 要除以2 --robert if (!xliffEditor.isHorizontalLayout()) { rowIndex = rowIndex / 2; } int caretOffset = cellEditor.getRealSplitOffset(); if (caretOffset < 0) { // 文本框已经关闭时 showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1")); return null; } // 不能选择多个字符进行分割 String selText = cellEditor.getSegmentViewer().getTextWidget().getSelectionText(); if (selText.length() != 0) { showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1")); return null; } XLFHandler handler = xliffEditor.getXLFHandler(); String rowId = handler.getRowId(rowIndex); /* burke 修改锁定文本段不能被分割和光标在文本段段首或者段末时,不能进行分割的BUG 添加代码 起 */ String tgt = handler.getCaseTgtContent(rowId); if (null != tgt) { if (tgt.equals("no")) { showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg2")); return null; } } int cellTextLength = ((UpdateDataBean) cellEditor.getCanonicalValue()).getText().length(); if (caretOffset <= 0 || caretOffset >= cellTextLength) { showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg3")); return null; } /* burke 修改锁定文本段不能被分割和光标在文本段段首或者段末时,不能进行分割的BUG 添加代码 终 */ cellEditor.close(); // 关闭Editor IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory(); try { operationHistory.execute(new SplitSegmentOperation("Split Segment", xliffEditor, handler, rowIndex, caretOffset), null, null); } catch (ExecutionException e) { e.printStackTrace(); } return null; } private void showInformation(ExecutionEvent event, String message) throws ExecutionException { Shell shell = HandlerUtil.getActiveShellChecked(event); MessageDialog.openInformation(shell, Messages.getString("handler.SplitSegmentHandler.msgTitle"), message); } }
3,954
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UpdateDataAndAutoResizeCommand.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/UpdateDataAndAutoResizeCommand.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.sourceforge.nattable.command.AbstractPositionCommand; import net.sourceforge.nattable.layer.ILayer; public class UpdateDataAndAutoResizeCommand extends AbstractPositionCommand { private Object newValue; public UpdateDataAndAutoResizeCommand(ILayer layer, int columnPosition, int rowPosition, Object newValue) { super(layer, columnPosition, rowPosition); this.newValue = newValue; } protected UpdateDataAndAutoResizeCommand(UpdateDataAndAutoResizeCommand command) { super(command); this.newValue = command.newValue; } public Object getNewValue() { // if (newValue instanceof String) { // String value = (String)newValue; // value = value.replaceAll("&", "&amp;"); // value = value.replaceAll("<", "&lt;"); // value = value.replaceAll(">", "&gt;"); // this.newValue = value; // } return newValue; } public UpdateDataAndAutoResizeCommand cloneCommand() { return new UpdateDataAndAutoResizeCommand(this); } @Override public boolean convertToTargetLayer(ILayer targetLayer) { return true; } }
1,152
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
DeleteCurrentSegmentAltTransHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/DeleteCurrentSegmentAltTransHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; /** * 删除当前文本段匹配 * @author weachy * @version * @since JDK1.5 */ public class DeleteCurrentSegmentAltTransHandler extends AbstractHandler { public Object execute(final ExecutionEvent event) throws ExecutionException { // final IEditorPart editor = HandlerUtil.getActiveEditor(event); // if (!(editor instanceof XLIFFEditorImplWithNatTable)) { // return null; // } // final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); // boolean res = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), // Messages.getString("handler.DeleteCurrentSegmentAltTransHandler.msgTitle1"), // Messages.getString("handler.DeleteCurrentSegmentAltTransHandler.msg1")); // if (res) { // BusyIndicator.showWhile(Display.getDefault(), // new Runnable() { // public void run() { // final XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; // XLFHandler handler = xliffEditor.getXLFHandler(); // // final int[] rowIndexs = xliffEditor.getSelectedRows(); // List<String> rowIds = new ArrayList<String>(xliffEditor.getXLFHandler() // .getRowIds(rowIndexs)); // // handler.deleteAltTrans(rowIds); // Display.getDefault().syncExec(new Runnable() { // public void run() { // IViewPart viewPart = window.getActivePage().findView( // "net.heartsome.cat.ts.ui.translation.view.matchview"); // if (viewPart != null && viewPart instanceof IMatchViewPart && rowIndexs.length != 0) { // ((IMatchViewPart) viewPart).refreshView(xliffEditor, rowIndexs[rowIndexs.length - 1]); // } // } // }); // } // }); // } return null; } }
1,937
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
DeleteSelectSegmentHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/DeleteSelectSegmentHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; /** * 删除选中文本段匹配 Handler * @author peason * @version * @since JDK1.6 */ public class DeleteSelectSegmentHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { // IEditorPart editor = HandlerUtil.getActiveEditor(event); // if (!(editor instanceof XLIFFEditorImplWithNatTable)) { // return null; // } // IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); // boolean res = MessageDialog.openConfirm(window.getShell(), "删除确认", "确定要删除选中文本段翻译吗?"); // if (res) { // XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; // try { // xliffEditor.updateSegments(xliffEditor.getSelectedRowIds(), xliffEditor.getTgtColumnIndex(), ""); // } catch (Exception e) { // e.printStackTrace(); // } // } return null; } }
1,417
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
DeleteAllSegmentTranslationsHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/DeleteAllSegmentTranslationsHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import java.util.ArrayList; import java.util.List; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * 删除选中文本段的译文 * @author weachy * @version * @since JDK1.5 */ public class DeleteAllSegmentTranslationsHandler extends AbstractHandler { private static final Logger LOGGER = LoggerFactory.getLogger(DeleteSelectionSegmentTranslationsHandler.class); public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (!(editor instanceof XLIFFEditorImplWithNatTable)) { return null; } IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg3")); if (res) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; try { XLFHandler handler = xliffEditor.getXLFHandler(); int count = xliffEditor.getAllRowCount(); int[] selectedRows = new int[count]; for (int i = 0; i < count; i++) { selectedRows[i] = i; } List<Integer> rows = new ArrayList<Integer>(); boolean exitFlag = false; for (int i = 0; i < selectedRows.length; i++) { String tgt = handler.getCaseTgtContent(handler.getRowId(selectedRows[i])); if (null != tgt) { if (tgt.equals("no")) { exitFlag = true; continue; } } rows.add(selectedRows[i]); } if (rows.size() != 0) { int columnIndex = xliffEditor.getTgtColumnIndex(); StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor(); if (cellEditor != null && cellEditor.getColumnIndex() == columnIndex) { cellEditor.getSegmentViewer().getTextWidget().forceFocus(); } int[] updateRows = new int[rows.size()]; for (int i = 0; i < rows.size(); i++) { int ri = rows.get(i); updateRows[i] = ri; } xliffEditor.updateCells(updateRows, columnIndex, ""); if (exitFlag) { MessageDialog.openInformation(xliffEditor.getSite().getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg2")); } } } catch (Exception e) { LOGGER.error("", e); e.printStackTrace(); } } return null; } }
3,267
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
EditAllSourceTextHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/EditAllSourceTextHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.EditableManager; import net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.SourceEditMode; /** * 编辑所有源文本的 Handler * @author peason * @version * @since JDK1.6 */ public class EditAllSourceTextHandler extends ChangeSourceEditableHandler { @Override public SourceEditMode getSourceEditMode(EditableManager editableManager) { return editableManager.getSourceEditMode().ALWAYS_EDITABLE; } }
550
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AddSelectionSegmentNotesHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/AddSelectionSegmentNotesHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog.AddOrUpdateNoteDialog; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 添加批注的 Handler * @author peason * @version * @since JDK1.6 */ public class AddSelectionSegmentNotesHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editorPart = HandlerUtil.getActiveEditor(event); if (editorPart instanceof XLIFFEditorImplWithNatTable) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editorPart; AddOrUpdateNoteDialog dialog = new AddOrUpdateNoteDialog(xliffEditor.getSite().getShell(), xliffEditor, AddOrUpdateNoteDialog.DIALOG_ADD, null); dialog.open(); } return null; } }
1,099
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
DeleteToEndOrToTagHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/DeleteToEndOrToTagHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import static net.heartsome.cat.common.innertag.factory.PlaceHolderEditModeBuilder.PATTERN; import java.util.Hashtable; import java.util.regex.Matcher; import net.heartsome.cat.ts.ui.innertag.SegmentViewer; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.NatTableConstant; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.graphics.Point; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 目标文本段中删除光标后或者标记前所有内容的 Handler * @author peason * @version * @since JDK1.6 */ public class DeleteToEndOrToTagHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor instanceof XLIFFEditorImplWithNatTable) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; String deleteType = event.getParameter("DeleteContent"); if (deleteType == null) { return null; } StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor(); if (cellEditor == null || !cellEditor.getCellType().equals(NatTableConstant.TARGET)) { return null; } if (!cellEditor.isEditable()) { // cellEditor.showUneditableMessage(); MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages .getString("handler.DeleteToEndOrToTagHandler.msgTitle"), cellEditor.getEditableManager() .getUneditableMessage()); return null; } StyledText styledText = cellEditor.getSegmentViewer().getTextWidget(); int offset = styledText.getCaretOffset(); Point p = styledText.getSelection(); if (p != null) { int len = styledText.getText().length(); String preText = ""; String nextText = ""; SegmentViewer viewer = (SegmentViewer) cellEditor.getSegmentViewer(); if (offset > 0) { preText = styledText.getText(0, offset - 1); preText = viewer.convertDisplayTextToOriginalText(preText); } // 删除标记前所有内容 if (deleteType.equals("DeleteToTag") && offset < len) { nextText = styledText.getText(offset, len - 1); Matcher matcher = PATTERN.matcher(nextText); if (matcher.find()) { int index = matcher.start(); nextText = nextText.substring(index); } else { // 选择删除标记前所有内容时,如果当前光标之后没有标记,则删除光标之后的所有内容 nextText = ""; } } nextText = viewer.convertDisplayTextToOriginalText(nextText); String newText = preText + nextText; Hashtable<String, String> map = new Hashtable<String, String>(); // Fix Bug #2883 删除光标后内容--同时选择多个文本段进行操作时,界面出错 By Jason // for (String rowId : xliffEditor.getSelectedRowIds()) { // map.put(rowId, newText); // } int index = cellEditor.getRowIndex(); String rowId = xliffEditor.getXLFHandler().getRowId(index); map.put(rowId, newText); xliffEditor.updateSegments(map, xliffEditor.getTgtColumnIndex(), null, null); // 定位光标 styledText.setCaretOffset(offset); } } return null; } }
3,777
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ChangeEditorLayoutHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/ChangeEditorLayoutHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import java.util.Map; import net.heartsome.cat.ts.ui.xliffeditor.nattable.Activator; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.ImageConstant; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.commands.IElementUpdater; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.menus.UIElement; /** * 改变基于 NatTable 编辑器的布局 handler * @author cheney * @since JDK1.6 */ public class ChangeEditorLayoutHandler extends AbstractHandler implements IElementUpdater { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editorPart = HandlerUtil.getActiveEditor(event); // 改为布局 if (editorPart != null && editorPart instanceof XLIFFEditorImplWithNatTable) { // ActiveCellRegion.setActiveCellRegion(null); ((XLIFFEditorImplWithNatTable) editorPart).changeLayout(); } return null; } public void updateElement(UIElement element, Map parameters) { String layout = (String) parameters.get("xliffEditor.layout"); if (XLIFFEditorImplWithNatTable.getCurrent().isHorizontalLayout()) { ImageDescriptor horizontalImageDescriptor = Activator .getImageDescriptor(layout == null ? ImageConstant.TOOL_LAYOUT_HORIZONTAL : "images/view/horizontal.png"); element.setIcon(horizontalImageDescriptor); element.setTooltip(Messages.getString("handler.ChangeEditorLayoutHandler.horizontalTooltip")); } else { ImageDescriptor verticalImageDescriptor = Activator .getImageDescriptor(layout == null ? ImageConstant.TOOL_LAYOUT_VERTICAL : "images/view/vertical.png"); element.setIcon(verticalImageDescriptor); element.setTooltip(Messages.getString("handler.ChangeEditorLayoutHandler.verticalTooltip")); } } }
2,166
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
VerticalMoveRowSelectionCommandHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/VerticalMoveRowSelectionCommandHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.config.VerticalNatTableConfig; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.sourceforge.nattable.selection.MoveRowSelectionCommandHandler; import net.sourceforge.nattable.selection.SelectionLayer; /** * 垂直布局下,处理选择行移动的 Handler。 (用户通过键盘的方向键移动选中行时,以三行为一个单位移动) * @author weachy * @version * @since JDK1.5 */ public class VerticalMoveRowSelectionCommandHandler extends MoveRowSelectionCommandHandler { public VerticalMoveRowSelectionCommandHandler(SelectionLayer selectionLayer) { super(selectionLayer); } @Override protected void moveLastSelectedUp(int stepSize, boolean withShiftMask, boolean withControlMask) { if (stepSize > 0) { stepSize = stepSize * VerticalNatTableConfig.ROW_SPAN; // 增大到所跨行数倍 } super.moveLastSelectedUp(stepSize, withShiftMask, withControlMask); XLIFFEditorImplWithNatTable.getCurrent().updateStatusLine(); } @Override protected void moveLastSelectedDown(int stepSize, boolean withShiftMask, boolean withControlMask) { if (stepSize > 0) { stepSize = stepSize * VerticalNatTableConfig.ROW_SPAN; // 增大到所跨行数倍 } super.moveLastSelectedDown(stepSize, withShiftMask, withControlMask); XLIFFEditorImplWithNatTable.getCurrent().updateStatusLine(); } }
1,490
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
CustomMatchHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/CustomMatchHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog.CustomMatchConditionDialog; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.PlatformUI; public class CustomMatchHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { CustomMatchConditionDialog dialog = new CustomMatchConditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); dialog.open(); return null; } }
641
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
CustomMatchContributionItem.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/CustomMatchContributionItem.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map.Entry; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import org.eclipse.jface.action.ContributionItem; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Item; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; public class CustomMatchContributionItem extends ContributionItem { public CustomMatchContributionItem() { } public CustomMatchContributionItem(String id) { super(id); } @Override public void fill(Menu menu, int index) { LinkedHashMap<String, String> map = XLFHandler.getCustomMatchFilterMap(); if (map == null || map.size() == 0) { for (Item item : menu.getItems()) { if (!item.isDisposed()) { item.dispose(); } } } else { for (Entry<String, String> entry : map.entrySet()) { final String xpath = entry.getValue(); MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText(entry.getKey()); item.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { XLIFFEditorImplWithNatTable xliffEditor = XLIFFEditorImplWithNatTable.getCurrent(); if (xliffEditor == null) { return; } xliffEditor.getXLFHandler().deleteAltTrans(xpath); ArrayList<Integer> rowList = new ArrayList<Integer>(); int[] rows = xliffEditor.getSelectedRows(); for (int i : rows) { rowList.add(i); } StructuredSelection selection = new StructuredSelection(rowList); xliffEditor.getSite().getSelectionProvider().setSelection( selection); } }); } } } @Override public boolean isDynamic() { return true; } }
2,016
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
CancelEditSourceTextHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/CancelEditSourceTextHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.EditableManager; import net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.SourceEditMode; /** * 取消编辑源文本的 Handler * @author peason * @version * @since JDK1.6 */ public class CancelEditSourceTextHandler extends ChangeSourceEditableHandler { @Override public SourceEditMode getSourceEditMode(EditableManager editableManager) { return editableManager.getSourceEditMode().DISEDITABLE; } }
549
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
DeleteSelectionSegmentTranslationsHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/DeleteSelectionSegmentTranslationsHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import java.util.ArrayList; import java.util.List; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * 删除选中文本段的译文 * @author weachy * @version * @since JDK1.5 */ public class DeleteSelectionSegmentTranslationsHandler extends AbstractHandler { private static final Logger LOGGER = LoggerFactory.getLogger(DeleteSelectionSegmentTranslationsHandler.class); public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (!(editor instanceof XLIFFEditorImplWithNatTable)) { return null; } IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg1")); if (res) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; try { XLFHandler handler = xliffEditor.getXLFHandler(); int[] selectedRows = xliffEditor.getSelectedRows(); List<Integer> rows = new ArrayList<Integer>(); boolean exitFlag = false; for (int i = 0; i < selectedRows.length; i++) { String tgt = handler.getCaseTgtContent(handler.getRowId(selectedRows[i])); if (null != tgt) { if (tgt.equals("no")) { exitFlag = true; continue; } } rows.add(selectedRows[i]); } if (rows.size() != 0) { int columnIndex = xliffEditor.getTgtColumnIndex(); StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor(); if (cellEditor != null && cellEditor.getColumnIndex() == columnIndex) { cellEditor.getSegmentViewer().getTextWidget().forceFocus(); } int[] updateRows = new int[rows.size()]; for (int i = 0; i < rows.size(); i++) { int ri = rows.get(i); updateRows[i] = ri; } xliffEditor.updateCells(updateRows, columnIndex, ""); if (exitFlag) { MessageDialog.openInformation(xliffEditor.getSite().getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg2")); } } } catch (Exception e) { LOGGER.error("", e); e.printStackTrace(); } } return null; } }
3,173
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
MergeNextHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/MergeNextHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import java.util.List; import net.heartsome.cat.ts.core.file.RowIdUtil; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.MergeSegmentOperation; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.operations.IOperationHistory; import org.eclipse.core.commands.operations.OperationHistoryFactory; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; /** * 与下一文本段合并(此类未使用,因此未做国际化) * @author weachy * @version * @since JDK1.5 */ public class MergeNextHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (!(editor instanceof XLIFFEditorImplWithNatTable)) { return null; } XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; List<String> selectedRowIds = xliffEditor.getSelectedRowIds(); if (selectedRowIds.size() < 1) { return null; } String rowId = selectedRowIds.get(selectedRowIds.size() - 1); XLFHandler handler = xliffEditor.getXLFHandler(); int rowIndex = handler.getRowIndex(rowId); IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); if (rowIndex == handler.countEditableTransUnit() - 1) { // 是最后一行 MessageDialog.openWarning(window.getShell(), "", "不存在下一文本段,不能合并。"); return null; } String rowId2 = handler.getRowId(rowIndex + 1); if (handler.isApproved(rowId) || handler.isApproved(rowId2)) { MessageDialog.openWarning(window.getShell(), "", "已批准文本段,不能合并。"); return null; } String fileName1 = RowIdUtil.getFileNameByRowId(rowId); String fileName2 = RowIdUtil.getFileNameByRowId(rowId2); if (fileName1 == null || fileName2 == null || !fileName1.equals(fileName2)) { MessageDialog.openWarning(window.getShell(), "", "文本段不在同一个文件内,不能合并。"); return null; } // IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory(); // try { // operationHistory.execute(new MergeSegmentOperation("Merge Segment", xliffEditor, handler, // rowIndex), null, null); // } catch (ExecutionException e) { // e.printStackTrace(); // } return null; } }
2,713
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
EditSelectionSegmentNotesHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/EditSelectionSegmentNotesHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog.UpdateNoteDialog; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 编辑批注的 Handler * @author peason * @version * @since JDK1.6 */ public class EditSelectionSegmentNotesHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editorPart = HandlerUtil.getActiveEditor(event); if (editorPart instanceof XLIFFEditorImplWithNatTable) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editorPart; if(xliffEditor.getSelectedRows().length == 0){ return null; } if (xliffEditor.getSelectedRows().length > 1) { MessageDialog.openInformation(xliffEditor.getSite().getShell(), Messages.getString("menu.BodyMenuConfiguration.msgTitle"), Messages.getString("menu.BodyMenuConfiguration.msg5")); return null; } UpdateNoteDialog dialog = new UpdateNoteDialog(xliffEditor.getSite().getShell(), xliffEditor,xliffEditor.getSelectedRows()[0]); dialog.open(); } return null; } }
1,535
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
MergePreviousHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/MergePreviousHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import java.util.List; import net.heartsome.cat.ts.core.file.RowIdUtil; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.LayerUtil; import net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.MergeSegmentOperation; import net.sourceforge.nattable.selection.SelectionLayer; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.operations.IOperationHistory; import org.eclipse.core.commands.operations.OperationHistoryFactory; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; /** * 与上一文本段合并(此类未使用,因此未做国际化) * @author weachy * @version * @since JDK1.5 */ public class MergePreviousHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (!(editor instanceof XLIFFEditorImplWithNatTable)) { return null; } XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; List<String> selectedRowIds = xliffEditor.getSelectedRowIds(); if (selectedRowIds.size() < 1) { return null; } String rowId = selectedRowIds.get(0); XLFHandler handler = xliffEditor.getXLFHandler(); int rowIndex = handler.getRowIndex(rowId); IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); if (rowIndex == 0) { // 是第一行 MessageDialog.openWarning(window.getShell(), "", "不存在上一文本段,不能合并。"); return null; } String rowId2 = handler.getRowId(rowIndex - 1); if (handler.isApproved(rowId) || handler.isApproved(rowId2)) { MessageDialog.openWarning(window.getShell(), "", "已批准文本段,不能合并。"); return null; } String fileName1 = RowIdUtil.getFileNameByRowId(rowId); String fileName2 = RowIdUtil.getFileNameByRowId(rowId2); if (fileName1 == null || fileName2 == null || !fileName1.equals(fileName2)) { MessageDialog.openWarning(window.getShell(), "", "文本段不在同一个文件内,不能合并。"); return null; } // IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory(); // try { // operationHistory.execute(new MergeSegmentOperation("Merge Segment", xliffEditor, handler, // rowIndex - 1), null, null); // } catch (ExecutionException e) { // e.printStackTrace(); // } // 选中上一行 SelectionLayer selectionLayer = LayerUtil.getLayer(xliffEditor.getTable(), SelectionLayer.class); selectionLayer.selectRow(0, rowIndex - 1, false, false); return null; } }
2,967
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
DeleteSelectionSegmentNotesHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/DeleteSelectionSegmentNotesHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler; import java.util.HashMap; import java.util.List; import java.util.Vector; import net.heartsome.cat.ts.core.bean.NoteBean; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ximpleware.NavException; import com.ximpleware.XPathEvalException; import com.ximpleware.XPathParseException; /** * 删除所选文本段批注 * @author weachy * @version * @since JDK1.5 */ public class DeleteSelectionSegmentNotesHandler extends AbstractHandler { private static final Logger LOGGER = LoggerFactory.getLogger(DeleteSelectionSegmentNotesHandler.class); public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (!(editor instanceof XLIFFEditorImplWithNatTable)) { return null; } IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg1")); if (res) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; XLFHandler handler = xliffEditor.getXLFHandler(); List<String> lstRowId = xliffEditor.getSelectedRowIds(); // 先将应用范围为当前文本段的批注删除 handler.deleteEditableSegmentNote(lstRowId); try { HashMap<String, Vector<NoteBean>> mapNote = new HashMap<String, Vector<NoteBean>>(); for (String rowId : lstRowId) { // 删除应用范围为所有文本段的批注 Vector<NoteBean> noteBeans = xliffEditor.getXLFHandler().getNotes(rowId); if (noteBeans != null && noteBeans.size() > 0) { mapNote.put(rowId, noteBeans); } } xliffEditor.getXLFHandler().deleteNote(mapNote); } catch (NavException e) { LOGGER.error("", e); MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2")); } catch (XPathParseException e) { LOGGER.error("", e); MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2")); } catch (XPathEvalException e) { LOGGER.error("", e); MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2")); } finally { xliffEditor.refresh(); } } return null; } }
3,347
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ExportAsTextHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/export/ExportAsTextHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.export; import java.io.File; import java.net.URI; import net.heartsome.cat.common.ui.utils.OpenEditorUtil; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.ide.FileStoreEditorInput; import org.eclipse.ui.part.FileEditorInput; /** * 此类未使用,因此未做国际化 * @author peason * @version * @since JDK1.6 */ public class ExportAsTextHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { String elementName = event.getParameter("elementName"); IEditorPart activeEditor = HandlerUtil.getActiveEditor(event); Shell shell = activeEditor.getEditorSite().getShell(); if (activeEditor == null || !(activeEditor instanceof XLIFFEditorImplWithNatTable)) { return null; } XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) activeEditor; if (xliffEditor.isMultiFile()) { MessageDialog.openInformation(shell, "", "当前编辑器打开了多个文件,无法执行该操作。"); } IEditorInput input = xliffEditor.getEditorInput(); URI uri = null; if (input instanceof FileEditorInput) { uri = ((FileEditorInput) input).getURI(); } else if (input instanceof FileStoreEditorInput) { uri = ((FileStoreEditorInput) input).getURI(); } else { return null; } File xliff = new File(uri); FileDialog fd = new FileDialog(shell, SWT.SAVE); String[] names = { "Plain Text Files [*.txt]", "All Files [*.*]" }; String[] extensions = { "*.txt", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$ fd.setFilterExtensions(extensions); fd.setFilterNames(names); fd.setFileName(xliff.getName() + ".txt"); //$NON-NLS-1$ String out = fd.open(); if (out == null) { return null; } XLFHandler handler = xliffEditor.getXLFHandler(); boolean result = handler.saveAsText(xliff.getAbsolutePath(), out, elementName); if (result) { IWorkbenchPage page = xliffEditor.getEditorSite().getPage(); OpenEditorUtil.OpenFileWithSystemEditor(page, out); } else { MessageDialog.openInformation(shell, "", "文件 “" + out + "” 保存失败!请重试。"); } return null; } }
2,745
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ExportHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/export/ExportHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.export; import net.heartsome.cat.common.core.Constant; import net.heartsome.cat.common.ui.wizard.TSWizardDialog; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IExportWizard; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ExportHandler extends AbstractHandler { private static final Logger LOGGER = LoggerFactory.getLogger(ExportHandler.class); private static final String PARAMETER_ID = "ExportWizardClassName"; public Object execute(ExecutionEvent event) throws ExecutionException { IStructuredSelection currentSelection = getSelectionToUse(event); IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); IExportWizard wizard = getExportWizard(event); wizard.init(window.getWorkbench(), currentSelection); TSWizardDialog dialog = new TSWizardDialog(window.getShell(), wizard); dialog.create(); dialog.open(); return null; } /** * 得到选中项 * @param event * @return ; */ protected IStructuredSelection getSelectionToUse(ExecutionEvent event) { String partId = HandlerUtil.getActivePartId(event); if (Constant.NAVIGATOR_VIEW_ID.equals(partId)) { ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof IStructuredSelection) { return (IStructuredSelection) selection; } } return StructuredSelection.EMPTY; } /** * 得到导出向导 * @param event * @return ; */ protected IExportWizard getExportWizard(ExecutionEvent event) { String wizardClassName = event.getParameter(PARAMETER_ID); try { Object obj = Class.forName(wizardClassName).newInstance(); if (IExportWizard.class.isInstance(obj)) { return (IExportWizard) obj; } } catch (ClassNotFoundException e) { LOGGER.error("", e); e.printStackTrace(); } catch (InstantiationException e) { LOGGER.error("", e); e.printStackTrace(); } catch (IllegalAccessException e) { LOGGER.error("", e); e.printStackTrace(); } return null; } }
2,407
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ExportAsHtmlHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/export/ExportAsHtmlHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.export; import java.io.File; import java.net.URI; import net.heartsome.cat.common.ui.utils.OpenEditorUtil; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.ide.FileStoreEditorInput; import org.eclipse.ui.part.FileEditorInput; /** * 此类未使用,因此未做国际化 * @author peason * @version * @since JDK1.6 */ public class ExportAsHtmlHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { String elementName = event.getParameter("elementName"); IEditorPart activeEditor = HandlerUtil.getActiveEditor(event); Shell shell = activeEditor.getEditorSite().getShell(); if (activeEditor == null || !(activeEditor instanceof XLIFFEditorImplWithNatTable)) { return null; } XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) activeEditor; if (xliffEditor.isMultiFile()) { MessageDialog.openInformation(shell, "", "当前编辑器打开了多个文件,无法执行该操作。"); } IEditorInput input = xliffEditor.getEditorInput(); URI uri = null; if (input instanceof FileEditorInput) { uri = ((FileEditorInput) input).getURI(); } else if (input instanceof FileStoreEditorInput) { uri = ((FileStoreEditorInput) input).getURI(); } else { return null; } File xliff = new File(uri); FileDialog fd = new FileDialog(shell, SWT.SAVE); String[] names = { "HTML Files [*.html]", "All Files [*.*]" }; String[] extensions = { "*.html", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$ fd.setFilterExtensions(extensions); fd.setFilterNames(names); fd.setFileName(xliff.getName() + ".html"); //$NON-NLS-1$ String out = fd.open(); if (out == null) { return null; } XLFHandler handler = xliffEditor.getXLFHandler(); boolean result = handler.saveAsHtml(xliff.getAbsolutePath(), out, elementName); if (result) { IWorkbenchPage page = xliffEditor.getEditorSite().getPage(); OpenEditorUtil.OpenFileWithSystemEditor(page, out); } else { MessageDialog.openInformation(shell, "", "文件 “" + out + "” 保存失败!请重试。"); } return null; } }
2,742
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
LockSegmentHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/translation/LockSegmentHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.translation; import java.util.ArrayList; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 翻译菜单下,锁定文本段-->锁定文本段的 handler * @author robert 2012-05-02 修改 * @version * @since JDK1.6 */ public class LockSegmentHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { // 这是之前的实现方式,这是锁定文本段。锁定全部文本段,锁定可编辑文本段的共同 handler,--robert 2012-05-02 // String lockSegment = event.getParameter("lockSegment"); // if (lockSegment == null) { // return null; // } // State state = event.getCommand().getState(RegistryToggleState.STATE_ID); // boolean isSelect = (Boolean) (state.getValue()); // state.setValue(!isSelect); // IEditorPart editor = HandlerUtil.getActiveEditor(event); // if (editor instanceof XLIFFEditorImplWithNatTable) { // XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; // // // 批准可编辑文本段时要初始化 rowIds ,批准所有文本段则不需要 // if (lockSegment.equals("lockDuplicateSegment")) { // // TODO 解决如何高效获取重复文本段后再做 // // } else { // ArrayList<String> rowIds = null; // if (lockSegment.equals("lockEditableSegment")) { // rowIds = xliffEditor.getXLFHandler().getRowIds(); // } else if (lockSegment.equals("lockAllSegment")) { // rowIds = null; // } // NattableUtil util = new NattableUtil(xliffEditor); // util.lockTransUnits(rowIds, !isSelect); // // 改变单元格编辑器模式为“只读” // util.changeCellEditorMode(rowIds, null); // // TODO 入库 // // } // // } IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor instanceof XLIFFEditorImplWithNatTable) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; XLFHandler handler = xliffEditor.getXLFHandler(); ArrayList<String> rowIds = (ArrayList<String>) xliffEditor.getSelectedRowIds(); ArrayList<String> needLockRowIds = new ArrayList<String>(); // 先判断所有的选择文本段的是否锁定状态 for (String rowId : rowIds) { if (!handler.isLocked(rowId)) { needLockRowIds.add(rowId); } } NattableUtil util = NattableUtil.getInstance(xliffEditor); // 如果都是锁定状态的,那么把它们都变成未锁定 if (needLockRowIds.size() <= 0) { util.lockTransUnits(rowIds, false); } else { util.lockTransUnits(needLockRowIds, true); // 改变单元格编辑器模式为“只读” // util.changeCellEditorMode(rowIds, null); } HsMultiActiveCellEditor.refrushCellsEditAbility(); } return null; } }
3,274
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UnTranslatedSegmentHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/translation/UnTranslatedSegmentHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.translation; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; /** * 未翻译 * @author peason * @version * @since JDK1.6 */ public class UnTranslatedSegmentHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { return null; } }
461
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
NeedReviewSegmentHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/translation/NeedReviewSegmentHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.translation; import java.util.List; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 有疑问的 Handler * @author peason * @version * @since JDK1.6 */ public class NeedReviewSegmentHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor instanceof XLIFFEditorImplWithNatTable) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; XLFHandler handler = xliffEditor.getXLFHandler(); List<String> selectedRowIds = xliffEditor.getSelectedRowIds(); boolean isNeedReview = true; //先判断所有的选择文本段的是否锁定状态 for(String rowId : selectedRowIds){ if (!handler.isNeedReview(rowId)) { isNeedReview = false; break; } } NattableUtil util = NattableUtil.getInstance(xliffEditor); util.changIsQuestionState(selectedRowIds, isNeedReview ? "no" : "yes"); } return null; } }
1,462
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AddSegmentToTMHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/translation/AddSegmentToTMHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.translation; import java.util.Arrays; import net.heartsome.cat.common.resources.ResourceUtils; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.view.IMatchViewPart; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiCellEditorControl; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.handlers.HandlerUtil; /** * 添加选中文本段到记忆库的 Handler * @author peason * @version * @since JDK1.6` */ public class AddSegmentToTMHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (!(editor instanceof XLIFFEditorImplWithNatTable)) { return null; } XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; String addSegmentToTM = event.getParameter("addSegmentToTM"); if (addSegmentToTM == null) { return null; } NattableUtil util = NattableUtil.getInstance(xliffEditor); HsMultiActiveCellEditor.commit(true); boolean state = util.addSelectSegmentToTM(); if (!state) { return null; } // 刷新项目 ResourceUtils.refreshCurentSelectProject(); if (addSegmentToTM.equals("addToTMAndJumpNext")) { // 添加到记忆库并跳转到下一文本段 int[] selectedRows = xliffEditor.getSelectedRows(); if (selectedRows.length < 1) { return null; } Arrays.sort(selectedRows); int lastSelectedRow = selectedRows[selectedRows.length - 1]; // 假如当前选择了第1,3行,则跳转到下一文本段时是跳转到第2行 for (int rowNum = 0; rowNum < selectedRows.length - 1; rowNum++) { if (selectedRows[rowNum + 1] != (selectedRows[rowNum] + 1)) { lastSelectedRow = rowNum; break; } } XLFHandler handler = xliffEditor.getXLFHandler(); int lastRow = handler.countEditableTransUnit() - 1; if (lastSelectedRow == lastRow) { lastSelectedRow = lastRow - 1; } xliffEditor.jumpToRow(lastSelectedRow + 1); } else if (addSegmentToTM.equals("addToTMAndJumpNextNotCompleteMatch")) { // 添加到记忆库并跳转到下一非完全匹配 int[] selectedRows = xliffEditor.getSelectedRows(); if (selectedRows.length < 1) { return null; } Arrays.sort(selectedRows); int lastSelectedRow = selectedRows[selectedRows.length - 1]; // 假如当前选择了第1,3行,则跳转到下一非完全匹配文本段时要从第2行开始检查 for (int rowNum = 0; rowNum < selectedRows.length - 1; rowNum++) { if (selectedRows[rowNum + 1] != (selectedRows[rowNum] + 1)) { lastSelectedRow = rowNum; break; } } XLFHandler handler = xliffEditor.getXLFHandler(); int row = handler.getNextFuzzySegmentIndex(lastSelectedRow); if (row != -1) { xliffEditor.jumpToRow(row); } else { MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("translation.AddSegmentToTMHandler.msgTitle"), Messages.getString("translation.AddSegmentToTMHandler.msg")); } } else { IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( "net.heartsome.cat.ts.ui.translation.view.matchview"); int[] selected =xliffEditor.getSelectedRows(); if (viewPart != null && viewPart instanceof IMatchViewPart && selected.length != 0) { ((IMatchViewPart) viewPart).reLoadMatches(xliffEditor, selected[selected.length - 1]); } HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor); } return null; } }
4,200
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
NotSendToTMHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/translation/NotSendToTMHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.translation; import java.util.List; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 不添加到记忆库 * @author peason * @version * @since JDK1.6 */ public class NotSendToTMHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor instanceof XLIFFEditorImplWithNatTable) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; List<String> selectedRowIds = xliffEditor.getSelectedRowIds(); if (selectedRowIds != null && selectedRowIds.size() > 0) { boolean isSendtoTm = true; XLFHandler handler = xliffEditor.getXLFHandler(); for (String rowId : selectedRowIds) { if (!handler.isSendToTM(rowId) && isSendtoTm) { isSendtoTm = false; break; } } NattableUtil util = NattableUtil.getInstance(xliffEditor); util.changeSendToTmState(selectedRowIds, isSendtoTm ? "yes" : "no"); } } return null; } }
1,481
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
DraftSegmentHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/translation/DraftSegmentHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.translation; import java.util.List; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 草稿 * @author peason * @version * @since JDK1.6 */ public class DraftSegmentHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor instanceof XLIFFEditorImplWithNatTable) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; NattableUtil util = NattableUtil.getInstance(xliffEditor); List<String> selectedRowIds = util.getRowIdsNoEmptyTranslate(false); if (selectedRowIds != null && selectedRowIds.size() > 0) { util.changeTgtState(selectedRowIds, "new"); } } return null; } }
1,165
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
SignedOffSegmentHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/translation/SignedOffSegmentHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.translation; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 执行签发的 Handler * @author peason * @version * @since JDK1.6 */ public class SignedOffSegmentHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (!(editor instanceof XLIFFEditorImplWithNatTable)) { return null; } XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; NattableUtil.getInstance(xliffEditor).changeToSignedOffState(); return null; } }
996
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UnlockSegmentHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/translation/UnlockSegmentHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.translation; import net.heartsome.cat.ts.core.file.XLFHandler; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 给当前界面所显示的所有文本段解锁 * @author robert 2012-09-24 */ public class UnlockSegmentHandler extends AbstractHandler{ public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart part = HandlerUtil.getActiveEditor(event); if (part instanceof XLIFFEditorImplWithNatTable) { final XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) part; XLFHandler handler = nattable.getXLFHandler(); handler.unlockSegment(); nattable.refresh(); HsMultiActiveCellEditor.refrushCellsEditAbility(); } return null; } }
1,129
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ApproveSegmentHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/translation/ApproveSegmentHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.translation; import java.util.List; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 是否批准可编辑/所有文本段的 Handler * @author peason * @version * @since JDK1.6 */ public class ApproveSegmentHandler extends AbstractHandler { public Object execute(ExecutionEvent event) { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor instanceof XLIFFEditorImplWithNatTable) { final XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; List<String> rowIds = xliffEditor.getSelectedRowIds(); if (rowIds.size() == 0) { return null; } String parameter = event.getParameter("approveSegment"); if (parameter != null) { HsMultiActiveCellEditor.commit(true); NattableUtil util = NattableUtil.getInstance(xliffEditor); util.approveTransUnits(parameter.equalsIgnoreCase("approveAndJumpNext")); // 执行批准 } } return null; } }
1,370
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
SplitPointSettingHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/translation/SplitPointSettingHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.translation; import java.util.List; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import net.heartsome.cat.ts.ui.xliffeditor.nattable.resource.Messages; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.part.FileEditorInput; /** * 设置 XLIFF 分割点 * @author peason * @version * @since JDK1.6 */ public class SplitPointSettingHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor instanceof XLIFFEditorImplWithNatTable) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; if (xliffEditor.isMultiFile()) { MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("menu.BodyMenuConfiguration.msgTitle"), Messages.getString("menu.BodyMenuConfiguration.msg7")); return null; } List<String> selectedRowIds = xliffEditor.getSelectedRowIds(); boolean isSplitPointExist = false; if (selectedRowIds != null && selectedRowIds.size() > 0) { for (String rowId : selectedRowIds) { if (xliffEditor.getSplitXliffPoints().contains(rowId)) { isSplitPointExist = true; } else { isSplitPointExist = false; break; } } if (!isSplitPointExist) { String xlfPath = ((FileEditorInput) xliffEditor.getEditorInput()).getFile().getLocation() .toOSString(); for (String rowId : selectedRowIds) { // String firstTURowId = xliffEditor.getXLFHandler().getRowIdByXpath(xlfPath, // "/xliff/file[1]/body/descendant::trans-unit[1]"); // if (firstTURowId != null && firstTURowId.equals(rowId)) { // MessageDialog.openInformation(HandlerUtil.getActiveShell(event), // Messages.getString("menu.BodyMenuConfiguration.msgTitle"), // Messages.getString("menu.BodyMenuConfiguration.msg8")); // continue; // } String lastTURowid = xliffEditor.getXLFHandler().getRowIdByXpath(xlfPath, "/xliff/file[last()]/body/descendant::trans-unit[last()]"); if (lastTURowid != null && lastTURowid.equals(rowId)) { MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("menu.BodyMenuConfiguration.msgTitle"), Messages.getString("menu.BodyMenuConfiguration.msg9")); continue; } if (!xliffEditor.getSplitXliffPoints().contains(rowId)) { // 将切割点的序列号添加到List中 xliffEditor.getSplitXliffPoints().add(rowId); xliffEditor.getTable().redraw(); } } } else { for (String rowId : selectedRowIds) { if (xliffEditor.getSplitXliffPoints().contains(rowId)) { // 删除切割点 int index = xliffEditor.getSplitXliffPoints().indexOf(rowId); xliffEditor.getSplitXliffPoints().remove(index); xliffEditor.getTable().redraw(); } } } } } return null; } }
3,295
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AcceptTerm5.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/acceptterm/AcceptTerm5.java
/** * AcceptTerm.java * * Version information : * * Date:2012-11-19 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.acceptterm; import net.heartsome.cat.ts.ui.view.ITermViewPart; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; /** * @author jason * @version * @since JDK1.6 */ public class AcceptTerm5 extends AbstractHandler { /** (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( "net.heartsome.cat.ts.ui.term.view.termView"); if (viewPart != null && viewPart instanceof ITermViewPart) { ITermViewPart matchView = (ITermViewPart) viewPart; matchView.acceptTermByIndex(4); } return null; } }
1,601
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AcceptTerm9.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/acceptterm/AcceptTerm9.java
/** * AcceptTerm.java * * Version information : * * Date:2012-11-19 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.acceptterm; import net.heartsome.cat.ts.ui.view.ITermViewPart; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; /** * @author jason * @version * @since JDK1.6 */ public class AcceptTerm9 extends AbstractHandler { /** (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( "net.heartsome.cat.ts.ui.term.view.termView"); if (viewPart != null && viewPart instanceof ITermViewPart) { ITermViewPart matchView = (ITermViewPart) viewPart; matchView.acceptTermByIndex(8); } return null; } }
1,601
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AcceptTerm6.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/acceptterm/AcceptTerm6.java
/** * AcceptTerm.java * * Version information : * * Date:2012-11-19 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.acceptterm; import net.heartsome.cat.ts.ui.view.ITermViewPart; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; /** * @author jason * @version * @since JDK1.6 */ public class AcceptTerm6 extends AbstractHandler { /** (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( "net.heartsome.cat.ts.ui.term.view.termView"); if (viewPart != null && viewPart instanceof ITermViewPart) { ITermViewPart matchView = (ITermViewPart) viewPart; matchView.acceptTermByIndex(5); } return null; } }
1,601
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AcceptTerm8.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/acceptterm/AcceptTerm8.java
/** * AcceptTerm.java * * Version information : * * Date:2012-11-19 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.acceptterm; import net.heartsome.cat.ts.ui.view.ITermViewPart; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; /** * @author jason * @version * @since JDK1.6 */ public class AcceptTerm8 extends AbstractHandler { /** (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( "net.heartsome.cat.ts.ui.term.view.termView"); if (viewPart != null && viewPart instanceof ITermViewPart) { ITermViewPart matchView = (ITermViewPart) viewPart; matchView.acceptTermByIndex(7); } return null; } }
1,601
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AcceptTerm7.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/acceptterm/AcceptTerm7.java
/** * AcceptTerm.java * * Version information : * * Date:2012-11-19 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.acceptterm; import net.heartsome.cat.ts.ui.view.ITermViewPart; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; /** * @author jason * @version * @since JDK1.6 */ public class AcceptTerm7 extends AbstractHandler { /** (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( "net.heartsome.cat.ts.ui.term.view.termView"); if (viewPart != null && viewPart instanceof ITermViewPart) { ITermViewPart matchView = (ITermViewPart) viewPart; matchView.acceptTermByIndex(6); } return null; } }
1,601
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AcceptTerm0.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/acceptterm/AcceptTerm0.java
/** * AcceptTerm.java * * Version information : * * Date:2012-11-19 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.acceptterm; import net.heartsome.cat.ts.ui.view.ITermViewPart; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; /** * @author jason * @version * @since JDK1.6 */ public class AcceptTerm0 extends AbstractHandler { /** (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( "net.heartsome.cat.ts.ui.term.view.termView"); if (viewPart != null && viewPart instanceof ITermViewPart) { ITermViewPart matchView = (ITermViewPart) viewPart; matchView.acceptTermByIndex(10); } return null; } }
1,602
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AcceptTerm4.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/acceptterm/AcceptTerm4.java
/** * AcceptTerm.java * * Version information : * * Date:2012-11-19 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.acceptterm; import net.heartsome.cat.ts.ui.view.ITermViewPart; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; /** * @author jason * @version * @since JDK1.6 */ public class AcceptTerm4 extends AbstractHandler { /** (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( "net.heartsome.cat.ts.ui.term.view.termView"); if (viewPart != null && viewPart instanceof ITermViewPart) { ITermViewPart matchView = (ITermViewPart) viewPart; matchView.acceptTermByIndex(3); } return null; } }
1,601
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AcceptTerm3.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/acceptterm/AcceptTerm3.java
/** * AcceptTerm.java * * Version information : * * Date:2012-11-19 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.acceptterm; import net.heartsome.cat.ts.ui.view.ITermViewPart; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; /** * @author jason * @version * @since JDK1.6 */ public class AcceptTerm3 extends AbstractHandler { /** (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( "net.heartsome.cat.ts.ui.term.view.termView"); if (viewPart != null && viewPart instanceof ITermViewPart) { ITermViewPart matchView = (ITermViewPart) viewPart; matchView.acceptTermByIndex(2); } return null; } }
1,601
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AcceptTerm2.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/acceptterm/AcceptTerm2.java
/** * AcceptTerm.java * * Version information : * * Date:2012-11-19 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.acceptterm; import net.heartsome.cat.ts.ui.view.ITermViewPart; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; /** * @author jason * @version * @since JDK1.6 */ public class AcceptTerm2 extends AbstractHandler { /** (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( "net.heartsome.cat.ts.ui.term.view.termView"); if (viewPart != null && viewPart instanceof ITermViewPart) { ITermViewPart matchView = (ITermViewPart) viewPart; matchView.acceptTermByIndex(1); } return null; } }
1,601
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AcceptTerm1.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/acceptterm/AcceptTerm1.java
/** * AcceptTerm.java * * Version information : * * Date:2012-11-19 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.acceptterm; import net.heartsome.cat.ts.ui.view.ITermViewPart; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; /** * @author jason * @version * @since JDK1.6 */ public class AcceptTerm1 extends AbstractHandler { /** (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( "net.heartsome.cat.ts.ui.term.view.termView"); if (viewPart != null && viewPart instanceof ITermViewPart) { ITermViewPart matchView = (ITermViewPart) viewPart; matchView.acceptTermByIndex(0); } return null; } }
1,601
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
DeleteAllTagsHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/tags/DeleteAllTagsHandler.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.tags; import java.util.ArrayList; import java.util.List; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiActiveCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor; import net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; /** * 删除所有标记 * @author weachy * @version * @since JDK1.5 */ public class DeleteAllTagsHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor instanceof XLIFFEditorImplWithNatTable) { XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor; int[] rows = xliffEditor.getSelectedRows(); if (rows.length == 0){ return null; } HsMultiCellEditor targetCellEditor = HsMultiActiveCellEditor.getTargetEditor(); StyledTextCellEditor cellEditor = targetCellEditor.getCellEditor(); if(cellEditor == null || cellEditor.isClosed()){ return null; } if(rows.length == 1){ cellEditor.clearTags(); // 清除内部标记 return null; } else { int activeEditRowIndex = targetCellEditor.getRowIndex(); cellEditor.clearTags(); // 清除内部标记 if(!xliffEditor.isHorizontalLayout()){ activeEditRowIndex = activeEditRowIndex / 2; } // non active row int[] nonActiveRows = new int[rows.length - 1]; int i = 0; for(int row : rows){ if(row == activeEditRowIndex){ continue; } nonActiveRows[i++] = row; } List<String> rowIdList = new ArrayList<String>(xliffEditor.getXLFHandler().getRowIds(rows)); xliffEditor.getXLFHandler().removeAllTags(rowIdList); xliffEditor.refresh(); } } return null; } }
2,157
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
QuickTagsHandler4.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/tags/QuickTagsHandler4.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.tags; /** * 快速插入标记 * @author weachy * @version * @since JDK1.5 */ public class QuickTagsHandler4 extends AbstractInsertTagHandler { @Override protected int getTagNum() { return 4; } }
269
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
QuickTagsHandler5.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/tags/QuickTagsHandler5.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.tags; /** * 快速插入标记 * @author weachy * @version * @since JDK1.5 */ public class QuickTagsHandler5 extends AbstractInsertTagHandler { @Override protected int getTagNum() { return 5; } }
269
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
QuickTagsHandler0.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/tags/QuickTagsHandler0.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.tags; /** * 快速插入标记 * @author weachy * @version * @since JDK1.5 */ public class QuickTagsHandler0 extends AbstractInsertTagHandler { @Override protected int getTagNum() { return 10; } }
270
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
QuickTagsHandler9.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/ts/net.heartsome.cat.ts.ui.xliffeditor.nattable/src/net/heartsome/cat/ts/ui/xliffeditor/nattable/handler/tags/QuickTagsHandler9.java
package net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.tags; /** * 快速插入标记 * @author weachy * @version * @since JDK1.5 */ public class QuickTagsHandler9 extends AbstractInsertTagHandler { @Override protected int getTagNum() { return 9; } }
269
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z