1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.entry; 22 23 24 import org.apache.directory.ldapstudio.browser.core.model.IBookmark; 25 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 26 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult; 27 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants; 28 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin; 29 import org.eclipse.jface.resource.ImageDescriptor; 30 import org.eclipse.ui.IEditorInput; 31 import org.eclipse.ui.IPersistableElement; 32 33 34 53 public class EntryEditorInput implements IEditorInput 54 { 55 56 57 private IEntry entry; 58 59 60 private ISearchResult searchResult; 61 62 63 private IBookmark bookmark; 64 65 66 private static boolean oneInstanceHackEnabled = true; 67 68 69 75 public EntryEditorInput( IEntry entry ) 76 { 77 this.entry = entry; 78 this.searchResult = null; 79 this.bookmark = null; 80 } 81 82 83 89 public EntryEditorInput( ISearchResult searchResult ) 90 { 91 this.entry = null; 92 this.searchResult = searchResult; 93 this.bookmark = null; 94 } 95 96 97 103 public EntryEditorInput( IBookmark bookmark ) 104 { 105 this.entry = null; 106 this.searchResult = null; 107 this.bookmark = bookmark; 108 } 109 110 111 118 public boolean exists() 119 { 120 return false; 121 } 122 123 124 127 public ImageDescriptor getImageDescriptor() 128 { 129 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_ATTRIBUTE ); 130 } 131 132 133 136 public String getName() 137 { 138 return "Entry Editor"; 139 } 140 141 142 145 public String getToolTipText() 146 { 147 return ""; 148 } 149 150 155 public IPersistableElement getPersistable() 156 { 157 return null; 158 } 159 160 161 164 public Object getAdapter( Class adapter ) 165 { 166 return null; 167 } 168 169 170 177 public IEntry getResolvedEntry() 178 { 179 if ( entry != null ) 180 { 181 return entry; 182 } 183 else if ( searchResult != null ) 184 { 185 return searchResult.getEntry(); 186 } 187 else if ( bookmark != null ) 188 { 189 return bookmark.getEntry(); 190 } 191 else 192 { 193 return null; 194 } 195 } 196 197 198 203 public IEntry getEntryInput() 204 { 205 return entry; 206 } 207 208 209 214 public ISearchResult getSearchResultInput() 215 { 216 return searchResult; 217 } 218 219 220 225 public IBookmark getBookmarkInput() 226 { 227 return bookmark; 228 } 229 230 231 236 public Object getInput() 237 { 238 if ( entry != null ) 239 { 240 return entry; 241 } 242 else if ( searchResult != null ) 243 { 244 return searchResult; 245 } 246 else if ( bookmark != null ) 247 { 248 return bookmark; 249 } 250 else 251 { 252 return null; 253 } 254 } 255 256 257 260 public int hashCode() 261 { 262 return getToolTipText().hashCode(); 263 } 264 265 266 271 public boolean equals( Object obj ) 272 { 273 boolean equal; 274 275 if ( oneInstanceHackEnabled ) 276 { 277 equal = ( obj instanceof EntryEditorInput ); 278 } 279 else 280 { 281 if ( obj instanceof EntryEditorInput ) 282 { 283 EntryEditorInput other = ( EntryEditorInput ) obj; 284 if ( this.getInput() == null && other.getInput() == null ) 285 { 286 return true; 287 } 288 else if ( this.getInput() == null || other.getInput() == null ) 289 { 290 return false; 291 } 292 else 293 { 294 equal = other.getInput().equals( this.getInput() ); 295 } 296 } 297 else 298 { 299 equal = false; 300 } 301 } 302 303 return equal; 304 } 305 306 307 314 public static void enableOneInstanceHack( boolean b ) 315 { 316 oneInstanceHackEnabled = b; 317 } 318 319 } 320 | Popular Tags |