Skip to content

Commit

Permalink
ValidateAction.handleDiagnostic process the resources of the selection
Browse files Browse the repository at this point in the history
- The action validates a  selection and would be best to delete and
create markers for resources based on that selection

Fixes #45
  • Loading branch information
merks committed Oct 15, 2024
1 parent e810c43 commit 47805ca
Showing 1 changed file with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -335,8 +337,16 @@ protected void handleDiagnostic(final Diagnostic diagnostic)
}

ResourceSet resourceSet = domain.getResourceSet();
Resource resource = eclipseResourcesUtil != null ? resourceSet.getResources().get(0) : null;
if (resource != null)
final Set<Resource> resources = new LinkedHashSet<Resource>();
if (eclipseResourcesUtil != null)
{
for (Object data : diagnostic.getData())
{
resources.add(data instanceof EObject ? ((EObject)data).eResource() : null);
}
resources.remove(null);
}
for (Resource resource : resources)
{
eclipseResourcesUtil.deleteMarkers(resource);
}
Expand Down Expand Up @@ -364,30 +374,35 @@ else if (part instanceof IViewerProvider)
}
}

if (resource != null)
if (eclipseResourcesUtil != null)
{
final Resource finalResource = resource;
IRunnableWithProgress runnable = new IRunnableWithProgress()
{
public void run(IProgressMonitor progressMonitor)
{
int count = 0;
int limit = getLimit();
for (Diagnostic childDiagnostic : diagnostic.getChildren())
public void run(IProgressMonitor progressMonitor)
{
if (progressMonitor.isCanceled() || ++count > limit)
int count = 0;
int limit = getLimit();
for (Diagnostic childDiagnostic : diagnostic.getChildren())
{
return;
if (progressMonitor.isCanceled() || ++count > limit)
{
return;
}
List<?> data = childDiagnostic.getData();
if (!data.isEmpty())
{
Object object = data.get(0);
Resource resource = object instanceof EObject ? ((EObject)object).eResource() : null;
if (resource != null)
{
eclipseResourcesUtil.createMarkers(resource, childDiagnostic);
}
}
}
eclipseResourcesUtil.createMarkers(finalResource, childDiagnostic);
}
}
};
};

if (eclipseResourcesUtil != null)
{
runnable = eclipseResourcesUtil.getWorkspaceModifyOperation(runnable);
}
runnable = eclipseResourcesUtil.getWorkspaceModifyOperation(runnable);

try
{
Expand All @@ -403,10 +418,10 @@ public void run(IProgressMonitor progressMonitor)
{
// Trigger direct updating of decorations, if there are adapters.
//
resource = null;
resources.clear();
}

if (resource == null)
if (resources.isEmpty())
{
// If no markers are produced the decorator won't be able to respond to marker resource deltas, so inform it directly.
//
Expand Down

0 comments on commit 47805ca

Please sign in to comment.