use of org.eclipse.jface.operation.IRunnableWithProgress in project translationstudio8 by heartsome.
the class ApplicationWorkbenchWindowAdvisor method restorEditorHistory.
/**
* 重新恢复产品上次退时出所保存的编辑器,此修复针对 mac 下的 bug 2998 启动:某客户安装的软件只能使用一次. robert 2013-05-21
*/
private void restorEditorHistory() {
// 只针对 mac 下的用户
if (System.getProperty("os.name").indexOf("Mac") == -1) {
return;
}
final WorkbenchPage page = (WorkbenchPage) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("", 10);
String tempEditorHistoryLC = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(Constant.TEMP_EDITOR_HISTORY).toOSString();
File tempEditorHistoryFile = new File(tempEditorHistoryLC);
if (!tempEditorHistoryFile.exists()) {
return;
}
monitor.worked(1);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
VTDGen vg = new VTDGen();
try {
boolean parseResult = vg.parseFile(tempEditorHistoryLC, true);
if (!parseResult) {
return;
}
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
int storeFileSum = 0;
ap.selectXPath("count(/editors/editor)");
storeFileSum = (int) ap.evalXPathToNumber();
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
subMonitor.beginTask("", storeFileSum);
ap.selectXPath("/editors/editor");
String editorId = null;
String localFilePath = null;
boolean activate = false;
IEditorReference activateEditorRefe = null;
IEditorReference firstEditor = null;
IFile curIFile = null;
int index = -1;
while (ap.evalXPath() != -1) {
activate = false;
editorId = null;
localFilePath = null;
if ((index = vn.getAttrVal("id")) != -1) {
editorId = vn.toRawString(index);
}
if ((index = vn.getAttrVal("path")) != -1) {
localFilePath = vn.toRawString(index);
}
if (editorId == null || editorId.trim().length() <= 0 || localFilePath == null || localFilePath.trim().length() <= 0) {
continue;
}
if ((index = vn.getAttrVal("active")) != -1) {
if ("true".equals(vn.toRawString(index))) {
activate = true;
}
}
curIFile = root.getFileForLocation(new Path(localFilePath));
if (!curIFile.exists()) {
subMonitor.worked(1);
continue;
}
if (activate) {
activateEditorRefe = page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
} else {
if (firstEditor == null) {
firstEditor = page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
} else {
page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
}
PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
}
subMonitor.worked(1);
}
PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
if (activateEditorRefe != null) {
if (firstEditor != null) {
page.activate(firstEditor.getEditor(true));
}
page.activate(activateEditorRefe.getEditor(true));
}
subMonitor.done();
monitor.done();
} catch (Exception e) {
LOGGER.error("restore editor file error", e);
}
}
};
try {
new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, runnable);
} catch (Exception e) {
LOGGER.error("restore editor file error", e);
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project translationstudio8 by heartsome.
the class SplitXliffWizard method performFinish.
@Override
public boolean performFinish() {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath containerIPath = root.getLocation().append(splitXliffWizardPage.getTargetXlfPathStr());
IContainer splitXlfsContainer = root.getContainerForLocation(containerIPath);
if (!splitXlfsContainer.exists()) {
// 创建该路径
File file = new File(splitXlfsContainer.getLocation().toOSString());
file.mkdirs();
}
model.setSplitXlfsContainer(splitXlfsContainer);
final IRunnableWithProgress splitProgress = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
// uicallback
canFinish = splitXliff.splitTheXliff(monitor);
}
};
try {
getContainer().run(true, true, splitProgress);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
// 创建项目后刷新资源视图
try {
model.getSplitFile().getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
e.printStackTrace();
}
return canFinish;
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project translationstudio8 by heartsome.
the class PreMachineTransUitls 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 PreMachineTransParameters parameters = new PreMachineTransParameters();
PreMachineTranslationDialog dialog = new PreMachineTranslationDialog(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 {
PreMachineTranslation pt = new PreMachineTranslation(xlfHandler, filesWithOsPath, project, parameters);
try {
final List<PreMachineTranslationCounter> result = pt.executeTranslation(monitor);
Display.getDefault().syncExec(new Runnable() {
public void run() {
//PreMachineTranslationResultDialog dialog = new PreMachineTranslationResultDialog(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);
MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.result.msg"));
} catch (InvocationTargetException e) {
logger.error("", e);
} catch (InterruptedException e) {
logger.error("", e);
}
}
} finally {
HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project translationstudio8 by heartsome.
the class ImportProjectWizardPage method updateProjectsList.
/**
* Update the list of projects based on path. Method declared public only
* for test suite.
*
* @param path
*/
public void updateProjectsList(final String path) {
// on an empty path empty selectedProjects
if (path == null || path.length() == 0) {
setMessage(Messages.getString("wizard.ImportProjectWizardPage.desc"));
selectedProjects = new ProjectRecord[0];
projectsList.refresh(true);
projectsList.setCheckedElements(selectedProjects);
setPageComplete(projectsList.getCheckedElements().length > 0);
lastPath = path;
return;
}
final File directory = new File(path);
long modified = directory.lastModified();
if (path.equals(lastPath) && lastModified == modified && lastCopyFiles == copyFiles) {
// change, no refreshing is required
return;
}
lastPath = path;
lastModified = modified;
lastCopyFiles = copyFiles;
// We can't access the radio button from the inner class so get the
// status beforehand
final boolean dirSelected = false;
try {
getContainer().run(true, true, new IRunnableWithProgress() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.operation.IRunnableWithProgress#run(org
* .eclipse.core.runtime.IProgressMonitor)
*/
@SuppressWarnings("rawtypes")
public void run(IProgressMonitor monitor) {
monitor.beginTask(DataTransferMessages.WizardProjectsImportPage_SearchingMessage, 100);
selectedProjects = new ProjectRecord[0];
Collection files = new ArrayList();
monitor.worked(10);
if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
if (sourceTarFile == null) {
return;
}
structureProvider = new TarLeveledStructureProvider(sourceTarFile);
Object child = structureProvider.getRoot();
if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
return;
}
Iterator filesIterator = files.iterator();
selectedProjects = new ProjectRecord[files.size()];
int index = 0;
monitor.worked(50);
monitor.subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
while (filesIterator.hasNext()) {
selectedProjects[index++] = (ProjectRecord) filesIterator.next();
}
} else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
ZipFile sourceFile = getSpecifiedZipSourceFile(path);
if (sourceFile == null) {
return;
}
structureProvider = new ZipLeveledStructureProvider(sourceFile);
Object child = structureProvider.getRoot();
if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
return;
}
Iterator filesIterator = files.iterator();
selectedProjects = new ProjectRecord[files.size()];
int index = 0;
monitor.worked(50);
monitor.subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
while (filesIterator.hasNext()) {
selectedProjects[index++] = (ProjectRecord) filesIterator.next();
}
} else {
monitor.worked(60);
}
monitor.done();
}
});
} catch (InvocationTargetException e) {
IDEWorkbenchPlugin.log(e.getMessage(), e);
} catch (InterruptedException e) {
// Nothing to do if the user interrupts.
}
projectsList.refresh(true);
ProjectRecord[] projects = getProjectRecords();
boolean displayWarning = false;
for (int i = 0; i < projects.length; i++) {
if (projects[i].hasConflicts) {
displayWarning = true;
projectsList.setGrayed(projects[i], true);
} else {
projectsList.setChecked(projects[i], true);
}
}
if (displayWarning) {
setMessage(DataTransferMessages.WizardProjectsImportPage_projectsInWorkspace, WARNING);
} else {
setMessage("");
}
setPageComplete(projectsList.getCheckedElements().length > 0);
if (selectedProjects.length == 0) {
setMessage(DataTransferMessages.WizardProjectsImportPage_noProjectsToImport, WARNING);
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project translationstudio8 by heartsome.
the class ImportProjectWizardPage2 method updateProjectsList.
public void updateProjectsList(final String path) {
if (path == null || path.length() == 0) {
setMessage(Messages.getString("wizard.ImportProjectWizardPage.desc"));
selectedProjects = new ProjectRecord[0];
setPageComplete(selectElementTree.getCheckedElements().length > 0);
lastPath = path;
return;
}
final File directory = new File(path);
long modified = directory.lastModified();
if (path.equals(lastPath) && lastModified == modified && lastCopyFiles == copyFiles) {
// change, no refreshing is required
return;
}
lastPath = path;
lastModified = modified;
lastCopyFiles = copyFiles;
// We can't access the radio button from the inner class so get the
// status beforehand
final boolean dirSelected = false;
try {
getContainer().run(true, true, new IRunnableWithProgress() {
@SuppressWarnings({ "rawtypes", "restriction" })
public void run(IProgressMonitor monitor) {
monitor.beginTask(Messages.getString("importProjectWizardPage.searchingMessage"), 100);
selectedProjects = new ProjectRecord[0];
Collection files = new ArrayList();
monitor.worked(10);
if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
if (sourceTarFile == null) {
return;
}
structureProvider = new TarLeveledStructureProvider(sourceTarFile);
Object child = structureProvider.getRoot();
if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
return;
}
Iterator filesIterator = files.iterator();
selectedProjects = new ProjectRecord[files.size()];
int index = 0;
monitor.worked(50);
monitor.subTask(Messages.getString("importProjectWizardPage.processingMessage"));
while (filesIterator.hasNext()) {
selectedProjects[index++] = (ProjectRecord) filesIterator.next();
}
} else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
ZipFile sourceFile = getSpecifiedZipSourceFile(path);
if (sourceFile == null) {
return;
}
structureProvider = new ZipLeveledStructureProvider(sourceFile);
Object child = structureProvider.getRoot();
if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
return;
}
Iterator filesIterator = files.iterator();
selectedProjects = new ProjectRecord[files.size()];
int index = 0;
monitor.worked(50);
monitor.subTask(Messages.getString("importProjectWizardPage.processingMessage"));
while (filesIterator.hasNext()) {
selectedProjects[index++] = (ProjectRecord) filesIterator.next();
}
} else {
monitor.worked(60);
}
monitor.done();
}
});
} catch (InvocationTargetException e) {
LOGGER.error(e.getMessage(), e);
} catch (InterruptedException e) {
LOGGER.error(e.getMessage(), e);
}
// 开始处理导入项目中的项目名称不合法的情况
String projectName = "";
StringBuffer errorProjectNameSB = new StringBuffer();
StringBuffer errorCharSB = new StringBuffer();
List<ProjectRecord> tempList = new ArrayList<ProjectRecord>();
boolean isError = false;
for (int i = 0; i < selectedProjects.length; i++) {
projectName = selectedProjects[i].getProjectName();
isError = false;
for (int j = 0; j < Constant.RESOURCE_ERRORCHAR.length; j++) {
if (projectName.indexOf(Constant.RESOURCE_ERRORCHAR[j]) != -1) {
errorCharSB.append(Constant.RESOURCE_ERRORCHAR[j]);
errorProjectNameSB.append(projectName + ", ");
isError = true;
}
}
if (!isError) {
tempList.add(selectedProjects[i]);
}
}
if (errorProjectNameSB.length() > 0) {
final String errorTip = MessageFormat.format(Messages.getString("importProjectWizardPage.projectError"), new Object[] { errorProjectNameSB.toString().substring(0, errorProjectNameSB.toString().length() - 2), errorCharSB.toString() });
Display.getDefault().asyncExec(new Runnable() {
public void run() {
MessageDialog.openWarning(getShell(), Messages.getString("importProject.all.dialog.warning"), errorTip);
}
});
}
selectedProjects = tempList.toArray(new ProjectRecord[tempList.size()]);
setPageComplete(selectElementTree.getCheckedElements().length > 0);
selectElementTree.refresh(true);
}
Aggregations