use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.
the class SelfEncapsulateFieldRefactoring method checkFinalConditions.
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
pm.beginTask(NO_NAME, 12);
pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_checking_preconditions);
RefactoringStatus result = new RefactoringStatus();
fRewriter = ASTRewrite.create(fRoot.getAST());
fChangeManager.clear();
boolean usingLocalGetter = isUsingLocalGetter();
boolean usingLocalSetter = isUsingLocalSetter();
result.merge(checkMethodNames(usingLocalGetter, usingLocalSetter));
pm.worked(1);
if (result.hasFatalError())
return result;
pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_searching_for_cunits);
final SubProgressMonitor subPm = new SubProgressMonitor(pm, 5);
ICompilationUnit[] affectedCUs = RefactoringSearchEngine.findAffectedCompilationUnits(SearchPattern.createPattern(fField, IJavaSearchConstants.REFERENCES), RefactoringScopeFactory.create(fField, fConsiderVisibility), subPm, result, true);
checkInHierarchy(result, usingLocalGetter, usingLocalSetter);
if (result.hasFatalError())
return result;
pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_analyzing);
IProgressMonitor sub = new SubProgressMonitor(pm, 5);
sub.beginTask(NO_NAME, affectedCUs.length);
IVariableBinding fieldIdentifier = fFieldDeclaration.resolveBinding();
ITypeBinding declaringClass = ((AbstractTypeDeclaration) ASTNodes.getParent(fFieldDeclaration, AbstractTypeDeclaration.class)).resolveBinding();
List<TextEditGroup> ownerDescriptions = new ArrayList<TextEditGroup>();
ICompilationUnit owner = fField.getCompilationUnit();
fImportRewrite = StubUtility.createImportRewrite(fRoot, true);
for (int i = 0; i < affectedCUs.length; i++) {
ICompilationUnit unit = affectedCUs[i];
sub.subTask(BasicElementLabels.getFileName(unit));
CompilationUnit root = null;
ASTRewrite rewriter = null;
ImportRewrite importRewrite;
List<TextEditGroup> descriptions;
if (owner.equals(unit)) {
root = fRoot;
rewriter = fRewriter;
importRewrite = fImportRewrite;
descriptions = ownerDescriptions;
} else {
root = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(unit, true);
rewriter = ASTRewrite.create(root.getAST());
descriptions = new ArrayList<TextEditGroup>();
importRewrite = StubUtility.createImportRewrite(root, true);
}
checkCompileErrors(result, root, unit);
AccessAnalyzer analyzer = new AccessAnalyzer(this, unit, fieldIdentifier, declaringClass, rewriter, importRewrite);
root.accept(analyzer);
result.merge(analyzer.getStatus());
if (!fSetterMustReturnValue)
fSetterMustReturnValue = analyzer.getSetterMustReturnValue();
if (result.hasFatalError()) {
fChangeManager.clear();
return result;
}
descriptions.addAll(analyzer.getGroupDescriptions());
if (!owner.equals(unit))
createEdits(unit, rewriter, descriptions, importRewrite);
sub.worked(1);
if (pm.isCanceled())
throw new OperationCanceledException();
}
ownerDescriptions.addAll(addGetterSetterChanges(fRoot, fRewriter, owner.findRecommendedLineSeparator(), usingLocalSetter, usingLocalGetter));
createEdits(owner, fRewriter, ownerDescriptions, fImportRewrite);
sub.done();
IFile[] filesToBeModified = ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits());
result.merge(Checks.validateModifiesFiles(filesToBeModified, getValidationContext()));
if (result.hasFatalError())
return result;
ResourceChangeChecker.checkFilesToBeChanged(filesToBeModified, new SubProgressMonitor(pm, 1));
return result;
}
use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.
the class MemberVisibilityAdjustor method rewriteVisibility.
/**
* Rewrites the computed adjustments.
*
* @param monitor the progress monitor to use
* @throws JavaModelException if an error occurs during search
*/
public final void rewriteVisibility(final IProgressMonitor monitor) throws JavaModelException {
try {
//$NON-NLS-1$
monitor.beginTask("", fAdjustments.keySet().size());
monitor.setTaskName(RefactoringCoreMessages.MemberVisibilityAdjustor_adjusting);
IMember member = null;
IVisibilityAdjustment adjustment = null;
for (final Iterator<IMember> iterator = fAdjustments.keySet().iterator(); iterator.hasNext(); ) {
member = iterator.next();
adjustment = fAdjustments.get(member);
if (adjustment != null)
adjustment.rewriteVisibility(this, new SubProgressMonitor(monitor, 1));
if (monitor.isCanceled())
throw new OperationCanceledException();
}
} finally {
fTypeHierarchies.clear();
monitor.done();
}
}
use of org.eclipse.core.runtime.OperationCanceledException in project translationstudio8 by heartsome.
the class ResourceDropAdapterAssistant method performResourceMove.
/**
* Performs a resource move
*/
private IStatus performResourceMove(CommonDropAdapter dropAdapter, IResource[] sources) {
MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_problemsMoving, null);
mergeStatus(problems, validateTarget(dropAdapter.getCurrentTarget(), dropAdapter.getCurrentTransfer(), dropAdapter.getCurrentOperation()));
IContainer target = getActualTarget((IResource) dropAdapter.getCurrentTarget());
boolean shouldLinkAutomatically = false;
if (target.isVirtual()) {
shouldLinkAutomatically = true;
for (int i = 0; i < sources.length; i++) {
if (sources[i].isVirtual() || sources[i].isLinked()) {
shouldLinkAutomatically = false;
break;
}
}
}
if (shouldLinkAutomatically) {
CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(getShell());
operation.setCreateLinks(true);
operation.copyResources(sources, target);
} else {
ReadOnlyStateChecker checker = new ReadOnlyStateChecker(getShell(), WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_MoveResourceAction_title, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_MoveResourceAction_checkMoveMessage);
sources = checker.checkReadOnlyResources(sources);
try {
RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(MoveResourcesDescriptor.ID);
MoveResourcesDescriptor descriptor = (MoveResourcesDescriptor) contribution.createDescriptor();
descriptor.setResourcesToMove(sources);
descriptor.setDestination(target);
refactoringStatus = new RefactoringStatus();
final Refactoring refactoring = descriptor.createRefactoring(refactoringStatus);
returnStatus = null;
IRunnableWithProgress checkOp = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
try {
refactoringStatus = refactoring.checkAllConditions(monitor);
} catch (CoreException ex) {
returnStatus = WorkbenchNavigatorPlugin.createErrorStatus(0, ex.getLocalizedMessage(), ex);
}
}
};
if (returnStatus != null)
return returnStatus;
try {
PlatformUI.getWorkbench().getProgressService().run(false, false, checkOp);
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
} catch (InvocationTargetException e) {
return WorkbenchNavigatorPlugin.createErrorStatus(0, e.getLocalizedMessage(), e);
}
if (refactoringStatus.hasEntries()) {
RefactoringStatusEntry[] entries = refactoringStatus.getEntries();
StringBuffer message = new StringBuffer();
int severity = 0;
for (RefactoringStatusEntry refactoringStatusEntry : entries) {
if (refactoringStatusEntry.getSeverity() > severity) {
severity = refactoringStatusEntry.getSeverity();
message.replace(0, message.length(), refactoringStatusEntry.getMessage());
} else if (refactoringStatusEntry.getSeverity() == severity) {
message.append("\n\n").append(refactoringStatusEntry.getMessage());
}
}
if (severity == RefactoringStatus.INFO) {
MessageDialog.openInformation(getShell(), WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_MoveResourceAction_title, message.toString());
} else if (severity == RefactoringStatus.WARNING) {
boolean result = MessageDialog.openConfirm(getShell(), WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_MoveResourceAction_title, message.toString());
if (!result) {
return Status.CANCEL_STATUS;
}
} else if (severity == RefactoringStatus.ERROR || severity == RefactoringStatus.FATAL) {
MessageDialog.openError(getShell(), WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_MoveResourceAction_title, message.toString());
return Status.CANCEL_STATUS;
} else {
}
/**
* Weachy:
* RefactoringUI 类需引入 org.eclipse.ltk.ui.refactoring 插件,
* 而 org.eclipse.ltk.ui.refactoring 插件会引入
* org.eclipse.compare、org.eclipse.team.core、org.eclipse.team.ui
* 三个插件。会导致在导航视图、首选项等出现无用的功能项。因此注释以下4行代码。
*/
// Dialog dialog= RefactoringUI.createLightWeightStatusDialog(refactoringStatus, getShell(), WorkbenchNavigatorMessages.MoveResourceAction_title);
// int result = dialog.open();
// if (result != IStatus.OK)
// return Status.CANCEL_STATUS;
}
final PerformRefactoringOperation op = new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS);
final IWorkspaceRunnable r = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
op.run(monitor);
}
};
returnStatus = null;
IRunnableWithProgress refactorOp = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
try {
ResourcesPlugin.getWorkspace().run(r, ResourcesPlugin.getWorkspace().getRoot(), IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException ex) {
returnStatus = WorkbenchNavigatorPlugin.createErrorStatus(0, ex.getLocalizedMessage(), ex);
}
}
};
if (returnStatus != null)
return returnStatus;
try {
PlatformUI.getWorkbench().getProgressService().run(false, false, refactorOp);
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
} catch (InvocationTargetException e) {
return WorkbenchNavigatorPlugin.createErrorStatus(0, e.getLocalizedMessage(), e);
}
} catch (CoreException ex) {
return WorkbenchNavigatorPlugin.createErrorStatus(0, ex.getLocalizedMessage(), ex);
} catch (OperationCanceledException e) {
}
}
return problems;
}
use of org.eclipse.core.runtime.OperationCanceledException in project translationstudio8 by heartsome.
the class NewTermDbBaseInfoPage method checkDb4Server.
/**
* 检查服务器型数据库
* @return ;
*/
public String checkDb4Server(IProgressMonitor monitor) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("", 3);
monitor.setTaskName(Messages.getString("wizard.NewTermDbBaseInfoPage.task1"));
String message = null;
if (!dbOp.checkDbConnection()) {
message = Messages.getString("wizard.NewTermDbBaseInfoPage.msg7");
return message;
}
if (!dbOp.checkSysDb()) {
// 检查是否创建了系统库,没创建则创建
try {
dbOp.createSysDb();
} catch (Exception e) {
logger.error(Messages.getString("wizard.NewTermDbBaseInfoPage.logger1"));
message = Messages.getString("wizard.NewTermDbBaseInfoPage.msg8");
return message;
}
}
monitor.worked(1);
if (dbOp.checkDbExistOnServer()) {
message = Messages.getString("wizard.NewTermDbBaseInfoPage.msg9") + dbOp.getMetaData().getDatabaseName();
return message;
}
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
monitor.done();
return message;
}
use of org.eclipse.core.runtime.OperationCanceledException in project translationstudio8 by heartsome.
the class ExportDocxDialog method okPressed.
@Override
protected void okPressed() {
if (xliffPathTxt.getText() == null || xliffPathTxt.getText().trim().equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.ok.msg0"));
return;
}
String docxPath = docxPathTxt.getText().trim();
if (docxPath == null || docxPath.length() <= 0) {
MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.ok.msg3"));
return;
}
IDialogSettings dialogSettings = Activator.getDefault().getDialogSettings();
dialogSettings.put(STORE_DOCX_PATH, docxPath);
XLFValidator.resetFlag();
if (!XLFValidator.validateXliffFile(strXliffFullPath)) {
return;
}
XLFValidator.resetFlag();
// 补全 docx 路径
docxPath = docxPath + File.separator + new File(strXliffFullPath).getName() + ".docx";
if (new File(docxPath).exists()) {
boolean confirm = MessageDialog.openConfirm(getShell(), Messages.getString("all.dialog.confirm"), MessageFormat.format(Messages.getString("ExportDocxDialog.ok.msg5"), "DOCX", docxPath));
if (confirm) {
new File(docxPath).delete();
} else {
return;
}
}
final boolean commentSelection = commentBtn.getSelection();
final boolean statusSelection = statusBtn.getSelection();
// 设置查询每个 tu 的条件,比如排除或者 仅导出
String expandXpath = "";
if (excludeBtn.getSelection()) {
if (excludeLockedBtn.getSelection()) {
expandXpath += " and not(@translate='no')";
}
if (exclude101Btn.getSelection()) {
expandXpath += " and not(target[@hs:quality='101'])";
}
if (exclude100Btn.getSelection()) {
expandXpath += " and not(target[@hs:quality='100'])";
}
} else if (onlyExportBtn.getSelection()) {
if (onlyExportNoteBtn.getSelection()) {
expandXpath += " and note/text()!=''";
} else if (onlyExportReviewBtn.getSelection()) {
expandXpath += " and @hs:needs-review='yes'";
}
}
final String finalExpandXpath = expandXpath;
// 这里开始调用导出的方法
final String finalDocxPath = docxPath;
Job job = new Job(Messages.getString("ExportDocxDialog.ok.monitor.title")) {
protected IStatus run(final IProgressMonitor monitor) {
try {
// 解析文件花一格。读取 xliff 数据花 1 格,导出花 18 格。
monitor.beginTask(Messages.getString("ExportDocxDialog.ok.monitor.msg0"), 20);
beginExport(monitor, finalDocxPath, commentSelection, statusSelection, finalExpandXpath);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.ok.msg4"));
}
});
monitor.done();
} catch (OperationCanceledException e) {
// do nothing
} catch (final Exception e) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(getShell(), Messages.getString("all.dialog.error"), Messages.getString("ExportDocxDialog.ok.exportError") + "\n" + e.getMessage());
}
});
LOGGER.error("Export xliff to MS WORD error\n" + e.getMessage(), e);
}
return Status.OK_STATUS;
}
};
// 当程序退出时,检测当前 job 是否正常关闭
CommonFunction.jobCantCancelTip(job);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void running(IJobChangeEvent event) {
ProgressIndicatorManager.displayProgressIndicator();
super.running(event);
}
@Override
public void done(IJobChangeEvent event) {
ProgressIndicatorManager.hideProgressIndicator();
super.done(event);
}
});
job.setUser(true);
job.schedule();
close();
}
Aggregations