1 11 package org.eclipse.ui.editors.text; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.content.IContentType; 17 18 import org.eclipse.core.filebuffers.IDocumentSetupParticipant; 19 20 import org.eclipse.jface.text.IDocument; 21 import org.eclipse.jface.text.IDocumentExtension3; 22 import org.eclipse.jface.text.source.IAnnotationModel; 23 24 import org.eclipse.ui.texteditor.IDocumentProvider; 25 import org.eclipse.ui.texteditor.IDocumentProviderExtension; 26 import org.eclipse.ui.texteditor.IDocumentProviderExtension2; 27 import org.eclipse.ui.texteditor.IDocumentProviderExtension3; 28 import org.eclipse.ui.texteditor.IDocumentProviderExtension4; 29 import org.eclipse.ui.texteditor.IDocumentProviderExtension5; 30 import org.eclipse.ui.texteditor.IElementStateListener; 31 32 33 62 public class ForwardingDocumentProvider implements IDocumentProvider, IDocumentProviderExtension, IDocumentProviderExtension2, IDocumentProviderExtension3, IDocumentProviderExtension4, IDocumentProviderExtension5, IStorageDocumentProvider { 63 64 private IDocumentProvider fParentProvider; 65 private String fPartitioning; 66 private IDocumentSetupParticipant fDocumentSetupParticipant; 67 private boolean fAllowSetParentProvider; 68 69 70 78 public ForwardingDocumentProvider(String partitioning, IDocumentSetupParticipant documentSetupParticipant, IDocumentProvider parentProvider) { 79 fPartitioning= partitioning; 80 fDocumentSetupParticipant= documentSetupParticipant; 81 fParentProvider= parentProvider; 82 fAllowSetParentProvider= false; 83 } 84 85 93 public ForwardingDocumentProvider(String partitioning, IDocumentSetupParticipant documentSetupParticipant) { 94 fPartitioning= partitioning; 95 fDocumentSetupParticipant= documentSetupParticipant; 96 fAllowSetParentProvider= true; 97 } 98 99 105 public void setParentProvider(IDocumentProvider parentProvider) { 106 if (fAllowSetParentProvider) 107 fParentProvider= parentProvider; 108 } 109 110 113 public void connect(Object element) throws CoreException { 114 fParentProvider.connect(element); 115 IDocument document= fParentProvider.getDocument(element); 116 if (document instanceof IDocumentExtension3) { 117 IDocumentExtension3 extension= (IDocumentExtension3) document; 118 if (extension.getDocumentPartitioner(fPartitioning) == null) 119 fDocumentSetupParticipant.setup(document); 120 } 121 } 122 123 126 public void disconnect(Object element) { 127 fParentProvider.disconnect(element); 128 } 129 130 133 public IDocument getDocument(Object element) { 134 return fParentProvider.getDocument(element); 135 } 136 137 140 public void resetDocument(Object element) throws CoreException { 141 fParentProvider.resetDocument(element); 142 } 143 144 147 public void saveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException { 148 fParentProvider.saveDocument(monitor, element, document, overwrite); 149 } 150 151 154 public long getModificationStamp(Object element) { 155 return fParentProvider.getModificationStamp(element); 156 } 157 158 161 public long getSynchronizationStamp(Object element) { 162 return fParentProvider.getSynchronizationStamp(element); 163 } 164 165 168 public boolean isDeleted(Object element) { 169 return fParentProvider.isDeleted(element); 170 } 171 172 175 public boolean mustSaveDocument(Object element) { 176 return fParentProvider.mustSaveDocument(element); 177 } 178 179 182 public boolean canSaveDocument(Object element) { 183 return fParentProvider.canSaveDocument(element); 184 } 185 186 189 public IAnnotationModel getAnnotationModel(Object element) { 190 return fParentProvider.getAnnotationModel(element); 191 } 192 193 196 public void aboutToChange(Object element) { 197 fParentProvider.aboutToChange(element); 198 } 199 200 203 public void changed(Object element) { 204 fParentProvider.changed(element); 205 } 206 207 210 public void addElementStateListener(IElementStateListener listener) { 211 fParentProvider.addElementStateListener(listener); 212 } 213 214 217 public void removeElementStateListener(IElementStateListener listener) { 218 fParentProvider.removeElementStateListener(listener); 219 } 220 221 224 public boolean isReadOnly(Object element) { 225 if (fParentProvider instanceof IDocumentProviderExtension) { 226 IDocumentProviderExtension extension= (IDocumentProviderExtension)fParentProvider; 227 return extension.isReadOnly(element); 228 } 229 return false; 230 } 231 232 235 public boolean isModifiable(Object element) { 236 if (fParentProvider instanceof IDocumentProviderExtension) { 237 IDocumentProviderExtension extension= (IDocumentProviderExtension)fParentProvider; 238 return extension.isModifiable(element); 239 } 240 return true; 241 } 242 243 246 public void validateState(Object element, Object computationContext) throws CoreException { 247 if (fParentProvider instanceof IDocumentProviderExtension) { 248 IDocumentProviderExtension extension= (IDocumentProviderExtension)fParentProvider; 249 extension.validateState(element, computationContext); 250 } 251 } 252 253 256 public boolean isStateValidated(Object element) { 257 if (fParentProvider instanceof IDocumentProviderExtension) { 258 IDocumentProviderExtension extension= (IDocumentProviderExtension)fParentProvider; 259 return extension.isStateValidated(element); 260 } 261 return true; 262 } 263 264 267 public void updateStateCache(Object element) throws CoreException { 268 if (fParentProvider instanceof IDocumentProviderExtension) { 269 IDocumentProviderExtension extension= (IDocumentProviderExtension)fParentProvider; 270 extension.updateStateCache(element); 271 } 272 } 273 274 277 public void setCanSaveDocument(Object element) { 278 if (fParentProvider instanceof IDocumentProviderExtension) { 279 IDocumentProviderExtension extension= (IDocumentProviderExtension)fParentProvider; 280 extension.setCanSaveDocument(element); 281 } 282 } 283 284 287 public IStatus getStatus(Object element) { 288 if (fParentProvider instanceof IDocumentProviderExtension) { 289 IDocumentProviderExtension extension= (IDocumentProviderExtension)fParentProvider; 290 return extension.getStatus(element); 291 } 292 return null; 293 } 294 295 298 public void synchronize(Object element) throws CoreException { 299 if (fParentProvider instanceof IDocumentProviderExtension) { 300 IDocumentProviderExtension extension= (IDocumentProviderExtension)fParentProvider; 301 extension.synchronize(element); 302 } 303 } 304 305 308 public void setProgressMonitor(IProgressMonitor progressMonitor) { 309 if (fParentProvider instanceof IDocumentProviderExtension2) { 310 IDocumentProviderExtension2 extension= (IDocumentProviderExtension2)fParentProvider; 311 extension.setProgressMonitor(progressMonitor); 312 } 313 } 314 315 318 public IProgressMonitor getProgressMonitor() { 319 if (fParentProvider instanceof IDocumentProviderExtension2) { 320 IDocumentProviderExtension2 extension= (IDocumentProviderExtension2)fParentProvider; 321 return extension.getProgressMonitor(); 322 } 323 return null; 324 } 325 326 329 public boolean isSynchronized(Object element) { 330 if (fParentProvider instanceof IDocumentProviderExtension3) { 331 IDocumentProviderExtension3 extension= (IDocumentProviderExtension3)fParentProvider; 332 return extension.isSynchronized(element); 333 } 334 return true; 335 } 336 337 341 public boolean isNotSynchronizedException(Object element, CoreException ex) { 342 if (fParentProvider instanceof IDocumentProviderExtension5) { 343 IDocumentProviderExtension5 extension= (IDocumentProviderExtension5)fParentProvider; 344 return extension.isNotSynchronizedException(element, ex); 345 } 346 return false; 347 } 348 349 353 public IContentType getContentType(Object element) throws CoreException { 354 if (fParentProvider instanceof IDocumentProviderExtension4) { 355 IDocumentProviderExtension4 extension= (IDocumentProviderExtension4)fParentProvider; 356 return extension.getContentType(element); 357 } 358 return null; 359 } 360 361 364 public String getDefaultEncoding() { 365 if (fParentProvider instanceof IStorageDocumentProvider) { 366 IStorageDocumentProvider provider= (IStorageDocumentProvider)fParentProvider; 367 return provider.getDefaultEncoding(); 368 } 369 return null; 370 } 371 372 375 public String getEncoding(Object element) { 376 if (fParentProvider instanceof IStorageDocumentProvider) { 377 IStorageDocumentProvider provider= (IStorageDocumentProvider)fParentProvider; 378 return provider.getEncoding(element); 379 } 380 return null; 381 } 382 383 386 public void setEncoding(Object element, String encoding) { 387 if (fParentProvider instanceof IStorageDocumentProvider) { 388 IStorageDocumentProvider provider= (IStorageDocumentProvider)fParentProvider; 389 provider.setEncoding(element, encoding); 390 } 391 } 392 } 393 | Popular Tags |