Search in sources :

Example 71 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project bndtools by bndtools.

the class BaselineErrorHandler method getResolutions.

@Override
public List<IMarkerResolution> getResolutions(IMarker marker) {
    List<IMarkerResolution> result = new LinkedList<IMarkerResolution>();
    final String suggestedVersion = marker.getAttribute(PROP_SUGGESTED_VERSION, null);
    if (suggestedVersion != null) {
        result.add(new IMarkerResolution() {

            @Override
            public void run(IMarker marker) {
                final IFile file = (IFile) marker.getResource();
                final IWorkspace workspace = file.getWorkspace();
                try {
                    workspace.run(new IWorkspaceRunnable() {

                        @Override
                        public void run(IProgressMonitor monitor) throws CoreException {
                            String input = "version " + suggestedVersion;
                            ByteArrayInputStream stream = new ByteArrayInputStream(input.getBytes());
                            file.setContents(stream, false, true, monitor);
                        }
                    }, null);
                } catch (CoreException e) {
                    logger.logError("Error applying baseline version quickfix.", e);
                }
            }

            @Override
            public String getLabel() {
                return "Change package version to " + suggestedVersion;
            }
        });
    }
    return result;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IMarkerResolution(org.eclipse.ui.IMarkerResolution) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkspace(org.eclipse.core.resources.IWorkspace) IMarker(org.eclipse.core.resources.IMarker) LinkedList(java.util.LinkedList)

Aggregations

IWorkspace (org.eclipse.core.resources.IWorkspace)71 CoreException (org.eclipse.core.runtime.CoreException)41 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)30 IProject (org.eclipse.core.resources.IProject)29 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)24 PersistenceException (org.talend.commons.exception.PersistenceException)23 IPath (org.eclipse.core.runtime.IPath)19 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 IStatus (org.eclipse.core.runtime.IStatus)17 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)15 IFile (org.eclipse.core.resources.IFile)14 ArrayList (java.util.ArrayList)11 Status (org.eclipse.core.runtime.Status)11 Path (org.eclipse.core.runtime.Path)10 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)10 File (java.io.File)9 IOException (java.io.IOException)9 IResource (org.eclipse.core.resources.IResource)9 IProjectDescription (org.eclipse.core.resources.IProjectDescription)8