1 11 package org.eclipse.compare.internal.patch; 12 13 import java.io.*; 14 15 import org.eclipse.compare.IEncodedStreamContentAccessor; 16 import org.eclipse.compare.ITypedElement; 17 import org.eclipse.compare.internal.*; 18 import org.eclipse.compare.patch.IHunk; 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.jface.resource.ImageDescriptor; 21 import org.eclipse.jface.resource.LocalResourceManager; 22 import org.eclipse.swt.graphics.Image; 23 24 public class HunkTypedElement implements ITypedElement, IEncodedStreamContentAccessor, IAdaptable { 25 26 private final HunkResult fHunkResult; 27 private final boolean fIsAfterState; 28 private final boolean fFullContext; 29 30 public HunkTypedElement(HunkResult result, boolean isAfterState, boolean fullContext) { 31 this.fHunkResult = result; 32 this.fIsAfterState = isAfterState; 33 this.fFullContext = fullContext; 34 } 35 36 39 public Image getImage() { 40 if (!fHunkResult.isOK()) { 41 LocalResourceManager imageCache = PatchCompareEditorInput.getImageCache(fHunkResult.getDiffResult().getConfiguration()); 42 return getHunkErrorImage(null, imageCache, false); 43 } 44 return null; 45 } 46 47 public static Image getHunkErrorImage(Image baseImage, LocalResourceManager imageCache, boolean onLeft) { 48 ImageDescriptor desc = new DiffImage(baseImage, CompareUIPlugin.getImageDescriptor(ICompareUIConstants.ERROR_OVERLAY), ICompareUIConstants.COMPARE_IMAGE_WIDTH, onLeft); 49 Image image = imageCache.createImage(desc); 50 return image; 51 } 52 53 public boolean isManuallyMerged() { 54 return getPatcher().isManuallyMerged(getHunkResult().getHunk()); 55 } 56 57 private Patcher getPatcher() { 58 return Patcher.getPatcher(fHunkResult.getDiffResult().getConfiguration()); 59 } 60 61 64 public String getName() { 65 return fHunkResult.getLabel(); 66 } 67 68 71 public String getType() { 72 return fHunkResult.getDiffResult().getDiff().getTargetPath(fHunkResult.getDiffResult().getConfiguration()).getFileExtension(); 73 } 74 75 78 public InputStream getContents() throws CoreException { 79 String contents = fHunkResult.getContents(fIsAfterState, fFullContext); 80 return fHunkResult.asInputStream(contents); 81 } 82 83 public String getCharset() throws CoreException { 84 return fHunkResult.getCharset(); 85 } 86 87 public HunkResult getHunkResult() { 88 return fHunkResult; 89 } 90 91 public Object getAdapter(Class adapter) { 92 if (adapter == IHunk.class) 93 return fHunkResult; 94 return Platform.getAdapterManager().getAdapter(this, adapter); 95 } 96 97 } 98 | Popular Tags |