use of org.eclipse.ui.IEditorPart 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 org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.
the class ExecuteQuickTranslation method execute.
/** (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
if (TranslateParameter.getInstance().isAutoQuickTrans()) {
return null;
}
final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
final IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof IXliffEditor)) {
return null;
}
final IXliffEditor xliffEditor = (IXliffEditor) editor;
final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
if (selectedRowIndexs.length == 0) {
return null;
}
// TransUnitBean transUnitBean = xliffEditor.getRowTransUnitBean(selectedRowIndexs[selectedRowIndexs.length - 1]);
IComplexMatch matcher = new QuickTranslationImpl();
// FileEditorInput input = (FileEditorInput) editor.getEditorInput();
// IProject project = input.getFile().getProject();
// List<AltTransBean> newAltTrans = matcher.executeTranslation(transUnitBean, project);
// if(newAltTrans.size() == 0){
// return null;
// }
IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
if (viewPart != null && viewPart instanceof MatchViewPart) {
MatchViewPart matchView = (MatchViewPart) viewPart;
matchView.manualExecComplexTranslation(selectedRowIndexs[0], xliffEditor, matcher);
// matchView.replaceMatchs(newAltTrans);
// matchView.refreshView(xliffEditor, selectedRowIndexs[selectedRowIndexs.length - 1]);
}
// }
return null;
}
use of org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.
the class AbstractExportHandler method initExportConfig.
public boolean initExportConfig(ExecutionEvent event) throws ExecutionException {
config = new ExportConfig();
Shell shell = HandlerUtil.getActiveShell(event);
String partId = HandlerUtil.getActivePartId(event);
if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
// 导航视图处于激活状态
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (selection != null && !selection.isEmpty()) {
for (Object obj : selection.toList()) {
if (obj instanceof IFile) {
addXLFFile((IFile) obj);
} else if (obj instanceof IFolder) {
traversalFile((IFolder) obj);
} else if (obj instanceof IProject) {
IProject proj = (IProject) obj;
traversalFile(proj.getFolder(XLF));
}
}
if (config.getProjects() == null || config.getProjects().size() < 1) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("xlf2tmx.info.notfoundxlf"));
return false;
}
}
} else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
// nattable 处于激活状态
IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
IXliffEditor xliffEditor = (IXliffEditor) editor;
if (xliffEditor.isMultiFile()) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg2"));
return false;
} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
addXLFFile(iFile);
}
}
return true;
}
use of org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.
the class ExportDocxHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);
String partId = HandlerUtil.getActivePartId(event);
IFile file = null;
if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
// 导航视图处于激活状态
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
// ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
List<?> lstObj = ((IStructuredSelection) selection).toList();
ArrayList<IFile> lstXliff = new ArrayList<IFile>();
for (Object obj : lstObj) {
if (obj instanceof IFile) {
IFile tempFile = (IFile) obj;
// Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
if (tempFile.getFileExtension() != null && CommonFunction.validXlfExtension(tempFile.getFileExtension())) {
lstXliff.add(tempFile);
}
}
}
if (lstXliff.size() > 1) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg1"));
return null;
}
if (lstXliff.size() == 1) {
file = lstXliff.get(0);
}
}
} else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
// nattable 处于激活状态
IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
IXliffEditor xliffEditor = (IXliffEditor) editor;
if (xliffEditor.isMultiFile()) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg2"));
return null;
} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
file = iFile;
}
}
if (file != null) {
XLFValidator.resetFlag();
if (!XLFValidator.validateXliffFile(file)) {
return null;
}
XLFValidator.resetFlag();
}
ExportDocxDialog dialog = new ExportDocxDialog(shell, file == null ? "" : file.getFullPath().toOSString(), file == null ? "" : ResourceUtils.iFileToOSPath(file));
dialog.open();
return null;
}
use of org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.
the class BatchQAHandler method execute.
@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
isMultiFile = false;
preferenceStore = Activator.getDefault().getPreferenceStore();
// UNDO 如果焦点在其他视图上时,获取的文件错误。
IFile multiTempIFile = null;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
final Shell shell = window.getShell();
// ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
if (HandlerUtil.getActivePart(event) instanceof IViewPart) {
ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
Iterator<Object> selectIt = structuredSelection.iterator();
while (selectIt.hasNext()) {
Object object = selectIt.next();
if (object instanceof IFile) {
IFile selectFile = (IFile) object;
String fileExtension = selectFile.getFileExtension();
// 如果后缀名不是xlf,那么就进行提示
if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
boolean isSure = MessageDialog.openConfirm(shell, Messages.getString("qa.all.dialog.warning"), MessageFormat.format(Messages.getString("qa.all.tip.notXliff"), new Object[] { selectFile.getFullPath() }));
if (!isSure) {
return null;
}
continue;
}
selectIFiles.add(selectFile);
} else if (object instanceof IProject) {
IProject selectProject = (IProject) object;
try {
ResourceUtils.getXliffs(selectProject, selectIFiles);
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.handlers.BatchQAHandler.log1"), e);
}
} else if (object instanceof IContainer) {
IContainer selectContainer = (IContainer) object;
try {
ResourceUtils.getXliffs(selectContainer, selectIFiles);
} catch (Exception e) {
logger.error(Messages.getString("qa.handlers.BatchQAHandler.log1"), e);
e.printStackTrace();
}
}
}
}
} else {
//如果左边未选择品质检查的类型,那么,获取nattable中打开的文件
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
if (activeEditor != null && !activeEditor.getSite().getId().equals(XLIFF_EDITOR_ID)) {
MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.BatchQAHandler.tip2"));
return null;
}
XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) activeEditor;
isMultiFile = nattable.isMultiFile();
multiTempIFile = ((FileEditorInput) nattable.getEditorInput()).getFile();
if (isMultiFile) {
List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
for (String multiFileStr : multiFilesList) {
selectIFiles.add(ResourceUtils.fileToIFile(multiFileStr));
}
} else {
selectIFiles.add(multiTempIFile);
}
}
CommonFunction.removeRepeateSelect(selectIFiles);
if (selectIFiles.size() == 0) {
MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.BatchQAHandler.tip1"));
return null;
}
List<IFile> lstFiles = new ArrayList<IFile>();
XLFValidator.resetFlag();
for (IFile iFile : selectIFiles) {
if (!XLFValidator.validateXliffFile(iFile)) {
lstFiles.add(iFile);
}
}
XLFValidator.resetFlag();
selectIFiles.removeAll(lstFiles);
if (selectIFiles.size() == 0) {
return null;
}
model = new QAModel();
model.setQaXlfList(selectIFiles);
quality = new QualityAssurance(model);
BatchQADialog dialog = new BatchQADialog(shell, model, isMultiFile);
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
// 先调用方法,查看品质检查结果视图是否处于显示状态,如果显示了的。删除数据
IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = workbenchPage.findView(QAResultViewPart.ID);
if (view != null) {
// 运行时,将结果视图中列表的数据清除
((QAResultViewPart) view).clearTableData();
}
QAResult qaResult = new QAResult();
// 存储品质检查的检查项
model.setBatchQAItemIdList(getBatchQAItems());
// 存储品质检查的检查时不包括的文本段
model.setNotInclude(getNotIncludePara());
//给品质检查结果视图发出通告,本次检查对象为合并打开文件
// qaResult.firePropertyChange(isMultiFile, new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
// 将当前所处理的文件传至 qaResult
List<String> fileList = new ArrayList<String>();
for (IFile iFIle : model.getQaXlfList()) {
fileList.add(iFIle.getLocation().toOSString());
}
qaResult.setFilePathList(fileList);
HsMultiActiveCellEditor.commit(true);
if (isMultiFile) {
model.setMuliFiles(true);
model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
qaResult.setMultiOper(model.getMultiOper());
quality.beginMultiFileQA(qaResult);
} else {
model.setMuliFiles(false);
qaResult.setMultiOper(model.getMultiOper());
quality.beginQA(qaResult);
}
}
return null;
}
Aggregations