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.Assert; 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.jface.resource.ImageDescriptor; 22 23 24 import org.eclipse.ui.editors.text.ILocationProvider; 25 26 import org.eclipse.ui.IEditorInput; 27 import org.eclipse.ui.IPersistableElement; 28 29 32 public class NonExistingFileEditorInput implements IEditorInput, ILocationProvider { 33 34 private static int fgNonExisting= 0; 35 36 private IFileStore fFileStore; 37 private String fName; 38 39 public NonExistingFileEditorInput(IFileStore fileStore, String namePrefix) { 40 Assert.isNotNull(fileStore); 41 Assert.isTrue(EFS.SCHEME_FILE.equals(fileStore.getFileSystem().getScheme())); 42 fFileStore= fileStore; 43 ++fgNonExisting; 44 fName= namePrefix + " " + fgNonExisting; } 46 47 50 public boolean exists() { 51 return false; 52 } 53 54 57 public ImageDescriptor getImageDescriptor() { 58 return null; 59 } 60 61 64 public String getName() { 65 return fName; 66 } 67 68 71 public IPersistableElement getPersistable() { 72 return null; 73 } 74 75 78 public String getToolTipText() { 79 return fName; 80 } 81 82 85 public Object getAdapter(Class adapter) { 86 if (ILocationProvider.class.equals(adapter)) 87 return this; 88 return Platform.getAdapterManager().getAdapter(this, adapter); 89 } 90 91 94 public IPath getPath(Object element) { 95 if (element instanceof NonExistingFileEditorInput) { 96 NonExistingFileEditorInput input= (NonExistingFileEditorInput)element; 97 return new Path(input.fFileStore.toURI().getPath()); 98 } 99 return null; 100 } 101 102 105 public boolean equals(Object o) { 106 if (o == this) 107 return true; 108 109 if (o instanceof NonExistingFileEditorInput) { 110 NonExistingFileEditorInput input = (NonExistingFileEditorInput) o; 111 return fFileStore.equals(input.fFileStore); 112 } 113 114 return false; 115 } 116 117 120 public int hashCode() { 121 return fFileStore.hashCode(); 122 } 123 } 124 | Popular Tags |