1 11 package org.eclipse.team.internal.ui.history; 12 13 import java.io.ByteArrayInputStream ; 14 import java.io.InputStream ; 15 import java.lang.reflect.InvocationTargetException ; 16 17 import org.eclipse.compare.ITypedElement; 18 import org.eclipse.compare.ResourceNode; 19 import org.eclipse.core.resources.IFile; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 import org.eclipse.jface.operation.IRunnableWithProgress; 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.progress.IProgressService; 25 26 27 public class TypedBufferedContent extends ResourceNode { 28 public TypedBufferedContent(IFile resource) { 29 super(resource); 30 } 31 protected InputStream createStream() throws CoreException { 32 return ((IFile)getResource()).getContents(); 33 } 34 public void setContent(byte[] contents) { 35 if (contents == null) contents = new byte[0]; 36 final InputStream is = new ByteArrayInputStream (contents); 37 IRunnableWithProgress runnable = new IRunnableWithProgress() { 38 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 39 try { 40 IFile file = (IFile) getResource(); 41 if (is != null) { 42 if (!file.exists()) { 43 file.create(is, false, monitor); 44 } else { 45 file.setContents(is, false, true, monitor); 46 } 47 } else { 48 file.delete(false, true, monitor); 49 } 50 } catch (CoreException e) { 51 throw new InvocationTargetException (e); 52 } 53 } 54 }; 55 try { 56 IProgressService progressService= PlatformUI.getWorkbench().getProgressService(); 57 progressService.run(false,false, runnable); 58 } catch (InvocationTargetException e) { 59 } catch (InterruptedException e) { 61 } 63 fireContentChanged(); 64 } 65 public ITypedElement replace(ITypedElement child, ITypedElement other) { 66 return null; 67 } 68 public void fireChange() { 69 fireContentChanged(); 70 } 71 } 72 | Popular Tags |