1 11 package org.apache.directory.ldapstudio.ldifeditor.editor; 12 13 14 import org.eclipse.core.runtime.IPath; 15 import org.eclipse.core.runtime.Platform; 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.ui.IPathEditorInput; 18 import org.eclipse.ui.IPersistableElement; 19 import org.eclipse.ui.PlatformUI; 20 import org.eclipse.ui.editors.text.ILocationProvider; 21 22 23 26 27 35 public class PathEditorInput implements IPathEditorInput, ILocationProvider 36 { 37 38 39 private IPath path; 40 41 42 48 public PathEditorInput( IPath path ) 49 { 50 if ( path == null ) 51 { 52 throw new IllegalArgumentException (); 53 } 54 55 this.path = path; 56 } 57 58 59 62 public int hashCode() 63 { 64 return path.hashCode(); 65 } 66 67 68 71 public boolean equals( Object o ) 72 { 73 if ( this == o ) 74 { 75 return true; 76 } 77 78 if ( o instanceof PathEditorInput ) 79 { 80 PathEditorInput input = ( PathEditorInput ) o; 81 return path.equals( input.path ); 82 } 83 84 return false; 85 } 86 87 88 91 public boolean exists() 92 { 93 return path.toFile().exists(); 94 } 95 96 97 100 public ImageDescriptor getImageDescriptor() 101 { 102 return PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor( path.toString() ); 103 } 104 105 106 109 public String getName() 110 { 111 return path.toFile().getName(); 112 } 114 115 116 119 public String getToolTipText() 120 { 121 return path.makeRelative().toOSString(); 122 } 123 124 125 128 public IPath getPath() 129 { 130 return path; 131 } 132 133 134 138 public Object getAdapter( Class adapter ) 139 { 140 if ( ILocationProvider.class.equals( adapter ) ) 141 { 142 return this; 143 } 144 145 return Platform.getAdapterManager().getAdapter( this, adapter ); 146 } 147 148 149 152 public IPersistableElement getPersistable() 153 { 154 return null; 155 } 156 157 158 161 public IPath getPath( Object element ) 162 { 163 if ( element instanceof PathEditorInput ) 164 { 165 PathEditorInput input = ( PathEditorInput ) element; 166 return input.getPath(); 167 } 168 169 return null; 170 } 171 } 172 | Popular Tags |