use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class ExcutePreMachineTranlateHandler method execute.
/**
* (non-Javadoc)
* @see net.heartsome.cat.common.ui.handlers.AbstractSelectProjectFilesHandler#execute(org.eclipse.core.commands.ExecutionEvent,
* java.util.List)
*/
@Override
public Object execute(ExecutionEvent event, List<IFile> list) {
if (!CommonFunction.checkEdition("U")) {
MessageDialog.openInformation(shell, Messages.getString("handler.ExcutePreMachineTranlateHandler.tips"), Messages.getString("handler.ExcutePreMachineTranlateHandler.unsuportversion"));
return null;
}
// 首先验证是否是合并打开的文件 --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);
PreMachineTransUitls.executeTranslation(list, shell);
return null;
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class ExecuteBingTransHandler 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.isBingState()) {
MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteBingTransHandler.msgTitle"), Messages.getString("handler.ExecuteBingTransHandler.msg"));
return null;
}
final IXliffEditor xliffEditor = (IXliffEditor) editor;
final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
if (selectedRowIndexs.length == 0) {
return null;
}
ISimpleMatcher matcher = new SimpleMatcherBingImpl();
IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
if (viewPart != null && viewPart instanceof MatchViewPart) {
MatchViewPart matchView = (MatchViewPart) viewPart;
matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher);
}
return null;
}
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;
}
PrefrenceParameters ps = PrefrenceParameters.getInstance();
if (!ps.isGoogleState()) {
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;
}
ISimpleMatcher matcher = new SimpleMatcherGoogleImpl();
IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
if (viewPart != null && viewPart instanceof MatchViewPart) {
MatchViewPart matchView = (MatchViewPart) viewPart;
matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher);
}
return null;
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class PreTransUitls 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 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());
}
}
Aggregations