use of org.eclipse.ui.PartInitException in project translationstudio8 by heartsome.
the class TranslationProgressFA method printTransProgFAReslut.
public void printTransProgFAReslut() {
String htmlPath = createFAResultHtml();
try {
model.getAnalysisIFileList().get(0).getProject().getFolder("Intermediate").getFolder("Report").refreshLocal(IResource.DEPTH_ONE, null);
} catch (CoreException e1) {
e1.printStackTrace();
logger.error(Messages.getString("qa.fileAnalysis.TranslationProgressFA.log1"), e1);
}
final FileEditorInput input = new FileEditorInput(ResourceUtils.fileToIFile(htmlPath));
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, QAConstant.FA_HtmlBrowserEditor, true);
} catch (PartInitException e) {
e.printStackTrace();
logger.error(Messages.getString("qa.fileAnalysis.TranslationProgressFA.log2"), e);
}
}
});
}
use of org.eclipse.ui.PartInitException in project translationstudio8 by heartsome.
the class WordsFA method printWordsFAReslut.
//-------------------------------------------------------------------------------------------//
//---------------------------------下面的代码主要是报表部份---------------------------------------//
//-------------------------------------------------------------------------------------------//
/**
* 输出字数统计结果到结果窗体中
* @param WordsFAResultMap
*/
public void printWordsFAReslut() {
String htmlPath = createFAResultHtml();
try {
model.getAnalysisIFileList().get(0).getProject().getFolder("Intermediate").getFolder("Report").refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e1) {
e1.printStackTrace();
}
final FileEditorInput input = new FileEditorInput(ResourceUtils.fileToIFile(htmlPath));
if (PlatformUI.getWorkbench().isClosing()) {
return;
}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, QAConstant.FA_HtmlBrowserEditor, true);
} catch (PartInitException e) {
logger.error(Messages.getString("qa.fileAnalysis.WordsFA.log5"), e);
e.printStackTrace();
}
}
});
}
use of org.eclipse.ui.PartInitException in project translationstudio8 by heartsome.
the class QAResultViewPart method openMultiFilesEditor.
/**
* 处理合并打开文件 nattable editor的相关问题
* @return ;
*/
public IXliffEditor openMultiFilesEditor() {
IXliffEditor xliffEditor = null;
FileEditorInput fileInput = new FileEditorInput(oper.getCurMultiTempFile());
IEditorReference[] editorRefer = window.getActivePage().findEditors(fileInput, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
IEditorPart editorPart = null;
if (editorRefer.length >= 1) {
editorPart = editorRefer[0].getEditor(true);
xliffEditor = (IXliffEditor) editorPart;
// 若该文件未激活,激活此文件
if (window.getActivePage().getActiveEditor() != editorPart) {
window.getActivePage().activate(editorPart);
}
// 对于已经打开过的文件,进行重排序
xliffEditor.resetOrder();
} else {
// 如果文件没有打开,那么先打开文件
try {
// 如果保存合并打开所有信息的临时文件已经被删除,那么,重新生成临时文件
if (!oper.getCurMultiTempFile().getLocation().toFile().exists()) {
// 检查这两个文件是否重新进行合并打开了的。
IFile findMultiTempIfile = oper.getMultiFilesTempIFile(true);
if (findMultiTempIfile != null) {
fileInput = new FileEditorInput(findMultiTempIfile);
oper.setCurMultiTempFile(findMultiTempIfile);
} else {
//先验证这些所处理的文件是否有已经被打开的
List<IFile> openedFileList = oper.getOpenedIfile();
if (openedFileList.size() > 0) {
String openFileStr = "";
for (IFile ifile : openedFileList) {
openFileStr += "\t" + ifile.getFullPath().toOSString() + "\n";
}
MessageDialog.openInformation(getSite().getShell(), Messages.getString("views.QAResultViewPart.msgTitle"), MessageFormat.format(Messages.getString("qa.views.QAResultViewPart.addTip1"), openFileStr));
return null;
}
// 如果选中的文件没有合并打开,那么就重新打开它们
IFile multiIFile = oper.createMultiTempFile();
if (multiIFile != null && multiIFile.exists()) {
fileInput = new FileEditorInput(multiIFile);
oper.setCurMultiTempFile(multiIFile);
} else {
MessageDialog.openInformation(getSite().getShell(), Messages.getString("views.QAResultViewPart.msgTitle"), Messages.getString("views.QAResultViewPart.msg1"));
return null;
}
xliffEditor = (IXliffEditor) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
}
}
} catch (PartInitException e) {
e.printStackTrace();
logger.error(Messages.getString("qa.views.QAResultViewPart.log2"), e);
}
}
return xliffEditor;
}
use of org.eclipse.ui.PartInitException in project translationstudio8 by heartsome.
the class OpenMultiXliffHandler method execute.
@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (currentSelection.isEmpty() || !(currentSelection instanceof IStructuredSelection)) {
return null;
}
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
Iterator<Object> selectIt = structuredSelection.iterator();
final ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
shell = window.getShell();
// 先验证是否跨项目
IProject selectedProject = null;
while (selectIt.hasNext()) {
Object object = selectIt.next();
if (object instanceof IFile) {
IFile iFile = (IFile) object;
if (!CommonFunction.validXlfExtension(iFile.getFileExtension())) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), MessageFormat.format(Messages.getString("handlers.OpenMultiXliffHandler.msg1"), iFile.getFullPath().toOSString()));
continue;
}
selectIFiles.add(iFile);
if (selectedProject == null) {
selectedProject = iFile.getProject();
} else {
if (selectedProject != iFile.getProject()) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg2"));
return null;
}
}
} else if (object instanceof IContainer) {
IContainer selectContainer = (IContainer) object;
if (selectedProject == null) {
selectedProject = selectContainer.getProject();
}
// 判断当前文件夹是否处于 XLIFF 文件夹下
try {
ResourceUtils.getXliffs(selectContainer, selectIFiles);
} catch (CoreException e) {
logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger1"), selectContainer.getFullPath().toOSString(), e);
}
}
}
// 过滤重复选择文件
CommonFunction.removeRepeateSelect(selectIFiles);
if (selectIFiles.size() < 2) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg3"));
return null;
}
MultiFilesOper oper = new MultiFilesOper(selectedProject, selectIFiles);
// 先验证这些文件是否已经合并打开,如果是,则退出
if (oper.validExist()) {
return null;
}
// 判断是否有重复打开的文件,并删除缓存中要合并打开的文件。
if (oper.hasOpenedIFile()) {
if (oper.getSelectIFiles().size() <= 0) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg4"));
return null;
} else {
boolean isResponse = MessageDialog.openConfirm(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle2"), Messages.getString("handlers.OpenMultiXliffHandler.msg5"));
if (isResponse) {
if (oper.getSelectIFiles().size() < 2) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg6"));
return null;
}
} else {
return null;
}
}
}
final IFile multiIFile = oper.createMultiTempFile();
if (multiIFile != null && multiIFile.exists()) {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.getString("handler.OpenMultiXliffHandler.tip1"), 10);
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 7, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
// 进行判断所选择文件的语言对是否符合标准,先解析文件
final XLFHandler xlfHander = new XLFHandler();
final Map<String, Object> newResultMap = xlfHander.openFiles(ResourceUtils.iFilesToFiles(selectIFiles), subMonitor);
// 针对解析失败
if (newResultMap == null || QAConstant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) newResultMap.get(QAConstant.RETURNVALUE_RESULT)) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), (String) newResultMap.get(Constant.RETURNVALUE_MSG));
}
});
return;
}
// 验证是否有多个语言
boolean hasDiffrentLangPair = false;
Map<String, ArrayList<String>> langMap = xlfHander.getLanguages();
if (langMap.size() > 1) {
hasDiffrentLangPair = true;
} else {
for (Entry<String, ArrayList<String>> entry : langMap.entrySet()) {
if (entry.getValue().size() > 1) {
hasDiffrentLangPair = true;
}
}
}
if (monitor.isCanceled()) {
return;
}
monitor.worked(1);
if (hasDiffrentLangPair) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg7"));
}
});
// 先删除临时文件,再退出
try {
multiIFile.delete(true, monitor);
} catch (CoreException e) {
logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger2"), e);
}
return;
}
final boolean[] validateResult = new boolean[] { false };
Display.getDefault().syncExec(new Runnable() {
public void run() {
validateResult[0] = XLFValidator.validateXlifIFiles(selectIFiles);
}
});
if (!validateResult[0]) {
try {
multiIFile.delete(true, monitor);
} catch (CoreException e) {
logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger2"), e);
}
return;
}
final FileEditorInput input = new FileEditorInput(multiIFile);
if (monitor.isCanceled()) {
return;
}
monitor.worked(1);
Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
// UNDO 这里合并打开时,要考虑传入参数xlfHandler,以防多次解析文件带来的消耗。
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, XLIFF_EDITOR_ID, true);
} catch (PartInitException e) {
e.printStackTrace();
}
}
});
if (monitor.isCanceled()) {
return;
}
monitor.worked(1);
monitor.done();
}
};
try {
new ProgressMonitorDialog(shell).run(true, true, runnable);
} catch (Exception e) {
logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger3"), e);
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg8"));
return null;
}
return null;
}
use of org.eclipse.ui.PartInitException in project translationstudio8 by heartsome.
the class SplitXliffHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
final String navegatorID = "net.heartsome.cat.common.ui.navigator.view";
final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
final Shell shell = window.getShell();
IFile selectFile = null;
XLIFFEditorImplWithNatTable xliffEditor = null;
List<Integer> splitXlfPointsIndex = new LinkedList<Integer>();
List<String> splitXlfPointsRowId = new LinkedList<String>();
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
// 如果是导航视图,那么就获取导航视图中选中的文件
if (activePart instanceof IViewPart) {
if (navegatorID.equals(activePart.getSite().getId())) {
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(navegatorID);
ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
Object object = structuredSelection.getFirstElement();
if (object instanceof IFile) {
selectFile = (IFile) object;
String fileExtension = selectFile.getFileExtension();
// 如果后缀名不是xlf,那么就退出操作
if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
return null;
}
FileEditorInput fileInput = new FileEditorInput(selectFile);
IEditorReference[] editorRefer = window.getActivePage().findEditors(fileInput, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
IEditorPart editorPart = null;
if (editorRefer.length >= 1) {
editorPart = editorRefer[0].getEditor(true);
xliffEditor = (XLIFFEditorImplWithNatTable) editorPart;
if (window.getActivePage().getActiveEditor() != editorPart) {
window.getActivePage().activate(editorPart);
}
} else {
try {
xliffEditor = (XLIFFEditorImplWithNatTable) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
} catch (PartInitException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
return null;
}
}
}
} else if (activePart instanceof IEditorPart) {
if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
selectFile = ((FileEditorInput) xliffEditor.getEditorInput()).getFile();
}
}
// 根据每个tu节点的rowId获取其具体的位置,才好进行排序
Map<Integer, String> pointIndexRowIdMap = new HashMap<Integer, String>();
for (String rowId : xliffEditor.getSplitXliffPoints()) {
// 获取指定tu节点所处其他结点的序列号
int tuPostion = xliffEditor.getXLFHandler().getTUPositionByRowId(rowId);
if (tuPostion >= 1) {
splitXlfPointsIndex.add(tuPostion);
pointIndexRowIdMap.put(tuPostion, rowId);
}
}
if (splitXlfPointsIndex.size() <= 0) {
MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg2"));
return null;
}
// 对切割点集合进行排序
for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
int point1 = splitXlfPointsIndex.get(i);
for (int j = i + 1; j < splitXlfPointsIndex.size(); j++) {
int point2 = splitXlfPointsIndex.get(j);
if (point1 > point2) {
splitXlfPointsIndex.set(i, point2);
splitXlfPointsIndex.set(j, point1);
point1 = point2;
}
}
}
// 向存储rowId的list存放数据,这样的话,所存储的rowId就是经过排序了的。
for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
splitXlfPointsRowId.add(pointIndexRowIdMap.get(splitXlfPointsIndex.get(i)));
}
SplitOrMergeXlfModel model = new SplitOrMergeXlfModel();
model.setSplitFile(selectFile);
model.setSplitXlfPointsIndex(splitXlfPointsIndex);
model.setSplitXlfPointsRowId(splitXlfPointsRowId);
model.setXliffEditor(xliffEditor);
model.setShell(shell);
SplitXliffWizard wizard = new SplitXliffWizard(model);
final TSWizardDialog dialog = new NattableWizardDialog(shell, wizard);
dialog.open();
return null;
}
Aggregations