use of org.eclipse.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.
the class QAResultViewPart method createPropMenu.
/**
* 创建右键参数
*/
private void createPropMenu() {
Menu propMenu = new Menu(table);
table.setMenu(propMenu);
MenuItem deletWarnItem = new MenuItem(propMenu, SWT.NONE);
deletWarnItem.setText(Messages.getString("views.QAResultViewPart.deletWarnItem"));
deletWarnItem.setImage(deleteImage);
deletWarnItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
QAResultBean bean;
for (int i = 0; i < dataList.size(); i++) {
bean = dataList.get(i);
// 0为错误,1为警告
if (1 == bean.getLevel()) {
dataList.remove(bean);
i--;
}
}
tableModel.textRenderer.clearRowHeiMap();
table.redraw();
}
});
MenuItem deleteAllItem = new MenuItem(propMenu, SWT.NONE);
deleteAllItem.setText(Messages.getString("views.QAResultViewPart.deleteAllItem"));
deleteAllItem.setImage(deleteImage);
deleteAllItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
dataList.clear();
tableModel.textRenderer.clearRowHeiMap();
table.redraw();
}
});
// 导出品质检查报告
exportItem = new MenuItem(propMenu, SWT.NONE);
exportItem.setText(Messages.getString("qa.views.QAResultViewPart.exportPopMenu"));
exportItem.setImage(exportImg);
exportItem.setEnabled(false);
exportItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ExportQAResultDialog dialog = new ExportQAResultDialog(getSite().getShell());
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
final String exportFilePath = dialog.getExportFilePath();
if (exportFilePath == null || exportFilePath.isEmpty()) {
MessageDialog.openInformation(getSite().getShell(), Messages.getString("qa.all.dialog.info"), Messages.getString("qa.views.QAResultViewPart.msg.nullFilePath"));
return;
}
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("", 1);
while (!isQAEnd) {
try {
Thread.sleep(500);
} catch (Exception e2) {
logger.error("", e2);
}
if (monitor.isCanceled()) {
return;
}
}
List<QAResultBean> exportDataList = new ArrayList<QAResultBean>();
exportDataList.addAll(dataList);
ExportQAResult export = new ExportQAResult(isMultiFile, exportFilePath);
export.beginExport(dataList, filePathList, monitor);
monitor.done();
}
};
try {
new ProgressMonitorDialog(getSite().getShell()).run(true, true, runnable);
} catch (Exception e1) {
logger.error("", e1);
}
}
}
});
propMenu.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
if (deleteImage != null && !deleteImage.isDisposed()) {
deleteImage.dispose();
}
}
});
}
use of org.eclipse.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.
the class NattableUtil method propagateTranslations.
// /**
// * 获得记忆库更新策略
// * @return ;
// */
// public int getTmxImportStrategy() {
// IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
// return ps.getInt(PreferenceConstants.TM_UPDATE);
// }
/**
* 繁殖翻译 robert
* @param rowIdsMap
* @param monitor
* @return
*/
public IStatus propagateTranslations(Map<String, List<String>> rowIdsMap, IProgressMonitor monitor) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
subMonitor.beginTask(Messages.getString("utils.NattableUtil.task7"), rowIdsMap.keySet().size());
Iterator<Entry<String, List<String>>> it = rowIdsMap.entrySet().iterator();
final XLFHandler handler = xliffEditor.getXLFHandler();
while (it.hasNext()) {
Entry<String, List<String>> entry = it.next();
// 这是源文本,也就是繁殖翻译中的父
String rootRowId = entry.getKey();
// 这是要被繁殖的所有rowIds,其源文与rootRowId的源文一致
final List<String> rowIds = entry.getValue();
// TransUnitBean tu = handler.getTransUnit(rootRowId);
// String tgtContent = tu.getTgtContent();
final String rootTgtPureText = handler.getTUPureTextByRowId(rootRowId, false);
String rootSrcFullText = handler.getTUFullTextByRowId(rootRowId, true);
String rootTgtFullText = handler.getTUFullTextByRowId(rootRowId, false);
for (String rowId : rowIds) {
String temp = rootTgtPureText;
String srcFullText = handler.getTUFullTextByRowId(rowId, true);
if (srcFullText.trim().equals(rootSrcFullText.trim())) {
temp = rootTgtFullText;
} else {
temp = IntelligentTagPrcessor.intelligentAppendTag(srcFullText, rootTgtFullText);
}
handler.changeTgtTextValue(rowId, temp, null, null);
}
// 下面这是处理处于获得焦点状态的文本段。无法繁殖翻译的情况
Display.getDefault().syncExec(new Runnable() {
public void run() {
int focusRowIndex = HsMultiActiveCellEditor.sourceRowIndex;
if (focusRowIndex == -1) {
return;
}
if (!XLIFFEditorImplWithNatTable.getCurrent().isHorizontalLayout()) {
focusRowIndex = VerticalNatTableConfig.getRealRowIndex(focusRowIndex);
}
String focusRowId = handler.getRowId(focusRowIndex);
if (rowIds.contains(focusRowId)) {
HsMultiActiveCellEditor.getTargetStyledEditor().setCanonicalValue(new UpdateDataBean(rootTgtPureText, null, null));
}
}
});
if (subMonitor.isCanceled()) {
return Status.OK_STATUS;
}
subMonitor.worked(1);
}
subMonitor.done();
return Status.OK_STATUS;
}
use of org.eclipse.core.runtime.IProgressMonitor 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.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.
the class NewFolderDialogOfHs method createNewFolder.
/**
* Creates a new folder with the given name and optionally linking to
* the specified link target.
*
* @param folderName name of the new folder
* @param linkTarget name of the link target folder. may be null.
* @return IFolder the new folder
*/
private IFolder createNewFolder(String folderName, final URI linkTarget) {
final IFolder folderHandle = createFolderHandle(folderName);
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
public void execute(IProgressMonitor monitor) throws CoreException {
try {
monitor.beginTask(IDEWorkbenchMessages.NewFolderDialog_progress, 2000);
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
if (linkTarget == null) {
folderHandle.create(false, true, monitor);
} else {
folderHandle.createLink(linkTarget, IResource.ALLOW_MISSING_LOCAL, monitor);
}
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
} finally {
monitor.done();
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(operation);
} catch (InterruptedException exception) {
return null;
} catch (InvocationTargetException exception) {
if (exception.getTargetException() instanceof CoreException) {
ErrorDialog.openError(getShell(), // no special message
IDEWorkbenchMessages.NewFolderDialog_errorTitle, // no special message
null, ((CoreException) exception.getTargetException()).getStatus());
} else {
// CoreExceptions are handled above, but unexpected runtime exceptions and errors may still occur.
IDEWorkbenchPlugin.log(getClass(), "createNewFolder", //$NON-NLS-1$
exception.getTargetException());
MessageDialog.openError(getShell(), IDEWorkbenchMessages.NewFolderDialog_errorTitle, NLS.bind(IDEWorkbenchMessages.NewFolderDialog_internalError, exception.getTargetException().getMessage()));
}
return null;
}
return folderHandle;
}
use of org.eclipse.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.
the class XLFHandler method openFiles.
/**
* 打开多个文件
* @param files
* 文件集合
* @param monitor
* 进度条
* @return ;
*/
public Map<String, Object> openFiles(List<File> files, IProgressMonitor monitor) {
boolean isStarting = PlatformUI.getWorkbench().isStarting();
if (isStarting) {
monitor = null;
} else if (monitor == null) {
monitor = new NullProgressMonitor();
}
try {
if (!isStarting) {
int sumWorkTicks = files.size();
monitor.beginTask(Messages.getString("file.XLFHandler.task1"), sumWorkTicks);
}
IProgressMonitor subMonitor = null;
Iterator<File> it = files.iterator();
while (it.hasNext()) {
File file = it.next();
if (!file.exists()) {
if (!isStarting) {
monitor.worked(1);
}
try {
throw new FileNotFoundException();
} catch (FileNotFoundException e) {
LOGGER.error("", e);
return getErrorResult(MessageFormat.format(Messages.getString("file.XLFHandler.logger1"), file.getAbsolutePath()), null);
}
}
if (!isStarting) {
subMonitor = new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
}
Map<String, Object> midResult = openFile(file, subMonitor);
if (midResult.get(Constant.RETURNVALUE_RESULT).equals(Constant.RETURNVALUE_RESULT_FAILURE)) {
return midResult;
}
}
} finally {
if (!isStarting) {
monitor.done();
}
}
return getSuccessResult();
}
Aggregations