1 20 21 package org.apache.directory.ldapstudio.ldifeditor.editor; 22 23 24 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorConstants; 25 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorActivator; 26 import org.eclipse.core.runtime.IPath; 27 import org.eclipse.core.runtime.Platform; 28 import org.eclipse.jface.resource.ImageDescriptor; 29 import org.eclipse.ui.IPathEditorInput; 30 import org.eclipse.ui.IPersistableElement; 31 import org.eclipse.ui.editors.text.ILocationProvider; 32 33 34 44 public class NonExistingLdifEditorInput implements IPathEditorInput, ILocationProvider 45 { 46 47 private static int counter = 0; 48 49 50 private String name; 51 52 53 56 public NonExistingLdifEditorInput() 57 { 58 counter++; 59 name = "LDIF " + counter; } 61 62 63 66 public boolean exists() 67 { 68 return false; 69 } 70 71 72 75 public ImageDescriptor getImageDescriptor() 76 { 77 return LdifEditorActivator.getDefault().getImageDescriptor( LdifEditorConstants.IMG_BROWSER_LDIFEDITOR ); 78 } 79 80 81 84 public String getName() 85 { 86 return name; 87 } 88 89 90 93 public IPersistableElement getPersistable() 94 { 95 return null; 96 } 97 98 99 102 public String getToolTipText() 103 { 104 return name; 105 } 106 107 108 112 public Object getAdapter( Class adapter ) 113 { 114 if ( ILocationProvider.class.equals( adapter ) ) 115 { 116 return this; 117 } 118 119 return Platform.getAdapterManager().getAdapter( this, adapter ); 120 } 121 122 123 130 public IPath getPath( Object element ) 131 { 132 if ( element instanceof NonExistingLdifEditorInput ) 133 { 134 NonExistingLdifEditorInput input = ( NonExistingLdifEditorInput ) element; 135 return input.getPath(); 136 } 137 138 return null; 139 } 140 141 142 145 public boolean equals( Object o ) 146 { 147 if ( o == this ) 148 { 149 return true; 150 } 151 152 if ( o instanceof NonExistingLdifEditorInput ) 153 { 154 NonExistingLdifEditorInput input = ( NonExistingLdifEditorInput ) o; 155 return name.equals( input.name ); 156 } 157 158 return false; 159 } 160 161 162 165 public int hashCode() 166 { 167 return name.hashCode(); 168 } 169 170 171 179 public IPath getPath() 180 { 181 return LdifEditorActivator.getDefault().getStateLocation().append( name + ".ldif" ); 182 } 183 184 } 185 | Popular Tags |