public void updateAnnotations()
{
LdifFile model = editor.getLdifModel();
ISourceViewer viewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
if ( viewer == null )
return;
IDocument document = viewer.getDocument();
IAnnotationModel annotationModel = viewer.getAnnotationModel();
if ( document == null || annotationModel == null || model == null )
return;
if ( annotationModel instanceof IAnnotationModelExtension )
{
( ( IAnnotationModelExtension ) annotationModel ).removeAllAnnotations();
List positionList = new ArrayList();
LdifContainer[] containers = model.getContainers();
for ( int i = 0; i < containers.length; i++ )
{
LdifContainer container = containers[i];
// LdifPart errorPart = null;
int errorOffset = -1;
int errorLength = -1;
StringBuffer errorText = null;
LdifPart[] parts = container.getParts();
for ( int k = 0; k < parts.length; k++ )
{
LdifPart part = parts[k];
if ( !part.isValid() )
{
if ( errorOffset == -1 )
{
// errorPart = part;
errorOffset = part.getOffset();
errorLength = part.getLength();
errorText = new StringBuffer();
errorText.append( part.toRawString() );
}
else
{
errorLength += part.getLength();
errorText.append( part.toRawString() );
}
}
}
if ( errorOffset == -1 && !container.isValid() )
{
errorOffset = container.getOffset();
errorLength = container.getLength();
errorText = new StringBuffer();
errorText.append( container.toRawString() );
}
if ( errorOffset > -1 )
{
// Annotation annotation = new Annotation("DEFAULT",
// true,
// invalidFilters[i].toString());
// if(errorPart instanceof LdifUnknownPart) {
// errorOffset = container.getOffset();
// errorLength = container.getLength();
// errorText = new StringBuffer(container.toString());
// }
Annotation annotation = new Annotation( ERROR_ANNOTATION_TYPE, true, errorText.toString() );
Position position = new Position( errorOffset, errorLength );
positionList.add( position );
viewer.getAnnotationModel().addAnnotation( annotation, position );
}
}
}
}