1 11 package org.eclipse.jface.text.source.projection; 12 13 import java.util.Iterator ; 14 import java.util.Map ; 15 16 import org.eclipse.jface.text.BadLocationException; 17 import org.eclipse.jface.text.Position; 18 import org.eclipse.jface.text.source.Annotation; 19 import org.eclipse.jface.text.source.AnnotationModel; 20 21 22 31 public class ProjectionAnnotationModel extends AnnotationModel { 32 33 34 37 public ProjectionAnnotationModel() { 38 } 39 40 46 public void collapse(Annotation annotation) { 47 if (annotation instanceof ProjectionAnnotation) { 48 ProjectionAnnotation projection= (ProjectionAnnotation) annotation; 49 if (!projection.isCollapsed()) { 50 projection.markCollapsed(); 51 modifyAnnotation(projection, true); 52 } 53 } 54 } 55 56 62 public void expand(Annotation annotation) { 63 if (annotation instanceof ProjectionAnnotation) { 64 ProjectionAnnotation projection= (ProjectionAnnotation) annotation; 65 if (projection.isCollapsed()) { 66 projection.markExpanded(); 67 modifyAnnotation(projection, true); 68 } 69 } 70 } 71 72 78 public void toggleExpansionState(Annotation annotation) { 79 if (annotation instanceof ProjectionAnnotation) { 80 ProjectionAnnotation projection= (ProjectionAnnotation) annotation; 81 82 if (projection.isCollapsed()) 83 projection.markExpanded(); 84 else 85 projection.markCollapsed(); 86 87 modifyAnnotation(projection, true); 88 } 89 } 90 91 98 public boolean expandAll(int offset, int length) { 99 return expandAll(offset, length, true); 100 } 101 102 111 public boolean collapseAll(int offset, int length) { 112 113 boolean collapsing= false; 114 115 Iterator iterator= getAnnotationIterator(); 116 while (iterator.hasNext()) { 117 ProjectionAnnotation annotation= (ProjectionAnnotation) iterator.next(); 118 if (!annotation.isCollapsed()) { 119 Position position= getPosition(annotation); 120 if (position != null && position.overlapsWith(offset, length) ) { 121 annotation.markCollapsed(); 122 modifyAnnotation(annotation, false); 123 collapsing= true; 124 } 125 } 126 } 127 128 if (collapsing) 129 fireModelChanged(); 130 131 return collapsing; 132 } 133 134 144 protected boolean expandAll(int offset, int length, boolean fireModelChanged) { 145 146 boolean expanding= false; 147 148 Iterator iterator= getAnnotationIterator(); 149 while (iterator.hasNext()) { 150 ProjectionAnnotation annotation= (ProjectionAnnotation) iterator.next(); 151 if (annotation.isCollapsed()) { 152 Position position= getPosition(annotation); 153 if (position != null && position.overlapsWith(offset, length) ) { 154 annotation.markExpanded(); 155 modifyAnnotation(annotation, false); 156 expanding= true; 157 } 158 } 159 } 160 161 if (expanding && fireModelChanged) 162 fireModelChanged(); 163 164 return expanding; 165 } 166 167 174 public void modifyAnnotations(Annotation[] deletions, Map additions, Annotation[] modifications) { 175 try { 176 replaceAnnotations(deletions, additions, false); 177 if (modifications != null) { 178 for (int i= 0; i < modifications.length; i++) 179 modifyAnnotation(modifications[i], false); 180 } 181 } catch (BadLocationException x) { 182 } 183 fireModelChanged(); 184 } 185 } 186 | Popular Tags |