use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.
the class XLIFFEditorImplWithNatTable method openFile.
/**
* 打开文件
* @param files
* @param input
* @throws PartInitException
* ;
*/
private void openFile(List<File> files, IEditorInput input) throws PartInitException {
OpenFile of = new OpenFile(files);
try {
/**
* 异常信息:<br />
* Warning: Detected recursive attempt by part net.heartsome.cat.ts.ui.xliffeditor.nattable.editor to create
* itself (this is probably, but not necessarily, a bug)
*/
if (!PlatformUI.getWorkbench().isStarting()) {
new ProgressMonitorDialog(getSite().getShell()).run(false, true, of);
} else {
of.run(null);
}
// of.run(null);
} catch (InvocationTargetException e) {
throw new PartInitException(e.getMessage(), e);
} catch (InterruptedException e) {
throw new PartInitException(e.getMessage(), e);
}
Map<String, Object> result = of.getOpenFileResult();
if (result == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) result.get(Constant.RETURNVALUE_RESULT)) {
openFileSucceed = false;
Throwable e = (Throwable) result.get(Constant.RETURNVALUE_EXCEPTION);
if (e != null) {
throw new PartInitException(e.getMessage(), e);
}
String msg = (String) result.get(Constant.RETURNVALUE_MSG);
if (msg == null || msg.length() == 0) {
msg = Messages.getString("editor.XLIFFEditorImplWithNatTable.msg4");
}
MessageDialog.openError(getSite().getShell(), Messages.getString("editor.XLIFFEditorImplWithNatTable.msgTitle3"), msg);
// 关闭此编辑器。
close();
} else {
// 成功打开文件时
openFileSucceed = true;
// 判断所打开的文件是否为空,如果为空,进行提示,并关闭编辑器, robert 2013-04-01
int tuSize = handler.countTransUnit();
if (tuSize <= 0) {
MessageDialog.openWarning(getSite().getShell(), Messages.getString("dialog.UpdateNoteDialog.msgTitle1"), Messages.getString("editor.XLIFFEditorImplWithNatTable.cantOpenNullFile"));
close();
}
Image oldTitleImage = titleImage;
if (input != null) {
IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
titleImage = imageDesc != null ? imageDesc.createImage() : null;
}
// 如果是合并打开,设置不一样的标志
if (multiFile) {
setTitleImage(net.heartsome.cat.ts.ui.xliffeditor.nattable.Activator.getImageDescriptor("icons/multiFiles.png").createImage());
} else {
setTitleImage(titleImage);
}
if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
oldTitleImage.dispose();
}
JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
}
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.
the class ExecuteFuzzyTranslationHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IEditorPart editor = window.getActivePage().getActiveEditor();
if (!XLIFF_EDITOR_ID.equals(editor.getSite().getId())) {
return null;
}
final XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) editor;
final NattableUtil util = NattableUtil.getInstance(nattable);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// monitor.beginTask(Messages.getString("translation.ExecuteFuzzyTranslationHandler.task1"), 8);
// 首选获取有译文的trans-unit
monitor.beginTask(Messages.getString("translation.ExecuteFuzzyTranslationHandler.task2"), 10);
XLFHandler handler = nattable.getXLFHandler();
Map<String, List<String>> rowIdMap = new HashMap<String, List<String>>();
rowIdMap = RepeatRowSearcher.getRepeateRowsForFuzzy(handler);
monitor.worked(1);
util.propagateTranslations(rowIdMap, monitor);
monitor.done();
}
};
try {
new ProgressMonitorDialog(nattable.getEditorSite().getShell()).run(true, true, runnable);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
nattable.autoResize();
return null;
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.
the class LicenseManageHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getDefault().getActiveShell());
try {
final String[] str = new String[3];
progress.run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
monitor.beginTask(Messages.getString("license.LicenseManageHandler.progress"), 10);
String[] temp = SystemResourceUtil.load(monitor);
str[0] = temp[0];
str[1] = temp[1];
str[2] = temp[2];
monitor.done();
}
});
SystemResourceUtil.showDialog(str);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
}
return null;
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.
the class PreTransUitls method executeTranslation.
public static void executeTranslation(List<IFile> list, final Shell shell) {
HsMultiActiveCellEditor.commit(true);
try {
if (list.size() == 0) {
MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg1"));
return;
}
List<IFile> lstFiles = new ArrayList<IFile>();
XLFValidator.resetFlag();
for (IFile iFile : list) {
if (!XLFValidator.validateXliffFile(iFile)) {
lstFiles.add(iFile);
}
}
XLFValidator.resetFlag();
list = new ArrayList<IFile>(list);
list.removeAll(lstFiles);
if (list.size() == 0) {
return;
}
final IProject project = list.get(0).getProject();
final List<String> filesWithOsPath = ResourceUtils.IFilesToOsPath(list);
final XLFHandler xlfHandler = new XLFHandler();
Map<String, Object> resultMap = xlfHandler.openFiles(filesWithOsPath);
if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
// 打开文件失败。
MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg2"));
return;
}
Map<String, List<XliffBean>> map = xlfHandler.getXliffInfo();
final PreTransParameters parameters = new PreTransParameters();
PreTranslationDialog dialog = new PreTranslationDialog(shell, map, parameters);
if (dialog.open() == Window.OK) {
if (project == null) {
MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg3"));
return;
}
if (filesWithOsPath == null || filesWithOsPath.size() == 0) {
MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg4"));
return;
}
final List<IFile> lstFile = list;
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
PreTranslation pt = new PreTranslation(xlfHandler, filesWithOsPath, project, parameters);
try {
final List<PreTranslationCounter> result = pt.executeTranslation(monitor);
Display.getDefault().syncExec(new Runnable() {
public void run() {
PreTranslationResultDialog dialog = new PreTranslationResultDialog(shell, result);
dialog.open();
}
});
project.refreshLocal(IResource.DEPTH_INFINITE, null);
result.clear();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (CoreException e) {
logger.error("", e);
e.printStackTrace();
} finally {
pt.clearResources();
}
Display.getDefault().syncExec(new Runnable() {
public void run() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
for (IFile file : lstFile) {
FileEditorInput editorInput = new FileEditorInput(file);
IEditorPart editorPart = page.findEditor(editorInput);
// 选择所有语言
XLFHandler handler = null;
if (editorPart != null && editorPart instanceof IXliffEditor) {
// xliff 文件已用 XLIFF 编辑器打开
IXliffEditor xliffEditor = (IXliffEditor) editorPart;
handler = xliffEditor.getXLFHandler();
handler.resetCache();
VTDGen vg = new VTDGen();
String path = ResourceUtils.iFileToOSPath(file);
if (vg.parseFile(path, true)) {
handler.getVnMap().put(path, vg.getNav());
xliffEditor.refresh();
}
}
}
}
});
}
};
try {
new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, runnable);
} catch (InvocationTargetException e) {
logger.error(Messages.getString("pretranslation.PreTransUitls.logger1"), e);
} catch (InterruptedException e) {
logger.error(Messages.getString("pretranslation.PreTransUitls.logger1"), e);
}
}
} finally {
HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
}
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project translationstudio8 by heartsome.
the class LockRepeatedSegmentHandler method execute.
@Override
public Object execute(final ExecutionEvent event, final List<IFile> iFileList) {
list = iFileList;
tmMatcher = new TmMatcher();
isCancel = false;
continuee = true;
isLocked = false;
if (list == null || list.isEmpty()) {
if (list.size() == 0) {
MessageDialog.openInformation(shell, Messages.getString("translation.LockRepeatedSegmentHandler.msgTitle"), Messages.getString("translation.LockRepeatedSegmentHandler.msg1"));
return null;
}
return null;
}
try {
window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
} catch (ExecutionException e1) {
LOGGER.error("", e1);
e1.printStackTrace();
}
// 首先验证是否是合并打开的文件 --robert
if (isEditor) {
IEditorReference[] editorRefe = window.getActivePage().findEditors(new FileEditorInput(list.get(0)), XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
if (editorRefe.length <= 0) {
return null;
}
nattable = (XLIFFEditorImplWithNatTable) editorRefe[0].getEditor(true);
// 针对合并打开
if (nattable.isMultiFile()) {
list = ResourceUtils.filesToIFiles(nattable.getMultiFileList());
}
}
// 添加验证 peason
List<IFile> lstFiles = new ArrayList<IFile>();
XLFValidator.resetFlag();
for (IFile iFile : list) {
if (!XLFValidator.validateXliffFile(iFile)) {
lstFiles.add(iFile);
}
}
XLFValidator.resetFlag();
if (!(list instanceof ArrayList)) {
list = new ArrayList<IFile>(list);
}
list.removeAll(lstFiles);
if (list.size() == 0) {
return null;
}
CommonFunction.removeRepeateSelect(list);
final LockRepeatedSegmentDialog dialog = new LockRepeatedSegmentDialog(shell, list, Messages.getString("translation.LockRepeatedSegmentHandler.dialog"));
if (dialog.open() == LockRepeatedSegmentDialog.OK) {
isLockInnerRepeatedSegment = dialog.isLockInnerRepeatedSegment();
isLockTM100Segment = dialog.isLockTM100Segment();
isLockTM101Segment = dialog.isLockTM101Segment();
if (!dialog.isLockInnerRepeatedSegment() && !dialog.isLockTM100Segment() && !dialog.isLockTM101Segment()) {
// “锁定内部”、“锁定100%”、“锁定101%”都未选中。
return null;
}
if (!isEditor) {
// 如果针对单个文件, 先验证是否有合并打开的
MultiFilesOper oper = new MultiFilesOper(list.get(0).getProject(), (ArrayList<IFile>) list);
// 如果有合并打开的文件,那么将这种转换成针对编辑器的方式处理
if (oper.validExist()) {
final IFile multiTempIFile = oper.getMultiFilesTempIFile(true);
IEditorReference[] editorRefe = window.getActivePage().findEditors(new FileEditorInput(multiTempIFile), XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
// 如果这几个文件没有合并打开,
if (editorRefe.length > 0) {
nattable = (XLIFFEditorImplWithNatTable) editorRefe[0].getEditor(true);
continuee = false;
}
}
}
// 开始进行处理
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
int totalWork = dialog.isLockInnerRepeatedSegment() ? list.size() : 0;
totalWork = (dialog.isLockTM100Segment() || dialog.isLockTM101Segment()) ? totalWork * 2 : totalWork;
monitor.beginTask(Messages.getString("translation.LockRepeatedSegmentHandler.task1"), totalWork);
// 修改结果显示为是否成功
final LockRepeatedSegmentResultDialog lrsrd = new LockRepeatedSegmentResultDialog(shell, list);
// 是否进行外部匹配
boolean checkTM = false;
curProject = list.get(0).getProject();
// 锁定外部完全匹配与外部上下文匹配
if ((dialog.isLockTM100Segment() || dialog.isLockTM101Segment())) {
// 如果是针对编辑器,那么将里面的文件进行统一处理
if (isEditor) {
LockTMSegment lts = lockTMSegmentOFEditor(list, dialog.isLockTM100Segment(), dialog.isLockTM101Segment(), monitor);
// 用户指定退出操作
if (lts == null && isCancel) {
return;
}
lrsrd.setLockedFullMatchResult(lts.getLockedFullMatchResult());
lrsrd.setLockedContextResult(lts.getLockedContextResult());
lrsrd.setTuNumResult(lts.getTuNumResult());
checkTM = true;
} else {
if (continuee) {
Map<String, Integer> lockedFullMatchResultMap = new HashMap<String, Integer>();
Map<String, Integer> lockedContextMatchResultMap = new HashMap<String, Integer>();
Map<String, Integer> lockedTuNumResultMap = new HashMap<String, Integer>();
for (int i = 0; i < list.size(); i++) {
IFile iFile = list.get(i);
LockTMSegment lts = lockTMSegment(Arrays.asList(iFile), dialog.isLockTM100Segment(), dialog.isLockTM101Segment(), monitor);
if (lts == null && isCancel) {
return;
}
// 返回的为空,是解析异常的文件被删除了。
if (lts != null) {
lockedFullMatchResultMap.putAll(lts.getLockedFullMatchResult());
lockedContextMatchResultMap.putAll(lts.getLockedContextResult());
lockedTuNumResultMap.putAll(lts.getTuNumResult());
} else {
i--;
}
}
lrsrd.setLockedFullMatchResult(lockedFullMatchResultMap);
lrsrd.setLockedContextResult(lockedContextMatchResultMap);
lrsrd.setTuNumResult(lockedTuNumResultMap);
checkTM = true;
} else {
LockTMSegment lts = lockTMSegmentOFEditor(list, dialog.isLockTM100Segment(), dialog.isLockTM101Segment(), monitor);
if (lts == null && isCancel) {
return;
}
lrsrd.setLockedFullMatchResult(lts.getLockedFullMatchResult());
lrsrd.setLockedContextResult(lts.getLockedContextResult());
lrsrd.setTuNumResult(lts.getTuNumResult());
checkTM = true;
}
}
}
// 锁定内部重复
if (dialog.isLockInnerRepeatedSegment()) {
SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, list.size(), SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
HashMap<String, Integer> lockedInnerRepeatedResault = new HashMap<String, Integer>();
HashMap<String, Integer> tuNumResult = null;
if (!checkTM) {
tuNumResult = new HashMap<String, Integer>();
}
Map<String, int[]> resMap = lockInnerRepeatedSegment(list, subMonitor, checkTM);
for (IFile iFile : list) {
String filePath = ResourceUtils.iFileToOSPath(iFile);
int[] res = resMap.get(filePath);
if (!checkTM) {
int countTU = res[0];
tuNumResult.put(filePath, countTU);
}
int countLockedInnerRepeatedSegment = res[1];
lockedInnerRepeatedResault.put(filePath, countLockedInnerRepeatedSegment);
}
lrsrd.setLockedInnerRepeatedResault(lockedInnerRepeatedResault);
if (!checkTM) {
lrsrd.setTuNumResult(tuNumResult);
}
}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
xliffEditor.reloadXliff();
}
// lrsrd.open();
if (hasWrongResults(list, lrsrd)) {
MessageDialog.openInformation(shell, Messages.getString("translation.LockRepeatedSegmentHandler.msgTitle"), Messages.getString("dialog.LockRepeatedSegmentResultDialog.locksuccesful"));
} else {
MessageDialog.openInformation(shell, Messages.getString("translation.LockRepeatedSegmentHandler.msgTitle"), Messages.getString("dialog.LockRepeatedSegmentResultDialog.locksuccesful"));
}
lrsrd.close();
HsMultiActiveCellEditor.refrushCellsEditAbility();
}
});
} finally {
monitor.done();
}
}
};
try {
new ProgressMonitorDialog(shell).run(true, true, runnable);
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
Aggregations