1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.entry; 22 23 24 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin; 25 import org.apache.directory.ldapstudio.browser.core.model.DN; 26 import org.apache.directory.ldapstudio.browser.core.model.IBookmark; 27 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 28 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 29 import org.apache.directory.ldapstudio.browser.core.model.IRootDSE; 30 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 31 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult; 32 import org.apache.directory.ldapstudio.browser.core.model.NameException; 33 import org.eclipse.ui.IEditorPart; 34 import org.eclipse.ui.IMemento; 35 import org.eclipse.ui.INavigationLocation; 36 import org.eclipse.ui.NavigationLocation; 37 38 39 45 public class EntryEditorNavigationLocation extends NavigationLocation 46 { 47 48 53 EntryEditorNavigationLocation( EntryEditor editor ) 54 { 55 super( editor ); 56 } 57 58 59 62 public String getText() 63 { 64 EntryEditorInput eei = getEntryEditorInput(); 65 if ( eei != null ) 66 { 67 if ( eei.getEntryInput() != null ) 68 { 69 if ( eei.getEntryInput() instanceof IRootDSE ) 70 { 71 return "Root DSE"; 72 } 73 else 74 { 75 return "Entry " + eei.getEntryInput().getDn().toString(); 76 } 77 } 78 else if ( eei.getSearchResultInput() != null ) 79 { 80 if ( eei.getSearchResultInput() instanceof IRootDSE ) 81 { 82 return "Root DSE"; 83 } 84 else 85 { 86 return "Search Result " + eei.getSearchResultInput().getDn().toString(); 87 } 88 } 89 else if ( eei.getBookmarkInput() != null ) 90 { 91 if ( eei.getBookmarkInput() instanceof IRootDSE ) 92 { 93 return "Root DSE"; 94 } 95 else 96 { 97 return "Bookmark " + eei.getBookmarkInput().getDn().toString(); 98 } 99 } 100 } 101 return super.getText(); 102 } 103 104 105 108 public void saveState( IMemento memento ) 109 { 110 EntryEditorInput eei = getEntryEditorInput(); 111 if ( eei != null ) 112 { 113 if ( eei.getEntryInput() != null ) 114 { 115 IEntry entry = eei.getEntryInput(); 116 memento.putString( "TYPE", "IEntry" ); 117 memento.putString( "DN", entry.getDn().toString() ); 118 memento.putString( "CONNECTION", entry.getConnection().getName() ); 119 } 120 else if ( eei.getSearchResultInput() != null ) 121 { 122 ISearchResult searchResult = eei.getSearchResultInput(); 123 memento.putString( "TYPE", "ISearchResult" ); 124 memento.putString( "DN", searchResult.getDn().toString() ); 125 memento.putString( "SEARCH", searchResult.getSearch().getName() ); 126 memento.putString( "CONNECTION", searchResult.getSearch().getConnection().getName() ); 127 } 128 else if ( eei.getBookmarkInput() != null ) 129 { 130 IBookmark bookmark = eei.getBookmarkInput(); 131 memento.putString( "TYPE", "IBookmark" ); 132 memento.putString( "BOOKMARK", bookmark.getName() ); 133 memento.putString( "CONNECTION", bookmark.getConnection().getName() ); 134 } 135 } 136 137 } 138 139 140 143 public void restoreState( IMemento memento ) 144 { 145 try 146 { 147 String type = memento.getString( "TYPE" ); 148 if ( "IEntry".equals( type ) ) 149 { 150 IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection( 151 memento.getString( "CONNECTION" ) ); 152 DN dn = new DN( memento.getString( "DN" ) ); 153 IEntry entry = connection.getEntryFromCache( dn ); 154 super.setInput( new EntryEditorInput( entry ) ); 155 } 156 else if ( "ISearchResult".equals( type ) ) 157 { 158 IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection( 159 memento.getString( "CONNECTION" ) ); 160 ISearch search = connection.getSearchManager().getSearch( memento.getString( "SEARCH" ) ); 161 ISearchResult[] searchResults = search.getSearchResults(); 162 DN dn = new DN( memento.getString( "DN" ) ); 163 for ( int i = 0; i < searchResults.length; i++ ) 164 { 165 if ( dn.equals( searchResults[i].getDn() ) ) 166 { 167 super.setInput( new EntryEditorInput( searchResults[i] ) ); 168 break; 169 } 170 } 171 } 172 else if ( "IBookmark".equals( type ) ) 173 { 174 IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection( 175 memento.getString( "CONNECTION" ) ); 176 IBookmark bookmark = connection.getBookmarkManager().getBookmark( memento.getString( "BOOKMARK" ) ); 177 super.setInput( new EntryEditorInput( bookmark ) ); 178 } 179 } 180 catch ( NameException e ) 181 { 182 e.printStackTrace(); 183 } 184 185 } 186 187 188 191 public void restoreLocation() 192 { 193 IEditorPart editorPart = getEditorPart(); 194 if ( editorPart != null && editorPart instanceof EntryEditor ) 195 { 196 EntryEditor entryEditor = ( EntryEditor ) editorPart; 197 entryEditor.setInput( ( EntryEditorInput ) getInput() ); 198 } 199 } 200 201 202 205 public boolean mergeInto( INavigationLocation currentLocation ) 206 { 207 if ( currentLocation == null ) 208 { 209 return false; 210 } 211 212 if ( getClass() != currentLocation.getClass() ) 213 { 214 return false; 215 } 216 217 EntryEditorNavigationLocation location = ( EntryEditorNavigationLocation ) currentLocation; 218 Object other = location.getEntryEditorInput().getInput(); 219 Object entry = getEntryEditorInput().getInput(); 220 221 if ( other == null && entry == null ) 222 { 223 return true; 224 } 225 else if ( other == null || entry == null ) 226 { 227 return false; 228 } 229 else 230 { 231 return entry.equals( other ); 232 } 233 } 234 235 236 239 public void update() 240 { 241 } 242 243 244 249 private EntryEditorInput getEntryEditorInput() 250 { 251 252 Object editorInput = getInput(); 253 if ( editorInput != null && editorInput instanceof EntryEditorInput ) 254 { 255 EntryEditorInput entryEditorInput = ( EntryEditorInput ) editorInput; 256 return entryEditorInput; 257 } 258 259 return null; 260 } 261 262 263 266 public String toString() 267 { 268 return "" + getEntryEditorInput().getInput(); 269 } 270 271 } 272 | Popular Tags |