1 11 12 package org.eclipse.jdt.internal.ui.propertiesfileeditor; 13 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.Platform; 16 import org.eclipse.core.runtime.content.IContentDescription; 17 import org.eclipse.core.runtime.content.IContentType; 18 19 import org.eclipse.core.resources.IFile; 20 21 import org.eclipse.jface.text.IDocument; 22 23 import org.eclipse.ui.editors.text.ForwardingDocumentProvider; 24 import org.eclipse.ui.editors.text.TextFileDocumentProvider; 25 26 import org.eclipse.ui.IFileEditorInput; 27 import org.eclipse.ui.texteditor.IDocumentProvider; 28 29 30 35 public class PropertiesFileDocumentProvider extends TextFileDocumentProvider { 36 37 38 private static final IContentType JAVA_PROPERTIES_FILE_CONTENT_TYPE= Platform.getContentTypeManager().getContentType("org.eclipse.jdt.core.javaProperties"); 40 41 45 public PropertiesFileDocumentProvider() { 46 IDocumentProvider provider= new TextFileDocumentProvider(); 47 provider= new ForwardingDocumentProvider(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, new PropertiesFileDocumentSetupParticipant(), provider); 48 setParentDocumentProvider(provider); 49 } 50 51 54 protected FileInfo createFileInfo(Object element) throws CoreException { 55 if (JAVA_PROPERTIES_FILE_CONTENT_TYPE == null || !(element instanceof IFileEditorInput)) 56 return null; 57 58 IFileEditorInput input= (IFileEditorInput)element; 59 60 IFile file= input.getFile(); 61 if (file == null || !file.isAccessible()) 62 return null; 63 64 IContentDescription description= file.getContentDescription(); 65 if (description == null || description.getContentType() == null || !description.getContentType().isKindOf(JAVA_PROPERTIES_FILE_CONTENT_TYPE)) 66 return null; 67 68 return super.createFileInfo(element); 69 } 70 71 75 protected DocumentProviderOperation createSaveOperation(final Object element, final IDocument document, final boolean overwrite) throws CoreException { 76 if (getFileInfo(element) == null) 77 return null; 78 79 return super.createSaveOperation(element, document, overwrite); 80 } 81 } 82 | Popular Tags |