Filter in-memory validator errors with ResourceChangeListener [message #1862652] |
Mon, 18 December 2023 14:18 |
Steve Vestal Messages: 2 Registered: December 2023 |
Junior Member |
|
|
I am developing an Eclipse plugin that extendes the XML editor, with a validator. My problem is that whenever edits are made when a validation error exists, a POST_CHANGE event is sent with an event.getSource() instanceof IWorkspace to my IResourceChangeListener. Edits to the in-memory DOM do not send POST_CHANGE events when there are no validation errors but do send events when validation errors exist. That would be OK except the event provides no way to distinguish that from a file resource save. The getKind() and getFlags() are all the same. Every key-click sends a POST_CHANGE event whenever validation errors are present in the in-memory content. I want to filter those out and only handle these events when the editor saves content to a workspace file.
I created an editor class
```
public class FHOWLEditor extends XMLMultiPageEditorPart implements LocationListener {...
```
where the plugin.xml associates an Eclipse XML validator
```
<extension point="org.eclipse.wst.sse.ui.sourcevalidation">
<validator
scope="total"
class="com.adventiumlabs.indigo.plugin.ui.edit.FHOWLXHTMLValidator"
id="com.adventiumlabs.indigo.plugin.ui.edit.validator">
<contentTypeIdentifier id="com.adventiumlabs.fhowl.fhowl">
<partitionType id="org.eclipse.wst.xml.XML_DEFAULT"/>
<partitionType id="org.eclipse.wst.xml.XML_COMMENT"/>
<partitionType id="org.eclipse.wst.sse.ST_DEFAULT"/>
<partitionType id="org.eclipse.wst.xml.XML_PI"/>
<partitionType id="org.eclipse.wst.html.HTML_DEFAULT"/>
</contentTypeIdentifier>
</validator>
</extension>
```
and my class FHOWLXHTMLValidator provides an XML validator,
```
@SuppressWarnings("restriction")
public class FHOWLXHTMLValidator extends DelegatingSourceValidator {
// For unknown reasons, extending DelegatingSourceValidatorForXML
// will not enable validation against the schema.
// org.eclipse.wst.xml.ui.internal.validation.DelegatingSourceValidatorForXML
private final static String Id = "org.eclipse.wst.xml.core.xml";
private Validator validator = null;
public FHOWLXHTMLValidator() {
super();
}
@Override
protected IValidator getDelegateValidator()
{
Validator v = getValidator();
if (v == null) {
return null;}
return v.asIValidator();
}
private Validator getValidator()
{
if (validator == null) {
validator = ValidationFramework.getDefault().getValidator(Id, null); }
return validator;
}
}
```
The flags and kinds are always the following for both file saves and for key-clicks when validation errors are present.
```
POST_CHANGE source class org.eclipse.core.internal.resources.Workspace
POST_CHANGE resource null
POST_CHANGE delta kind 4
POST_CHANGE delta flags 0
POST_CHANGE delta resource org.eclipse.core.internal.resources.WorkspaceRoot
```
A complicating factor is that I cannot find online Javadoc for the ValidationFramework, and an attempt to install Web Developer Tools and XSL Developer Tools for 2022-03 to try and get the Javadoc resulted in an infinite loop of popups "Requesting Java AST from selection," resulting in an unusable development environment.
[Updated on: Tue, 19 December 2023 16:16] Report message to a moderator
|
|
|
|
Re: Filter in-memory validator errors with ResourceChangeListener [message #1862725 is a reply to message #1862721] |
Fri, 22 December 2023 13:09 |
Steve Vestal Messages: 2 Registered: December 2023 |
Junior Member |
|
|
My problem is that the delta.getKind() is always 4 and the delta.getFlags() is always 0 for both a validation error and a save-file event. It seems odd to me that the resource is null in both cases. The delta resource is WorkspaceRoot in both cases. Is there a validator event handler of some sort that I could intercept or add to make the distinction?
I tried iterating over the all the delta.getAffectedChildren(). Same result, kind always 4 and flags always 0. I noticed that a validation event results in one POST_CHANGE while a file save results in two (at least in some cases).
I am still at 2022-03 in case that makes a difference.
[Updated on: Fri, 22 December 2023 13:36] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03952 seconds