use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class PreMachineTransUitls method executeTranslation.
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 PreMachineTransParameters parameters = new PreMachineTransParameters();
PreMachineTranslationDialog dialog = new PreMachineTranslationDialog(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 {
PreMachineTranslation pt = new PreMachineTranslation(xlfHandler, filesWithOsPath, project, parameters);
try {
final List<PreMachineTranslationCounter> result = pt.executeTranslation(monitor);
Display.getDefault().syncExec(new Runnable() {
public void run() {
//PreMachineTranslationResultDialog dialog = new PreMachineTranslationResultDialog(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);
MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.result.msg"));
} catch (InvocationTargetException e) {
logger.error("", e);
} catch (InterruptedException e) {
logger.error("", e);
}
}
} finally {
HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
}
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class ImportProjectWizardPage2 method getAllOpenedIFile.
/**
* 获取所有已经被打开的文件
* @return
*/
private Map<IFile, IEditorPart> getAllOpenedIFile() {
Map<IFile, IEditorPart> openedIfileMap = new HashMap<IFile, IEditorPart>();
IEditorReference[] referenceArray = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
for (IEditorReference reference : referenceArray) {
IEditorPart editor = reference.getEditor(true);
// 如果这是一个 nattable 编辑器
if (XLIFF_EDITOR_ID.equals(editor.getSite().getId())) {
IXliffEditor xlfEditor = (IXliffEditor) editor;
if (xlfEditor.isMultiFile()) {
for (File file : xlfEditor.getMultiFileList()) {
openedIfileMap.put(ResourceUtils.fileToIFile(file.getAbsolutePath()), editor);
}
} else {
openedIfileMap.put(((FileEditorInput) editor.getEditorInput()).getFile(), editor);
}
} else {
// 其他情况,直接将文件丢进去就行了
openedIfileMap.put(((FileEditorInput) editor.getEditorInput()).getFile(), editor);
}
}
return openedIfileMap;
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class MultiFilesOper method getAllOpenedIFiles.
/**
* 获取当前所打开的所有文件
* @return
*/
public List<IFile> getAllOpenedIFiles() {
IEditorReference[] editorRes = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
List<IFile> isOpenedXlfList = new ArrayList<IFile>();
try {
IXliffEditor xlfEditor;
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 getMultiFilesTempIFile.
/**
* 根据指定要合并打开的文件,获取其配置文件
* @param selectIFiles
* @param isActive 如果找到了符合的合并打开临时文件,是否激活当前nattable编辑器
* @return ;
*/
public IFile getMultiFilesTempIFile(boolean isActive) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorReference[] editorRes = page.getEditorReferences();
for (int i = 0; i < editorRes.length; i++) {
if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
try {
IXliffEditor xlfEditor = (IXliffEditor) editorRes[i].getEditor(true);
IFile multiTempFile = ((FileEditorInput) editorRes[i].getEditorInput()).getFile();
List<File> openedFileList = xlfEditor.getMultiFileList();
boolean isExist = false;
if (selectIFiles.size() == openedFileList.size()) {
isExist = true;
for (IFile iFile : selectIFiles) {
if (openedFileList.indexOf(iFile.getFullPath().toFile()) == -1) {
continue;
}
}
}
// }
if (isActive) {
page.activate(editorRes[i].getEditor(true));
}
if (isExist) {
return multiTempFile;
}
} catch (PartInitException e) {
e.printStackTrace();
}
}
}
return null;
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class TermBaseSearchDialog method InsertGridTgtToEditor.
private void InsertGridTgtToEditor() {
GridItem[] selection = grid.getSelection();
if (null == selection || selection.length == 0) {
return;
}
IXliffEditor tempEditor = null;
IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (activeEditor instanceof IXliffEditor) {
IXliffEditor editor = (IXliffEditor) activeEditor;
tempEditor = editor;
}
if (tempEditor == null) {
return;
}
int[] selectedRows = tempEditor.getSelectedRows();
if (null == selectedRows || selectedRows.length == 0) {
return;
}
int rowIndex = selectedRows[0];
if (tempEditor == null || rowIndex < 0) {
return;
}
TransUnitBean transUnit = tempEditor.getRowTransUnitBean(rowIndex);
Hashtable<String, String> tuProp = transUnit.getTuProps();
if (tuProp != null) {
String translate = tuProp.get("translate");
if (translate != null && translate.equalsIgnoreCase("no")) {
MessageDialog.openInformation(tempEditor.getSite().getShell(), Messages.getString("view.TerminologyViewPart.msgTitle"), Messages.getString("view.TerminologyViewPart.msg1"));
return;
}
}
String tarTerm = selection[0].getText(1);
if (null == tarTerm || tarTerm.isEmpty()) {
return;
}
try {
tempEditor.insertCell(rowIndex, tempEditor.getTgtColumnIndex(), tarTerm);
// tempEditor.setFocus(); // 焦点给回编辑器
} catch (ExecutionException e) {
if (Constant.RUNNING_MODE == Constant.MODE_DEBUG) {
e.printStackTrace();
}
MessageDialog.openInformation(tempEditor.getSite().getShell(), Messages.getString("view.TerminologyViewPart.msgTitle"), Messages.getString("view.TerminologyViewPart.msg2") + e.getMessage());
}
}
Aggregations