1 14 15 package org.eclipse.ant.internal.ui.editor.text; 16 17 18 import org.eclipse.ant.internal.ui.model.AntModel; 19 import org.eclipse.ant.internal.ui.model.IProblemRequestor; 20 import org.eclipse.ant.internal.ui.model.LocationProvider; 21 import org.eclipse.core.resources.IFile; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.jface.text.IDocument; 24 import org.eclipse.jface.text.IDocumentExtension3; 25 import org.eclipse.jface.text.ISynchronizable; 26 import org.eclipse.jface.text.source.IAnnotationModel; 27 import org.eclipse.ui.IEditorInput; 28 import org.eclipse.ui.editors.text.TextFileDocumentProvider; 29 import org.eclipse.ui.texteditor.IDocumentProvider; 30 31 public class AntEditorDocumentProvider extends TextFileDocumentProvider { 32 33 private final AntDocumentSetupParticipant fAntDocumentSetupParticipant; 34 35 38 protected class AntFileInfo extends FileInfo { 39 40 public AntModel fAntModel; 41 42 public AntFileInfo() { 43 } 44 } 45 46 public AntEditorDocumentProvider() { 47 IDocumentProvider provider= new TextFileDocumentProvider(new AntStorageDocumentProvider()); 48 setParentDocumentProvider(provider); 49 fAntDocumentSetupParticipant = new AntDocumentSetupParticipant(); 50 } 51 52 public AntModel getAntModel(Object element) { 53 FileInfo info= getFileInfo(element); 54 if (info instanceof AntFileInfo) { 55 AntFileInfo xmlInfo= (AntFileInfo) info; 56 return xmlInfo.fAntModel; 57 } 58 return null; 59 } 60 61 64 protected IAnnotationModel createAnnotationModel(IFile file) { 65 return new AntAnnotationModel(file); 66 } 67 68 protected AntModel createAntModel(Object element, IDocument document, IAnnotationModel annotationModel) { 69 IProblemRequestor requestor= annotationModel instanceof IProblemRequestor ? (IProblemRequestor) annotationModel : null; 70 return new AntModel(document, requestor, new LocationProvider(element instanceof IEditorInput ? (IEditorInput) element : null)); 71 } 72 73 76 protected FileInfo createFileInfo(Object element) throws CoreException { 77 FileInfo info= super.createFileInfo(element); 78 if (!(info instanceof AntFileInfo)) { 79 return null; 80 } 81 82 IDocument document= info.fTextFileBuffer.getDocument(); 88 if (document instanceof IDocumentExtension3) { 89 IDocumentExtension3 extension= (IDocumentExtension3) document; 90 if (extension.getDocumentPartitioner(AntDocumentSetupParticipant.ANT_PARTITIONING) == null) 91 fAntDocumentSetupParticipant.setup(document); 92 } 93 94 AntFileInfo xmlInfo= (AntFileInfo) info; 102 IAnnotationModel annotationModel= xmlInfo.fTextFileBuffer.getAnnotationModel(); 103 if (annotationModel instanceof IProblemRequestor) { 104 xmlInfo.fModel= annotationModel; 105 } else { 106 annotationModel= xmlInfo.fModel; 107 } 108 109 if (annotationModel == null) { 110 annotationModel= new AntExternalAnnotationModel(); 111 xmlInfo.fModel= annotationModel; 112 } 113 114 AntModel antModel= createAntModel(element, document, annotationModel); 115 antModel.install(); 116 xmlInfo.fAntModel= antModel; 117 setUpSynchronization(xmlInfo); 118 119 return xmlInfo; 120 } 121 122 125 protected void disposeFileInfo(Object element, FileInfo info) { 126 if (info instanceof AntFileInfo) { 127 AntFileInfo xmlInfo= (AntFileInfo) info; 128 if (xmlInfo.fAntModel != null) { 129 IDocument doc= xmlInfo.fTextFileBuffer.getDocument(); 130 Object lock= null; 131 if (doc instanceof ISynchronizable) { 132 lock= ((ISynchronizable) doc).getLockObject(); 133 } else { 134 lock= xmlInfo.fAntModel; 135 } 136 if (lock == null) { 137 xmlInfo.fAntModel.dispose(); 138 xmlInfo.fAntModel= null; 139 } else { 140 synchronized (lock) { 141 xmlInfo.fAntModel.dispose(); 142 xmlInfo.fAntModel= null; 143 } 144 } 145 } 146 } 147 super.disposeFileInfo(element, info); 148 } 149 150 153 protected FileInfo createEmptyFileInfo() { 154 return new AntFileInfo(); 155 } 156 } | Popular Tags |