use of org.eclipse.core.runtime.MultiStatus in project che by eclipse.
the class JavaCorrectionProcessor method collectProposals.
public static IStatus collectProposals(IInvocationContext context, /*IAnnotationModel model, */
List<Problem> annotations, boolean addQuickFixes, boolean addQuickAssists, Collection<IJavaCompletionProposal> proposals) {
ArrayList<ProblemLocation> problems = new ArrayList<>();
// collect problem locations and corrections from marker annotations
for (Problem curr : annotations) {
problems.add(new ProblemLocation(curr));
}
// for (int i= 0; i < annotations.length; i++) {
// Annotation curr= annotations[i];
// ProblemLocation problemLocation= null;
// if (curr instanceof IJavaAnnotation) {
// problemLocation= getProblemLocation((IJavaAnnotation) curr, model);
// if (problemLocation != null) {
// problems.add(problemLocation);
// }
// }
//// if (problemLocation == null && addQuickFixes && curr instanceof SimpleMarkerAnnotation) {
//// collectMarkerProposals((SimpleMarkerAnnotation) curr, proposals);
//// }
// }
MultiStatus resStatus = null;
IProblemLocation[] problemLocations = problems.toArray(new IProblemLocation[problems.size()]);
if (addQuickFixes) {
IStatus status = collectCorrections(context, problemLocations, proposals);
if (!status.isOK()) {
resStatus = new MultiStatus(JavaPlugin.ID_PLUGIN, IStatus.ERROR, CorrectionMessages.JavaCorrectionProcessor_error_quickfix_message, null);
resStatus.add(status);
}
}
if (addQuickAssists) {
IStatus status = collectAssists(context, problemLocations, proposals);
if (!status.isOK()) {
if (resStatus == null) {
resStatus = new MultiStatus(JavaPlugin.ID_PLUGIN, IStatus.ERROR, CorrectionMessages.JavaCorrectionProcessor_error_quickassist_message, null);
}
resStatus.add(status);
}
}
if (resStatus != null) {
return resStatus;
}
return Status.OK_STATUS;
}
use of org.eclipse.core.runtime.MultiStatus in project che by eclipse.
the class LocalFile method delete.
public void delete(int options, IProgressMonitor monitor) throws CoreException {
if (monitor == null)
monitor = new NullProgressMonitor();
// monitor = new InfiniteProgress(monitor);
try {
monitor.beginTask(NLS.bind(Messages.deleting, this), 200);
String message = Messages.deleteProblem;
MultiStatus result = new MultiStatus(Policy.PI_FILE_SYSTEM, EFS.ERROR_DELETE, message, null);
internalDelete(file, filePath, result, monitor);
if (!result.isOK())
throw new CoreException(result);
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.MultiStatus in project che by eclipse.
the class LocalFile method internalDelete.
/**
* Deletes the given file recursively, adding failure info to
* the provided status object. The filePath is passed as a parameter
* to optimize java.io.File object creation.
*/
private boolean internalDelete(File target, String pathToDelete, MultiStatus status, IProgressMonitor monitor) {
//first try to delete - this should succeed for files and symbolic links to directories
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
if (target.delete() || !target.exists())
return true;
if (target.isDirectory()) {
monitor.subTask(NLS.bind(Messages.deleting, target));
String[] list = target.list();
if (list == null)
list = EMPTY_STRING_ARRAY;
int parentLength = pathToDelete.length();
boolean failedRecursive = false;
for (int i = 0, imax = list.length; i < imax; i++) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
//optimized creation of child path object
StringBuffer childBuffer = new StringBuffer(parentLength + list[i].length() + 1);
childBuffer.append(pathToDelete);
childBuffer.append(File.separatorChar);
childBuffer.append(list[i]);
String childName = childBuffer.toString();
// try best effort on all children so put logical OR at end
failedRecursive = !internalDelete(new File(childName), childName, status, monitor) || failedRecursive;
monitor.worked(1);
}
try {
// don't try to delete the root if one of the children failed
if (!failedRecursive && target.delete())
return true;
} catch (Exception e) {
// we caught a runtime exception so log it
String message = NLS.bind(Messages.couldnotDelete, target.getAbsolutePath());
status.add(new Status(IStatus.ERROR, Policy.PI_FILE_SYSTEM, EFS.ERROR_DELETE, message, e));
return false;
}
}
//if we got this far, we failed
String message = null;
if (fetchInfo().getAttribute(EFS.ATTRIBUTE_READ_ONLY))
message = NLS.bind(Messages.couldnotDeleteReadOnly, target.getAbsolutePath());
else
message = NLS.bind(Messages.couldnotDelete, target.getAbsolutePath());
status.add(new Status(IStatus.ERROR, Policy.PI_FILE_SYSTEM, EFS.ERROR_DELETE, message, null));
return false;
}
use of org.eclipse.core.runtime.MultiStatus in project translationstudio8 by heartsome.
the class ResourceDropAdapterAssistant method performFileDrop.
/**
* Performs a drop using the FileTransfer transfer type.
*/
private IStatus performFileDrop(final CommonDropAdapter anAdapter, Object data) {
final int currentOperation = anAdapter.getCurrentOperation();
MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 0, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_problemImporting, null);
mergeStatus(problems, validateTarget(anAdapter.getCurrentTarget(), anAdapter.getCurrentTransfer(), currentOperation));
final IContainer target = getActualTarget((IResource) anAdapter.getCurrentTarget());
final String[] names = (String[]) data;
// Run the import operation asynchronously.
// Otherwise the drag source (e.g., Windows Explorer) will be blocked
// while the operation executes. Fixes bug 16478.
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
getShell().forceActive();
new CopyFilesAndFoldersOperation(getShell()).copyOrLinkFiles(names, target, currentOperation);
}
});
return problems;
}
use of org.eclipse.core.runtime.MultiStatus 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;
}
Aggregations