use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class MultiFilesOper method getOpenedIfile.
/**
* 获取所选择的要合并打开的文件中已经被打开的文件
* @return
*/
public List<IFile> getOpenedIfile() {
IEditorReference[] editorRes = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
List<IFile> isOpenedXlfList = new ArrayList<IFile>();
IXliffEditor xlfEditor;
try {
for (int i = 0; i < editorRes.length; i++) {
if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
IFile iFile = ((FileEditorInput) editorRes[i].getEditorInput()).getFile();
//合并打开的情况
if ("xlp".equals(iFile.getFileExtension())) {
xlfEditor = (IXliffEditor) editorRes[i].getEditor(true);
isOpenedXlfList.addAll(ResourceUtils.filesToIFiles(xlfEditor.getMultiFileList()));
} else {
try {
isOpenedXlfList.add(((FileEditorInput) editorRes[i].getEditorInput()).getFile());
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
} catch (Exception e) {
LOGGER.error("", e);
}
return isOpenedXlfList;
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class MultiFilesOper method hasOpenedIFile.
/**
* 验证当前要合并打开的文件是否有文件存在已经打开的情况,并从当前要合并打开的文件中删除已经打开的文件
* <div style='color:red'>这个方法一是验证 所选要打开的文件 中是否已经有被打开了的,第二是,会删除已经打开的文件,因此慎用。<br>
* getOpenedIfile 方法也有验证所选择文件是否有打开的情况</div>
* @return
*/
public boolean hasOpenedIFile() {
IEditorReference[] editorRes = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
List<IFile> isOpenedXlfList = new ArrayList<IFile>();
IXliffEditor xlfEditor;
boolean hasOpenedIFile = false;
try {
for (int i = 0; i < editorRes.length; i++) {
if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
IFile iFile = ((FileEditorInput) editorRes[i].getEditorInput()).getFile();
//合并打开的情况
if ("xlp".equals(iFile.getFileExtension())) {
System.out.println("---------------");
xlfEditor = (IXliffEditor) editorRes[i].getEditor(true);
isOpenedXlfList.addAll(ResourceUtils.filesToIFiles(xlfEditor.getMultiFileList()));
} else {
try {
isOpenedXlfList.add(((FileEditorInput) editorRes[i].getEditorInput()).getFile());
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
if (isOpenedXlfList.size() > 0) {
for (IFile iFile : isOpenedXlfList) {
if (selectIFiles.indexOf(iFile) >= 0) {
hasOpenedIFile = true;
selectIFiles.remove(iFile);
}
}
}
} catch (Exception e) {
LOGGER.error("", e);
}
return hasOpenedIFile;
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class MultiFilesOper method validExist.
/**
* 验证该合并打开的文件是否已经重复被打开,如果被合并打开,则返回true,未被打开,返回false.
* @param selectIFiles
* @return ;
*/
public boolean validExist() {
IEditorReference[] editorRes = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
for (int i = 0; i < editorRes.length; i++) {
if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
try {
IFile iFile = ((FileEditorInput) editorRes[i].getEditorInput()).getFile();
if (!"xlp".equals(iFile.getFileExtension())) {
continue;
}
} catch (Exception e) {
LOGGER.error("", e);
}
boolean isRepeat = true;
IXliffEditor xlfEditor = (IXliffEditor) editorRes[i].getEditor(true);
List<IFile> mergerIFileList = ResourceUtils.filesToIFiles(xlfEditor.getMultiFileList());
if (mergerIFileList.size() == selectIFiles.size()) {
for (IFile curIFile : selectIFiles) {
if (mergerIFileList.indexOf(curIFile) < 0) {
isRepeat = false;
break;
}
}
} else {
isRepeat = false;
}
if (isRepeat) {
return true;
}
}
}
return false;
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class ExecuteGoogleTransHandler method execute.
/**
* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof IXliffEditor)) {
return null;
}
// check the google translation state: check the key availability
PrefrenceParameters ps = PrefrenceParameters.getInstance();
if (!ps.getState()) {
MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteGoogleTransHandler.msgTitle"), Messages.getString("handler.ExecuteGoogleTransHandler.msg"));
return null;
}
final IXliffEditor xliffEditor = (IXliffEditor) editor;
final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
if (selectedRowIndexs.length == 0) {
return null;
}
// int currentRowIndex = selectedRowIndexs[0];
// TransUnitBean transUnitBean = xliffEditor.getRowTransUnitBean(currentRowIndex);
// if (transUnitBean == null) {
// return null;
// }
// String srcPureText = transUnitBean.getSrcText();
// String tgtLanguage = xliffEditor.getTgtColumnName();
// String srcLanguage = xliffEditor.getSrcColumnName();
// TransUnitInfo2TranslationBean tuInfo2Trans = new TransUnitInfo2TranslationBean();
// tuInfo2Trans.setSrcPureText(srcPureText);
// tuInfo2Trans.setSrcLanguage(srcLanguage);
// tuInfo2Trans.setTgtLangugage(tgtLanguage);
String tshelp = System.getProperties().getProperty("TSHelp");
String tsstate = System.getProperties().getProperty("TSState");
if (tshelp == null || !"true".equals(tshelp) || tsstate == null || !"true".equals(tsstate)) {
LoggerFactory.getLogger(ExecuteGoogleTransHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
System.exit(0);
}
ISimpleMatcher matcher = new SimpleMatcherGoogleImpl();
// String tgtText = matcher.executeMatch(tuInfo2Trans);
// if (tgtText.equals("")) {
// return null;
// }
// AltTransBean bean = new AltTransBean(srcPureText, tgtText, srcLanguage, tgtLanguage,
// matcher.getMathcerOrigin(), matcher.getMathcerToolId());
// bean.getMatchProps().put("match-quality", "100");
// bean.getMatchProps().put("hs:matchType", matcher.getMatcherType());
// bean.setSrcContent(srcPureText);
// bean.setTgtContent(tgtText);
// List<AltTransBean> newAltTrans = new ArrayList<AltTransBean>();
// newAltTrans.add(bean);
// check if need save the AltTrans to file
// if (CommonFunction.checkEdition("U") && matcher.isSuportPreTrans()) {
// List<String> oldToolIds = new ArrayList<String>();
// oldToolIds.add(matcher.getMathcerToolId());
// xliffEditor.getXLFHandler().updateAltTrans(xliffEditor.getXLFHandler().getRowId(currentRowIndex), newAltTrans, oldToolIds);
// }
IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
if (viewPart != null && viewPart instanceof MatchViewPart) {
MatchViewPart matchView = (MatchViewPart) viewPart;
matchView.manualExecSimpleTranslation(matcher);
//matchView.refreshView(xliffEditor, selectedRowIndexs[0]);
// matchView.replaceMatchs(newAltTrans);
// matchView.refreshViewByToolId(xliffEditor, newAltTrans, matcher.getMathcerToolId());
// newAltTrans.clear();
}
return null;
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class PreTranslationHandler method execute.
@Override
public Object execute(ExecutionEvent event, List<IFile> list) {
// 首先验证是否是合并打开的文件 --robert 2012-10-17
if (isEditor) {
try {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
IEditorReference[] editorRefe = window.getActivePage().findEditors(new FileEditorInput(list.get(0)), XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
if (editorRefe.length <= 0) {
return null;
}
IXliffEditor xlfEditor = (IXliffEditor) editorRefe[0].getEditor(true);
// 针对合并打开
if (xlfEditor.isMultiFile()) {
list = ResourceUtils.filesToIFiles(xlfEditor.getMultiFileList());
}
} catch (ExecutionException e) {
logger.error("", e);
}
}
CommonFunction.removeRepeateSelect(list);
PreTransUitls.executeTranslation(list, shell);
return null;
}
Aggregations