1 11 package org.eclipse.ui.internal.editors.text; 12 13 import org.eclipse.core.filesystem.EFS; 14 import org.eclipse.core.filesystem.IFileStore; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IPath; 18 import org.eclipse.core.runtime.Path; 19 import org.eclipse.core.runtime.Platform; 20 21 import org.eclipse.core.resources.IStorage; 22 23 import org.eclipse.jface.resource.ImageDescriptor; 24 25 import org.eclipse.jface.text.Assert; 26 27 import org.eclipse.ui.editors.text.ILocationProvider; 28 29 import org.eclipse.ui.IPathEditorInput; 30 import org.eclipse.ui.IPersistableElement; 31 import org.eclipse.ui.IStorageEditorInput; 32 import org.eclipse.ui.model.IWorkbenchAdapter; 33 34 37 public class JavaFileEditorInput implements IPathEditorInput, IStorageEditorInput, ILocationProvider { 38 39 44 private class WorkbenchAdapter implements IWorkbenchAdapter { 45 48 public Object [] getChildren(Object o) { 49 return null; 50 } 51 52 55 public ImageDescriptor getImageDescriptor(Object object) { 56 return null; 57 } 58 59 62 public String getLabel(Object o) { 63 return ((JavaFileEditorInput)o).getName(); 64 } 65 66 69 public Object getParent(Object o) { 70 return null; 71 } 72 } 73 74 private IFileStore fFileStore; 75 private WorkbenchAdapter fWorkbenchAdapter= new WorkbenchAdapter(); 76 private IStorage fStorage; 77 private IPath fPath; 78 79 public JavaFileEditorInput(IFileStore fileStore) { 80 Assert.isNotNull(fileStore); 81 Assert.isTrue(EFS.SCHEME_FILE.equals(fileStore.getFileSystem().getScheme())); 82 fFileStore= fileStore; 83 fWorkbenchAdapter= new WorkbenchAdapter(); 84 } 85 88 public boolean exists() { 89 return fFileStore.fetchInfo().exists(); 90 } 91 92 95 public ImageDescriptor getImageDescriptor() { 96 return null; 97 } 98 99 102 public String getName() { 103 return fFileStore.getName(); 104 } 105 106 109 public IPersistableElement getPersistable() { 110 return null; 111 } 112 113 116 public String getToolTipText() { 117 return fFileStore.toString(); 118 } 119 120 123 public Object getAdapter(Class adapter) { 124 if (ILocationProvider.class.equals(adapter)) 125 return this; 126 if (IWorkbenchAdapter.class.equals(adapter)) 127 return fWorkbenchAdapter; 128 return Platform.getAdapterManager().getAdapter(this, adapter); 129 } 130 131 134 public IPath getPath(Object element) { 135 if (element instanceof JavaFileEditorInput) 136 return ((JavaFileEditorInput)element).getPath(); 137 138 return null; 139 } 140 141 145 public IPath getPath() { 146 if (fPath == null) 147 fPath= new Path(fFileStore.toURI().getPath()); 148 return fPath; 149 } 150 151 154 public boolean equals(Object o) { 155 if (o == this) 156 return true; 157 158 if (o instanceof JavaFileEditorInput) { 159 JavaFileEditorInput input= (JavaFileEditorInput) o; 160 return fFileStore.equals(input.fFileStore); 161 } 162 163 if (o instanceof IPathEditorInput) { 164 IPathEditorInput input= (IPathEditorInput)o; 165 return getPath().equals(input.getPath()); 166 } 167 168 return false; 169 } 170 171 174 public int hashCode() { 175 return fFileStore.hashCode(); 176 } 177 178 182 public IStorage getStorage() throws CoreException { 183 if (fStorage == null) 184 fStorage= new JavaFileStorage(fFileStore); 185 return fStorage; 186 } 187 188 } 189 | Popular Tags |