use of net.heartsome.cat.database.ui.tm.wizard.UpdateTMWizardDialog 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