Search in sources :

Example 1 with BatchModification

use of org.eclipse.xtext.ui.editor.model.edit.BatchModification in project xtext-eclipse by eclipse.

the class WorkbenchMarkerResolutionAdapter method run.

@Override
public void run(IMarker[] markers, IProgressMonitor progressMonitor) {
    Map<IProject, List<IMarker>> markersByProject = // 
    Arrays.asList(markers).stream().collect(Collectors.groupingBy(marker -> marker.getResource().getProject()));
    SubMonitor monitor = SubMonitor.convert(progressMonitor);
    monitor.beginTask("Applying resolutions", markersByProject.size());
    markersByProject.forEach((key, value) -> {
        BatchModification batch = batchModificationProvider.get();
        batch.setProject(key);
        List<IBatchableModification> modifications = new ArrayList<>();
        List<IMarker> markersInProject = value;
        markersInProject.forEach(marker -> {
            IssueResolution resolution = resolution(marker);
            if (resolution != null) {
                IModification modification = resolution.getModification();
                if (modification instanceof IBatchableModification) {
                    modifications.add((IBatchableModification) modification);
                }
            }
        });
        cancelIfNeeded(monitor);
        batch.apply(modifications, monitor.newChild(1));
        cancelIfNeeded(monitor);
    });
    monitor.done();
}
Also used : Arrays(java.util.Arrays) IssueUtil(org.eclipse.xtext.ui.util.IssueUtil) WorkbenchMarkerResolution(org.eclipse.ui.views.markers.WorkbenchMarkerResolution) SubMonitor(org.eclipse.core.runtime.SubMonitor) Inject(com.google.inject.Inject) Image(org.eclipse.swt.graphics.Image) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) Logger(org.apache.log4j.Logger) List(java.util.List) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Provider(com.google.inject.Provider) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification) IProject(org.eclipse.core.resources.IProject) Issue(org.eclipse.xtext.validation.Issue) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IBatchableModification(org.eclipse.xtext.ui.editor.model.edit.BatchModification.IBatchableModification) Map(java.util.Map) BatchModification(org.eclipse.xtext.ui.editor.model.edit.BatchModification) Optional(java.util.Optional) IMarker(org.eclipse.core.resources.IMarker) IMarkerResolution(org.eclipse.ui.IMarkerResolution) SubMonitor(org.eclipse.core.runtime.SubMonitor) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) BatchModification(org.eclipse.xtext.ui.editor.model.edit.BatchModification) IBatchableModification(org.eclipse.xtext.ui.editor.model.edit.BatchModification.IBatchableModification) ArrayList(java.util.ArrayList) List(java.util.List) IMarker(org.eclipse.core.resources.IMarker) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification)

Aggregations

Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Logger (org.apache.log4j.Logger)1 IMarker (org.eclipse.core.resources.IMarker)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 Image (org.eclipse.swt.graphics.Image)1 IMarkerResolution (org.eclipse.ui.IMarkerResolution)1 WorkbenchMarkerResolution (org.eclipse.ui.views.markers.WorkbenchMarkerResolution)1 BatchModification (org.eclipse.xtext.ui.editor.model.edit.BatchModification)1