use of org.eclipse.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.
the class LockRepeatedSegmentHandler method lockTMSegmentOFEditor.
/**
* 专门处理以 nattble 形式打开的文件
* @param iFileList
* @param isLockTM100Segment
* @param isLockTM101Segment
* @param monitor
* @return ;
*/
private LockTMSegment lockTMSegmentOFEditor(List<IFile> iFileList, boolean isLockTM100Segment, boolean isLockTM101Segment, IProgressMonitor monitor) {
XLFHandler xlfHandler = nattable.getXLFHandler();
SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, iFileList.size(), SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
subMonitor.beginTask("", 10);
subMonitor.setTaskName(Messages.getString("translation.LockRepeatedSegmentHandler.task2"));
// 解析文件,占 1/10,这里是直接获取编辑器的XLFHandler,故不需解析
if (!monitorWork(subMonitor, 1)) {
return null;
}
List<String> filesPath = ResourceUtils.IFilesToOsPath(iFileList);
LockTMSegment lts = new LockTMSegment(xlfHandler, tmMatcher, filesPath, curProject);
lts.setLockedContextMatch(isLockTM101Segment);
lts.setLockedFullMatch(isLockTM100Segment);
// 查记忆库并锁定,占剩下的 9/10。
IProgressMonitor subSubMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
if (!lts.executeTranslation(subSubMonitor)) {
subSubMonitor.done();
subMonitor.done();
isCancel = true;
return null;
}
subSubMonitor.done();
subMonitor.done();
if (nattable != null) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
nattable.getTable().redraw();
}
});
}
Map<String, List<String>> needLockRowIdMap = lts.getNeedLockRowIdMap();
if (needLockRowIdMap.size() > 0) {
lockTU(xlfHandler, needLockRowIdMap);
}
return lts;
}
use of org.eclipse.core.runtime.IProgressMonitor in project mechanoid by robotoworks.
the class NewMechanoidElementWizard method performFinish.
@Override
public boolean performFinish() {
final IPath newFilePath = createNewResourceFilePath();
onBeforeCreateElementResource();
WorkspaceModifyDelegatingOperation op = new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
try {
mNewResource = createElementResource(monitor, newFilePath);
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
});
try {
getContainer().run(true, true, op);
selectAndReveal(mNewResource);
openResource(mNewResource);
} catch (InvocationTargetException e) {
Throwable realException = e.getTargetException();
MessageDialog.openError(getShell(), Messages.NewMechanoidElementWizard_Dialog_CreateResourceError_Title, realException.getMessage());
return false;
} catch (InterruptedException e) {
return false;
}
return true;
}
use of org.eclipse.core.runtime.IProgressMonitor in project flux by eclipse.
the class AuthFailureReporter method newValue.
@Override
public void newValue(Observable<ConnectionStatus> o, ConnectionStatus v) {
if (v.isAuthFailure()) {
UIJob job = new UIJob("Flux Error Reporter") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
MessageDialog.openError(null, "Flux Connection Failed", "Flux Web Socket handshake failed. Most likely this means " + "your Flux credentials are invalid.");
return Status.OK_STATUS;
}
};
job.schedule();
//We only report this error once.
// since this error is all we handle... there's no point to continue listening
} else if (v.isConnected()) {
//This means credentials must be valid and this listener now useless.
dispose();
}
}
use of org.eclipse.core.runtime.IProgressMonitor in project flux by eclipse.
the class LiveEditConnector method dispose.
public void dispose() {
this.liveEditCoordinator.removeLiveEditConnector(liveEditConnector);
this.repository.removeRepositoryListener(repositoryListener);
FileBuffers.getTextFileBufferManager().removeFileBufferListener(fileBufferListener);
ResourcesPlugin.getWorkspace().removeResourceChangeListener(workspaceListener);
WorkbenchJob jw = new WorkbenchJob("Removing listener") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
window.getActivePage().removePartListener(partListener);
}
return Status.OK_STATUS;
}
};
jw.setSystem(true);
jw.schedule();
for (IDocument document : documentMappings.values()) {
if (document != null) {
document.removeDocumentListener(documentListener);
}
}
resourceMappings.clear();
documentMappings.clear();
}
use of org.eclipse.core.runtime.IProgressMonitor in project che by eclipse.
the class ReplaceInvocationsRefactoring method checkFinalConditions.
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 20);
fChangeManager = new TextChangeManager();
RefactoringStatus result = new RefactoringStatus();
fSourceProvider = resolveSourceProvider(fMethodBinding, result);
if (result.hasFatalError())
return result;
result.merge(fSourceProvider.checkActivation());
if (result.hasFatalError())
return result;
fSourceProvider.initialize();
fTargetProvider.initialize();
pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_searching);
RefactoringStatus searchStatus = new RefactoringStatus();
String binaryRefsDescription = Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description, BasicElementLabels.getJavaElementName(fSourceProvider.getMethodName()));
ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
ICompilationUnit[] units = fTargetProvider.getAffectedCompilationUnits(searchStatus, binaryRefs, new SubProgressMonitor(pm, 1));
binaryRefs.addErrorIfNecessary(searchStatus);
if (searchStatus.hasFatalError()) {
result.merge(searchStatus);
return result;
}
IFile[] filesToBeModified = getFilesToBeModified(units);
result.merge(Checks.validateModifiesFiles(filesToBeModified, getValidationContext()));
if (result.hasFatalError())
return result;
result.merge(ResourceChangeChecker.checkFilesToBeChanged(filesToBeModified, new SubProgressMonitor(pm, 1)));
checkOverridden(result, new SubProgressMonitor(pm, 4));
IProgressMonitor sub = new SubProgressMonitor(pm, 15);
//$NON-NLS-1$
sub.beginTask("", units.length * 3);
for (int c = 0; c < units.length; c++) {
ICompilationUnit unit = units[c];
sub.subTask(Messages.format(RefactoringCoreMessages.InlineMethodRefactoring_processing, BasicElementLabels.getFileName(unit)));
CallInliner inliner = null;
try {
boolean added = false;
MultiTextEdit root = new MultiTextEdit();
CompilationUnitChange change = (CompilationUnitChange) fChangeManager.get(unit);
change.setEdit(root);
BodyDeclaration[] bodies = fTargetProvider.getAffectedBodyDeclarations(unit, new SubProgressMonitor(pm, 1));
if (bodies.length == 0)
continue;
inliner = new CallInliner(unit, (CompilationUnit) bodies[0].getRoot(), fSourceProvider);
for (int b = 0; b < bodies.length; b++) {
BodyDeclaration body = bodies[b];
inliner.initialize(body);
RefactoringStatus nestedInvocations = new RefactoringStatus();
ASTNode[] invocations = removeNestedCalls(nestedInvocations, unit, fTargetProvider.getInvocations(body, new SubProgressMonitor(sub, 2)));
for (int i = 0; i < invocations.length; i++) {
ASTNode invocation = invocations[i];
result.merge(inliner.initialize(invocation, fTargetProvider.getStatusSeverity()));
if (result.hasFatalError())
break;
if (result.getSeverity() < fTargetProvider.getStatusSeverity()) {
added = true;
TextEditGroup group = new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_inline);
change.addTextEditGroup(group);
result.merge(inliner.perform(group));
}
}
// do this after we have inlined the method calls. We still want
// to generate the modifications.
result.merge(nestedInvocations);
}
if (!added) {
fChangeManager.remove(unit);
} else {
root.addChild(inliner.getModifications());
ImportRewrite rewrite = inliner.getImportEdit();
if (rewrite.hasRecordedChanges()) {
TextEdit edit = rewrite.rewriteImports(null);
if (edit instanceof MultiTextEdit ? ((MultiTextEdit) edit).getChildrenSize() > 0 : true) {
root.addChild(edit);
change.addTextEditGroup(new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_import, new TextEdit[] { edit }));
}
}
}
} finally {
if (inliner != null)
inliner.dispose();
}
sub.worked(1);
if (sub.isCanceled())
throw new OperationCanceledException();
}
result.merge(searchStatus);
sub.done();
pm.done();
return result;
}
Aggregations