1 11 package org.eclipse.compare; 12 13 import java.io.InputStream ; 14 import java.io.BufferedInputStream ; 15 16 import org.eclipse.swt.graphics.Image; 17 18 import org.eclipse.compare.IResourceProvider; 19 import org.eclipse.core.resources.IEncodedStorage; 20 import org.eclipse.core.resources.IFileState; 21 import org.eclipse.core.resources.IResource; 22 import org.eclipse.core.resources.ResourcesPlugin; 23 import org.eclipse.core.runtime.CoreException; 24 import org.eclipse.core.runtime.IPath; 25 26 35 public class HistoryItem implements IEncodedStreamContentAccessor, ITypedElement, IModificationDate, IResourceProvider { 36 37 private ITypedElement fBase; 38 private IFileState fFileState; 39 40 48 public HistoryItem(ITypedElement base, IFileState fileState) { 49 fBase= base; 50 fFileState= fileState; 51 } 52 53 56 public String getName() { 57 return fBase.getName(); 58 } 59 60 63 public Image getImage() { 64 return fBase.getImage(); 65 } 66 67 70 public String getType() { 71 return fBase.getType(); 72 } 73 74 77 public long getModificationDate() { 78 return fFileState.getModificationTime(); 79 } 80 81 84 public InputStream getContents() throws CoreException { 85 return new BufferedInputStream (fFileState.getContents()); 86 } 87 88 91 public String getCharset() throws CoreException { 92 String charset= fFileState.getCharset(); 93 if (charset == null) { 94 IResource resource= getResource(); 95 if (resource instanceof IEncodedStorage) 96 charset= ((IEncodedStorage)resource).getCharset(); 97 } 98 return charset; 99 } 100 101 104 public IResource getResource() { 105 IPath fullPath= fFileState.getFullPath(); 106 return ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath); 107 } 108 } 109 110 | Popular Tags |