use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class WordsFA method lockRepeatTU.
/**
* 执行锁定重复文本段
*/
private void lockRepeatTU(Map<String, WordsFAResult> wordsFAResultMap) {
final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
// 首先,判断当前所处理的文件是否合并打开
if (model.isMultiFile()) {
if (needLockRowIdList.size() <= 0) {
return;
}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IEditorInput input = new FileEditorInput(model.getMultiTempIFile());
IEditorReference[] reference = window.getActivePage().findEditors(input, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
nattble = (XLIFFEditorImplWithNatTable) reference[0].getEditor(true);
XLFHandler thisHandler = nattble.getXLFHandler();
thisHandler.lockFaTU(needLockRowIdList);
nattble.redraw();
}
});
} else {
//针对已经打开的文件进行锁定
if (needLockRowIdList.size() <= 0) {
return;
}
final Map<String, List<String>> rowIdMap = RowIdUtil.groupRowIdByFileName(needLockRowIdList);
for (final IFile iFile : model.getAnalysisIFileList()) {
isOpened = false;
final String filePath = iFile.getLocation().toOSString();
if (rowIdMap.get(filePath) == null || rowIdMap.get(filePath).size() <= 0) {
continue;
}
Display.getDefault().syncExec(new Runnable() {
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IEditorInput input = new FileEditorInput(iFile);
IEditorReference[] reference = window.getActivePage().findEditors(input, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
if (reference.length > 0) {
isOpened = true;
nattble = (XLIFFEditorImplWithNatTable) reference[0].getEditor(true);
XLFHandler thisHandler = nattble.getXLFHandler();
thisHandler.lockFaTU(rowIdMap.get(filePath));
nattble.redraw();
}
}
});
if (!isOpened) {
for (String rowId : rowIdMap.get(filePath)) {
handler.lockedTU(rowId);
}
}
}
}
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class FileAnalysisHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
model = new FAModel();
faItemId = event.getParameter("faItemId");
allTUSize = 0;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
shell = window.getShell();
IFile multiTempIFile = null;
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;
@SuppressWarnings("unchecked") 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;
}
}
selectIFiles.add(selectFile);
} else if (object instanceof IContainer) {
IContainer selectContainer = (IContainer) object;
try {
ResourceUtils.getXliffs(selectContainer, selectIFiles);
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.handlers.FileAnalysisHandler.log1"), e);
}
}
}
}
} else if (HandlerUtil.getActivePart(event) instanceof IEditorPart) {
// 如果左边未选择品质检查的类型,那么,获取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);
}
} else {
MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip3"));
return null;
}
CommonFunction.removeRepeateSelect(selectIFiles);
if (selectIFiles.size() <= 0) {
MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.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;
}
// 判断要分析的文件是否是属于同一个项目中的.
IProject project = selectIFiles.get(0).getProject();
if (selectIFiles.size() >= 2) {
for (int i = 1; i < selectIFiles.size(); i++) {
if (selectIFiles.get(i).getProject() != project) {
MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip2"));
return null;
}
}
}
model.setAnalysisIFileList(selectIFiles);
model.setShell(shell);
model.setMultiFile(isMultiFile);
if (isMultiFile) {
model.setMultiTempIFile(multiTempIFile);
}
// 文件分析框的框名
title = model.getAnalysisItemMap().get(faItemId).get(QAConstant.FA_ITEM_NAME);
FileAnalysisDialog dialog = new FileAnalysisDialog(shell, model, title, faItemId);
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
analysisFile(title);
}
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class NumberOrTagConsisQAHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
boolean isMultiFile = false;
IFile multiTempIFile = null;
IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
// 改为布局
if (editorPart != null && editorPart instanceof XLIFFEditorImplWithNatTable) {
String qaItem = event.getParameter("qaItemId");
XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) editorPart;
ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
FileEditorInput input = (FileEditorInput) nattable.getEditorInput();
// 首先判断是否是合并打开的文件
if (nattable.isMultiFile()) {
isMultiFile = true;
}
if (isMultiFile) {
multiTempIFile = input.getFile();
List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
for (String filePath : multiFilesList) {
selectIFiles.add(ResourceUtils.fileToIFile(filePath));
}
} else {
selectIFiles.add(input.getFile());
}
QAModel model = new QAModel();
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
shell = window.getShell();
// 先调用方法,查看品质检查结果视图是否处于显示状态,如果是显示的,就删除数据
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));
if (isMultiFile) {
model.setMuliFiles(true);
model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
} else {
model.setMuliFiles(false);
}
boolean isNumberQA = false;
if (QAConstant.QA_NUMBER.equals(qaItem)) {
isNumberQA = true;
} else if (QAConstant.QA_TAG.equals(qaItem)) {
isNumberQA = false;
}
List<String> fileList = new ArrayList<String>();
for (IFile iFIle : selectIFiles) {
fileList.add(iFIle.getLocation().toOSString());
}
qaResult.setFilePathList(fileList);
HsMultiActiveCellEditor.commit(true);
beginQA(selectIFiles, model, isNumberQA, qaResult);
}
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class AddTermToTBDialog method okPressed.
@Override
protected void okPressed() {
String srcTerm = cleanString(txtSrc.getText());
String tgtTerm = cleanString(txtTgt.getText());
if (srcTerm == null || srcTerm.equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.msg1"));
return;
}
if (tgtTerm == null || tgtTerm.equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.msg2"));
return;
}
// 添加空格不可入库的判断,--robert 2012-11-19
if (srcTerm.length() > 0 && srcTerm.trim().equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.addTip1"));
return;
}
if (tgtTerm.length() > 0 && tgtTerm.trim().equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.addTip2"));
return;
}
srcTerm = srcTerm.trim();
tgtTerm = tgtTerm.trim();
XLFHandler handler = new XLFHandler();
IStructuredSelection srcSelected = (IStructuredSelection) cmbSrcLang.getSelection();
Language srcSelectedLang = (Language) srcSelected.getFirstElement();
String srcLang = srcSelectedLang.getCode();
IStructuredSelection tgtSelection = (IStructuredSelection) cmbTgtLang.getSelection();
Language tgtSelectedLang = (Language) tgtSelection.getFirstElement();
String tgtLang = tgtSelectedLang.getCode();
String strTBX = handler.generateTBXWithString(srcLang, tgtLang, srcTerm, tgtTerm, txtProperty.getText());
TbImporter importer = TbImporter.getInstance();
importer.setProject(project);
int state = -1;
try {
if (TYPE == EDIT_TYPE) {
if (null != this.dbOperator) {
state = DatabaseService.importTbxWithString(strTBX, null, this.dbOperator, Constants.IMPORT_MODEL_ALWAYSADD, srcLang);
if (state != 1) {
return;
}
}
} else if (TYPE == ADD_TYPE) {
state = importer.executeImport(strTBX, srcLang, null);
if (state == ITbImporter.IMPORT_STATE_FAILED) {
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.msg3"));
importer.clearResources();
return;
}
}
} catch (ImportException e) {
final String msg = e.getMessage();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), msg);
}
});
return;
}
importer.clearResources();
TerminologyViewPart view = (TerminologyViewPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(TerminologyViewPart.ID);
if (view != null) {
view.refresh();
}
setReturnCode(OK);
if (TYPE == ADD_TYPE) {
try {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
LOGGER.error("", e);
}
}
close();
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class UpdateTMHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);
String partId = HandlerUtil.getActivePartId(event);
ArrayList<IFile> lstXliff = new ArrayList<IFile>();
// boolean isShowCurrentLangBtn = true;
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();
for (Object obj : lstObj) {
if (obj instanceof IFile) {
IFile file = (IFile) obj;
// Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
if (file.getFileExtension() != null && CommonFunction.validXlfExtension(file.getFileExtension())) {
lstXliff.add(file);
}
} else if (obj instanceof IFolder) {
try {
ResourceUtils.getXliffs((IFolder) obj, lstXliff);
} catch (CoreException e) {
LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger1"), e);
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg1"));
}
} else if (obj instanceof IProject) {
try {
ResourceUtils.getXliffs((IProject) obj, lstXliff);
} catch (CoreException e) {
LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger2"), e);
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg2"));
}
}
}
CommonFunction.removeRepeateSelect(lstXliff);
if (lstXliff.size() == 0) {
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
return null;
}
Iterator<IFile> iterator = lstXliff.iterator();
while (iterator.hasNext()) {
IFile file = iterator.next();
FileEditorInput editorInput = new FileEditorInput(file);
IEditorPart editorPart = page.findEditor(editorInput);
if (editorPart == null || (editorPart != null && !(editorPart instanceof IXliffEditor))) {
// isShowCurrentLangBtn = false;
break;
}
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
return null;
}
} 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()) {
List<String> lstFile = new XLFHandler().getMultiFiles(iFile);
if (lstFile.size() > 0) {
for (String filePath : lstFile) {
lstXliff.add(ResourceUtils.fileToIFile(filePath));
}
}
} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
lstXliff.add(iFile);
}
}
if (lstXliff.size() > 0) {
if (lstXliff.size() > 1) {
String projectPath = lstXliff.get(0).getProject().getFullPath().toOSString();
for (int i = 1; i < lstXliff.size(); i++) {
String projectPath2 = lstXliff.get(i).getProject().getFullPath().toOSString();
if (!projectPath.equals(projectPath2)) {
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg4"));
return null;
}
}
}
ArrayList<IFile> lstFiles = new ArrayList<IFile>();
XLFValidator.resetFlag();
for (IFile iFile : lstXliff) {
if (!XLFValidator.validateXliffFile(iFile)) {
lstFiles.add(iFile);
}
}
XLFValidator.resetFlag();
lstXliff.removeAll(lstFiles);
if (lstXliff.size() == 0) {
return null;
}
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(lstXliff.get(0).getProject());
if (projectConfig.getDefaultTMDb() == null) {
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg5"));
return null;
}
UpdateTMWizard wizard = new UpdateTMWizard(lstXliff);
TSWizardDialog dialog = new UpdateTMWizardDialog(shell, wizard);
// UpdateTMDialog dialog = new UpdateTMDialog(shell, isShowCurrentLangBtn, lstXliff);
dialog.open();
}
return null;
}
Aggregations