1 11 package org.eclipse.ui.internal.texteditor; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.core.runtime.Assert; 16 17 import org.eclipse.swt.graphics.Font; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 21 import org.eclipse.jface.text.source.Annotation; 22 import org.eclipse.jface.text.source.AnnotationRulerColumn; 23 import org.eclipse.jface.text.source.CompositeRuler; 24 import org.eclipse.jface.text.source.IAnnotationHover; 25 import org.eclipse.jface.text.source.IAnnotationModel; 26 import org.eclipse.jface.text.source.IVerticalRulerColumn; 27 import org.eclipse.jface.text.source.IVerticalRulerInfo; 28 import org.eclipse.jface.text.source.IVerticalRulerInfoExtension; 29 import org.eclipse.jface.text.source.IVerticalRulerListener; 30 31 import org.eclipse.ui.editors.text.EditorsUI; 32 33 import org.eclipse.ui.internal.editors.text.EditorsPlugin; 34 35 import org.eclipse.jface.preference.IPreferenceStore; 36 import org.eclipse.jface.util.IPropertyChangeListener; 37 import org.eclipse.jface.util.PropertyChangeEvent; 38 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor; 39 import org.eclipse.ui.texteditor.AnnotationPreference; 40 import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess; 41 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences; 42 import org.eclipse.ui.texteditor.rulers.AbstractContributedRulerColumn; 43 44 53 public class AnnotationColumn extends AbstractContributedRulerColumn implements IVerticalRulerInfo, IVerticalRulerInfoExtension { 54 55 public static final String ID= "org.eclipse.ui.editors.columns.annotations"; 57 private final static int VERTICAL_RULER_WIDTH= 12; 58 59 60 private IVerticalRulerColumn fDelegate; 61 private final MarkerAnnotationPreferences fAnnotationPreferences= EditorsPlugin.getDefault().getMarkerAnnotationPreferences(); 62 private IPropertyChangeListener fPropertyListener; 63 64 67 public Control createControl(CompositeRuler parentRuler, Composite parentControl) { 68 initialize(); 69 Control control= fDelegate.createControl(parentRuler, parentControl); 70 return control; 71 } 72 73 76 public Control getControl() { 77 return fDelegate.getControl(); 78 } 79 80 83 public int getWidth() { 84 return fDelegate.getWidth(); 85 } 86 87 90 public void redraw() { 91 fDelegate.redraw(); 92 } 93 94 97 public void setFont(Font font) { 98 fDelegate.setFont(font); 99 } 100 101 104 public void setModel(IAnnotationModel model) { 105 fDelegate.setModel(model); 106 } 107 108 111 public void columnRemoved() { 112 if (fPropertyListener != null) { 113 IPreferenceStore store= getPreferenceStore(); 114 if (store != null) 115 store.removePropertyChangeListener(fPropertyListener); 116 fPropertyListener= null; 117 } 118 } 119 120 123 private void initialize() { 124 if (fDelegate == null) 125 fDelegate= new AnnotationRulerColumn(VERTICAL_RULER_WIDTH, new DefaultMarkerAnnotationAccess()); 126 IPreferenceStore store= getPreferenceStore(); 127 if (store != null && fDelegate instanceof AnnotationRulerColumn) { 128 final AnnotationRulerColumn column= (AnnotationRulerColumn) fDelegate; 129 for (Iterator iter2= fAnnotationPreferences.getAnnotationPreferences().iterator(); iter2.hasNext();) { 131 AnnotationPreference preference= (AnnotationPreference)iter2.next(); 132 String key= preference.getVerticalRulerPreferenceKey(); 133 boolean showAnnotation= true; 134 if (key != null && store.contains(key)) 135 showAnnotation= store.getBoolean(key); 136 if (showAnnotation) 137 column.addAnnotationType(preference.getAnnotationType()); 138 } 139 column.addAnnotationType(Annotation.TYPE_UNKNOWN); 140 141 fPropertyListener= new IPropertyChangeListener() { 143 public void propertyChange(PropertyChangeEvent event) { 144 String property= event.getProperty(); 145 AnnotationPreference annotationPreference= getVerticalRulerAnnotationPreference(property); 146 if (annotationPreference != null && event.getNewValue() instanceof Boolean ) { 147 Object type= annotationPreference.getAnnotationType(); 148 if (((Boolean )event.getNewValue()).booleanValue()) 149 column.addAnnotationType(type); 150 else 151 column.removeAnnotationType(type); 152 column.redraw(); 153 } 154 } 155 }; 156 store.addPropertyChangeListener(fPropertyListener); 157 } 158 } 159 160 167 private AnnotationPreference getVerticalRulerAnnotationPreference(String preferenceKey) { 168 if (preferenceKey == null) 169 return null; 170 171 Iterator e= fAnnotationPreferences.getAnnotationPreferences().iterator(); 172 while (e.hasNext()) { 173 AnnotationPreference info= (AnnotationPreference) e.next(); 174 if (info != null && preferenceKey.equals(info.getVerticalRulerPreferenceKey())) 175 return info; 176 } 177 return null; 178 } 179 180 private IPreferenceStore getPreferenceStore() { 181 return EditorsUI.getPreferenceStore(); 182 } 183 184 189 public void setDelegate(IVerticalRulerColumn column) { 190 Assert.isLegal(fDelegate == null); 191 Assert.isLegal(column != null); 192 fDelegate= column; 193 } 194 195 198 public void addVerticalRulerListener(IVerticalRulerListener listener) { 199 if (fDelegate instanceof IVerticalRulerInfoExtension) 200 ((IVerticalRulerInfoExtension) fDelegate).addVerticalRulerListener(listener); 201 } 202 203 206 public IAnnotationHover getHover() { 207 if (fDelegate instanceof IVerticalRulerInfoExtension) 208 return ((IVerticalRulerInfoExtension) fDelegate).getHover(); 209 return null; 210 } 211 212 215 public IAnnotationModel getModel() { 216 if (fDelegate instanceof IVerticalRulerInfoExtension) 217 return ((IVerticalRulerInfoExtension) fDelegate).getModel(); 218 return null; 219 } 220 221 224 public void removeVerticalRulerListener(IVerticalRulerListener listener) { 225 if (fDelegate instanceof IVerticalRulerInfoExtension) 226 ((IVerticalRulerInfoExtension) fDelegate).removeVerticalRulerListener(listener); 227 } 228 229 232 public int getLineOfLastMouseButtonActivity() { 233 if (fDelegate instanceof IVerticalRulerInfo) 234 ((IVerticalRulerInfo) fDelegate).getLineOfLastMouseButtonActivity(); 235 return -1; 236 } 237 238 241 public int toDocumentLineNumber(int y_coordinate) { 242 if (fDelegate instanceof IVerticalRulerInfo) 243 ((IVerticalRulerInfo) fDelegate).toDocumentLineNumber(y_coordinate); 244 return -1; 245 } 246 } 247 | Popular Tags |