1 20 21 package org.apache.directory.ldapstudio.browser.core.internal.model; 22 23 24 import org.apache.directory.ldapstudio.browser.core.events.BookmarkUpdateEvent; 25 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry; 26 import org.apache.directory.ldapstudio.browser.core.internal.search.LdapSearchPageScoreComputer; 27 import org.apache.directory.ldapstudio.browser.core.model.BookmarkParameter; 28 import org.apache.directory.ldapstudio.browser.core.model.DN; 29 import org.apache.directory.ldapstudio.browser.core.model.IBookmark; 30 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 31 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 32 import org.eclipse.search.ui.ISearchPageScoreComputer; 33 34 35 41 public class Bookmark implements IBookmark 42 { 43 44 45 private static final long serialVersionUID = 2914726541167255499L; 46 47 48 private IConnection connection; 49 50 51 private BookmarkParameter bookmarkParameter; 52 53 54 private DelegateEntry bookmarkEntry; 55 56 57 60 protected Bookmark() 61 { 62 } 63 64 65 71 public Bookmark( IConnection connection, BookmarkParameter bookmarkParameter ) 72 { 73 this.connection = connection; 74 this.bookmarkParameter = bookmarkParameter; 75 this.bookmarkEntry = new DelegateEntry( connection, bookmarkParameter.getDn() ); 76 } 77 78 79 86 public Bookmark( IConnection connection, DN dn, String name ) 87 { 88 this.connection = connection; 89 this.bookmarkParameter = new BookmarkParameter( dn, name ); 90 this.bookmarkEntry = new DelegateEntry( connection, dn ); 91 } 92 93 94 97 public DN getDn() 98 { 99 return this.bookmarkParameter.getDn(); 100 } 101 102 103 106 public void setDn( DN dn ) 107 { 108 this.bookmarkParameter.setDn( dn ); 109 this.fireBookmarkUpdated( BookmarkUpdateEvent.Detail.BOOKMARK_UPDATED ); 110 } 111 112 113 116 public String getName() 117 { 118 return this.bookmarkParameter.getName(); 119 } 120 121 122 125 public void setName( String name ) 126 { 127 this.bookmarkParameter.setName( name ); 128 this.fireBookmarkUpdated( BookmarkUpdateEvent.Detail.BOOKMARK_UPDATED ); 129 } 130 131 132 135 public Object getAdapter( Class adapter ) 136 { 137 Class <?> clazz = ( Class <?> ) adapter; 138 if ( clazz.isAssignableFrom( ISearchPageScoreComputer.class ) ) 139 { 140 return new LdapSearchPageScoreComputer(); 141 } 142 if ( clazz.isAssignableFrom( IConnection.class ) ) 143 { 144 return getConnection(); 145 } 146 if ( clazz.isAssignableFrom( IEntry.class ) ) 147 { 148 return getEntry(); 149 } 150 if ( clazz.isAssignableFrom( IBookmark.class ) ) 151 { 152 return this; 153 } 154 155 return null; 156 } 157 158 159 private void fireBookmarkUpdated( BookmarkUpdateEvent.Detail detail ) 160 { 161 if ( this.getName() != null && !"".equals( this.getName() ) ) { EventRegistry.fireBookmarkUpdated( new BookmarkUpdateEvent( this, detail ), this ); 163 } 164 } 165 166 167 170 public BookmarkParameter getBookmarkParameter() 171 { 172 return bookmarkParameter; 173 } 174 175 176 179 public void setBookmarkParameter( BookmarkParameter bookmarkParameter ) 180 { 181 this.bookmarkParameter = bookmarkParameter; 182 } 183 184 185 188 public IConnection getConnection() 189 { 190 return this.connection; 191 } 192 193 194 197 public IEntry getEntry() 198 { 199 return this.bookmarkEntry; 200 } 201 202 203 206 public String toString() 207 { 208 return this.getName(); 209 } 210 211 } 212 | Popular Tags |