Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Eclipse Web Tools Platform Project (WTP) » Filter in-memory validator errors with ResourceChangeListener(How to intercept a validator error event notification in either a handler or the change listener event.)
Filter in-memory validator errors with ResourceChangeListener [message #1862652] Mon, 18 December 2023 14:18 Go to next message
Steve Vestal is currently offline Steve VestalFriend
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 #1862721 is a reply to message #1862652] Fri, 22 December 2023 09:21 Go to previous messageGo to next message
Reaha Taul is currently offline Reaha TaulFriend
Messages: 1
Registered: October 2023
Junior Member
The issue you're encountering stems from the fact that both in-memory DOM edits and file saves trigger the same POST_CHANGE event with the same event data. This makes it difficult to differentiate between the two scenarios and handle them appropriately.

To effectively distinguish between in-memory edits and file saves, you need to access the event's delta object, which provides additional information about the specific change being made. The delta object contains a flags field that indicates whether the change was made to the workspace file or to the in-memory DOM.

Here's how you can access and analyze the delta object to identify file saves:

Retrieve the delta object: In your IResourceChangeListener implementation, extract the delta object from the IResourceChangeEvent event using the getDelta() method.

Check the flags field: Examine the delta object's flags field. If the flags are 0, it indicates that the change was made to the in-memory DOM. If the flags are non-zero, it implies that the change was made to the workspace file.

Handle file saves accordingly: If the flags are non-zero, it means the change was triggered by a file save. You can then perform any necessary actions specific to file saves, such as saving the updated XML file or triggering additional validation checks.

This approach allows you to filter out in-memory edits and focus on handling events related to file saves, ensuring that your plugin behaves as intended when the XML editor saves the file.
Re: Filter in-memory validator errors with ResourceChangeListener [message #1862725 is a reply to message #1862721] Fri, 22 December 2023 13:09 Go to previous messageGo to next message
Steve Vestal is currently offline Steve VestalFriend
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

Re: Filter in-memory validator errors with ResourceChangeListener [message #1863383 is a reply to message #1862725] Tue, 30 January 2024 12:18 Go to previous messageGo to next message
Pomary Linea is currently offline Pomary LineaFriend
Messages: 1
Registered: October 2023
Junior Member
Here's a response incorporating insights and suggestions:

Understanding the Issue:

Undesired POST_CHANGE Events: Edits triggering validation errors are generating unnecessary events, even when the file isn't saved.
Missing Javadoc: Lack of accessible ValidationFramework documentation makes it harder to troubleshoot.
Development Environment Issues: The "Requesting Java AST from selection" loop hinders progress.
Additional Considerations:

Validator Configuration: Review your validator's configuration to ensure it's not triggering validation too aggressively.
Alternative Validation Approaches: If the issue persists, consider alternative validation methods, such as manual triggering or decoupling validation from resource change events.
Re: Filter in-memory validator errors with ResourceChangeListener [message #1864521 is a reply to message #1863383] Thu, 21 March 2024 10:22 Go to previous message
Ziangze Cho is currently offline Ziangze ChoFriend
Messages: 2
Registered: January 2024
Junior Member
Here's a response combining potential solutions and addressing the Javadoc issue:

Understanding the Problem:

Your in-memory edits trigger POST_CHANGE events even without file saves when validation errors exist.
These events lack clear distinction from actual file saves, making filtering difficult.
Potential Solutions:

Leverage Dirty State:

Check the editor's dirty state (isDirty()) before processing the POST_CHANGE event in your IResourceChangeListener.
If the editor is clean (no unsaved changes), the event likely comes from in-memory edits and can be ignored.
Custom Event from Editor:

Modify your FHOWLEditor class to emit a custom event upon saving the file.
In your IResourceChangeListener, listen for this custom event instead of relying solely on POST_CHANGE.
Validation Event (if available):

Explore the Validation Framework (might require digging into source code).
If it provides a specific event upon validation errors, use it to differentiate from file saves.
Previous Topic:Eclipse won't syntax highlight JavaScript files
Next Topic:Javascript syntax coloring
Goto Forum:
  


Current Time: Mon May 06 07:48:32 GMT 2024

Powered by FUDForum. Page generated in 0.03013 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top