Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » Determine if file has errors
Determine if file has errors [message #215589] Tue, 17 June 2008 14:22 Go to next message
Philippe Sabourin is currently offline Philippe Sabourin
Messages: 28
Registered: July 2009
Junior Member
Is it possible to determine whether the file you have open in your editor
has errors programatically? What I would like to be able to do is to
disable a page in my editor if I determine that the file being edited has
errors in it (in this case it's an XML file, but I think it could apply to
any type). I am using a StructuredTextEditor and a FormPage as the two
pages for my editor.
Re: Determine if file has errors [message #215607 is a reply to message #215589] Tue, 17 June 2008 17:12 Go to previous messageGo to next message
Lawrence Mandel is currently offline Lawrence Mandel
Messages: 486
Registered: July 2009
Senior Member
>Is it possible to determine whether the file you have open in your editor

>has errors programatically? What I would like to be able to do is to
>disable a page in my editor if I determine that the file being edited has

>errors in it (in this case it's an XML file, but I think it could apply
to
>any type). I am using a StructuredTextEditor and a FormPage as the two
>pages for my editor.

I think two approaches are:

1. Validate the file yourself by calling the WTP validation framework.
This will add some overhead if the file has already been validated.

2. Ask the workbench for the markers set on the file and check for error
markers. I think error markers are typically only set on save so a dirty
editor would not report errors in this case.

There may be a way to ask the structured source editing (SSE) framework
for the errors. Someone on the SSE team should be able to comment further
on this.

Lawrence Mandel
-
Co-author Eclipse Web Tools Platform: Developing Java Web Applications
http://www.eclipsewtp.org
Re: Determine if file has errors [message #215623 is a reply to message #215607] Tue, 17 June 2008 17:43 Go to previous messageGo to next message
Philippe Sabourin is currently offline Philippe Sabourin
Messages: 28
Registered: July 2009
Junior Member
lmandel@ca.ibm.com wrote:

>>Is it possible to determine whether the file you have open in your editor

>>has errors programatically? What I would like to be able to do is to
>>disable a page in my editor if I determine that the file being edited has

>>errors in it (in this case it's an XML file, but I think it could apply
> to
>>any type). I am using a StructuredTextEditor and a FormPage as the two
>>pages for my editor.

> I think two approaches are:

> 1. Validate the file yourself by calling the WTP validation framework.
> This will add some overhead if the file has already been validated.

> 2. Ask the workbench for the markers set on the file and check for error
> markers. I think error markers are typically only set on save so a dirty
> editor would not report errors in this case.

> There may be a way to ask the structured source editing (SSE) framework
> for the errors. Someone on the SSE team should be able to comment further
> on this.

> Lawrence Mandel
> -
> Co-author Eclipse Web Tools Platform: Developing Java Web Applications
> http://www.eclipsewtp.org

Do you have code examples of either of these methods?
Re: Determine if file has errors [message #215740 is a reply to message #215623] Wed, 18 June 2008 14:07 Go to previous messageGo to next message
Lawrence Mandel is currently offline Lawrence Mandel
Messages: 486
Registered: July 2009
Senior Member
1. I haven't tried this with the new (WTP 3.0) WTP validation framework
but it looks like you can do this by calling
ValidationFramework.getDefault().getValidatorsFor(YourIResou rce);
and then iterating through the validators and calling validate on each
one. JavaDoc for the new validation framework is available in the WTP help
centre (Help->Help Contents->Web Tools Platform User
Guide->Reference->Validation Framework API Reference in Eclipse)

2. Take a look at findMarkers on IResource. This should allow you to find
the error markers. You don't need to worry about the depth as you should
have the IFile. You are probably interested in subtypes. For example, if I
remember correctly there is a WSDL error subtype for WSDL errors. For
example, you might want to make a call like

IMarker[] problemMarkers = myIFile.findMarkers(IMarker.PROBLEM, true, 0);

http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/api/org/eclipse/core/resources/IR esource.html


Lawrence Mandel
-
Co-author Eclipse Web Tools Platform: Developing Java Web Applications
http://www.eclipsewtp.org
Re: Determine if file has errors [message #215771 is a reply to message #215740] Wed, 18 June 2008 18:44 Go to previous message
Philippe Sabourin is currently offline Philippe Sabourin
Messages: 28
Registered: July 2009
Junior Member
lmandel@ca.ibm.com wrote:

> 1. I haven't tried this with the new (WTP 3.0) WTP validation framework
> but it looks like you can do this by calling
> ValidationFramework.getDefault().getValidatorsFor(YourIResou rce);
> and then iterating through the validators and calling validate on each
> one. JavaDoc for the new validation framework is available in the WTP help
> centre (Help->Help Contents->Web Tools Platform User
> Guide->Reference->Validation Framework API Reference in Eclipse)

> 2. Take a look at findMarkers on IResource. This should allow you to find
> the error markers. You don't need to worry about the depth as you should
> have the IFile. You are probably interested in subtypes. For example, if I
> remember correctly there is a WSDL error subtype for WSDL errors. For
> example, you might want to make a call like

> IMarker[] problemMarkers = myIFile.findMarkers(IMarker.PROBLEM, true, 0);

>
http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/api/org/eclipse/core/resources/IR esource.html


> Lawrence Mandel
> -
> Co-author Eclipse Web Tools Platform: Developing Java Web Applications
> http://www.eclipsewtp.org

I tried method #2 as suggested by someone else on the rcp newsgroup, but
it didn't work (I think its cause my errors only show up as little red
markers on the right vertical bar, not as problem markers on the left
vertical bar like normal errors). I will give #1 a shot and let you know.

Thanks,
Philippe
Previous Topic:context XML : how to add Resource values?
Next Topic:Adding the RichFaces into the palette of the WTP "Web Page Editor"
Goto Forum:
  


Current Time: Thu Oct 23 19:15:54 GMT 2014

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

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