1 20 21 package org.apache.directory.ldapstudio.ldifeditor.editor.reconciler; 22 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile; 28 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart; 29 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer; 30 import org.apache.directory.ldapstudio.ldifeditor.editor.ILdifEditor; 31 32 import org.eclipse.jface.text.IDocument; 33 import org.eclipse.jface.text.Position; 34 import org.eclipse.jface.text.source.Annotation; 35 import org.eclipse.jface.text.source.IAnnotationModel; 36 import org.eclipse.jface.text.source.IAnnotationModelExtension; 37 import org.eclipse.jface.text.source.ISourceViewer; 38 39 40 class LdifAnnotationUpdater 41 { 42 43 private static final String ERROR_ANNOTATION_TYPE = "org.eclipse.ui.workbench.texteditor.error"; 44 45 private ILdifEditor editor; 46 47 48 public LdifAnnotationUpdater( ILdifEditor editor ) 49 { 50 this.editor = editor; 51 } 52 53 54 public void dispose() 55 { 56 } 57 58 59 public void updateAnnotations( LdifContainer[] containers ) 60 { 61 62 } 63 64 65 public void updateAnnotations() 66 { 67 68 LdifFile model = editor.getLdifModel(); 69 ISourceViewer viewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class ); 70 if ( viewer == null ) 71 return; 72 73 IDocument document = viewer.getDocument(); 74 IAnnotationModel annotationModel = viewer.getAnnotationModel(); 75 if ( document == null || annotationModel == null || model == null ) 76 return; 77 78 if ( annotationModel instanceof IAnnotationModelExtension ) 79 { 80 ( ( IAnnotationModelExtension ) annotationModel ).removeAllAnnotations(); 81 82 List positionList = new ArrayList (); 83 84 LdifContainer[] containers = model.getContainers(); 85 for ( int i = 0; i < containers.length; i++ ) 86 { 87 LdifContainer container = containers[i]; 88 89 int errorOffset = -1; 91 int errorLength = -1; 92 StringBuffer errorText = null; 93 94 LdifPart[] parts = container.getParts(); 95 for ( int k = 0; k < parts.length; k++ ) 96 { 97 LdifPart part = parts[k]; 98 if ( !part.isValid() ) 99 { 100 if ( errorOffset == -1 ) 101 { 102 errorOffset = part.getOffset(); 104 errorLength = part.getLength(); 105 errorText = new StringBuffer (); 106 errorText.append( part.toRawString() ); 107 } 108 else 109 { 110 errorLength += part.getLength(); 111 errorText.append( part.toRawString() ); 112 } 113 } 114 } 115 116 if ( errorOffset == -1 && !container.isValid() ) 117 { 118 errorOffset = container.getOffset(); 119 errorLength = container.getLength(); 120 errorText = new StringBuffer (); 121 errorText.append( container.toRawString() ); 122 } 123 124 if ( errorOffset > -1 ) 125 { 126 Annotation annotation = new Annotation( ERROR_ANNOTATION_TYPE, true, errorText.toString() ); 135 Position position = new Position( errorOffset, errorLength ); 136 positionList.add( position ); 137 viewer.getAnnotationModel().addAnnotation( annotation, position ); 138 } 139 140 } 141 } 142 } 143 144 } | Popular Tags |