1 8 package com.nightlabs.rcp.io; 9 10 import java.io.File ; 11 import java.io.IOException ; 12 13 import org.eclipse.core.runtime.IPath; 14 import org.eclipse.core.runtime.Path; 15 import org.eclipse.jface.resource.ImageDescriptor; 16 import org.eclipse.ui.IEditorInput; 17 import org.eclipse.ui.IPathEditorInput; 18 import org.eclipse.ui.IPersistableElement; 19 20 public class FileEditorInput 21 implements IEditorInput, 22 IPathEditorInput 23 { 24 protected File file; 25 26 public FileEditorInput(File f) 27 { 28 if (f == null) 29 throw new IllegalArgumentException ("Param f must not be null!"); 30 31 this.file = f; 32 } 33 34 public boolean exists() 35 { 36 return file.exists(); 37 } 38 39 public File getFile() { 40 return file; 41 } 42 43 public String getName() 44 { 45 return file.getName(); 46 } 47 48 public ImageDescriptor getImageDescriptor() 49 { 50 return null; 52 } 53 54 public IPersistableElement getPersistable() 55 { 56 return null; 58 } 59 60 public String getToolTipText() 61 { 62 return file.getAbsolutePath(); 63 } 64 65 public Object getAdapter(Class adapter) 66 { 67 return null; 69 } 70 71 public IPath getPath() 72 { 73 try { 74 String path = file.getCanonicalPath(); 75 return new Path(path); 76 } catch (IOException e) { 77 e.printStackTrace(); 79 } 80 return null; 81 } 82 83 public int hashCode() 84 { 85 return file.hashCode(); 86 } 87 88 public boolean equals(Object o) 89 { 90 if (o == this) 91 return true; 92 93 if (o instanceof FileEditorInput) { 94 FileEditorInput input = (FileEditorInput) o; 95 return file.equals(input.getFile()); 96 } 97 98 return false; 99 } 100 101 protected boolean saved = true; 102 public boolean isSaved() 103 { 104 if (!exists()) 105 return false; 106 107 return saved; 108 } 109 public void setSaved(boolean saved) { 110 this.saved = saved; 111 } 112 } 113 | Popular Tags |