1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.searchresult; 22 23 24 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin; 25 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 26 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 27 import org.eclipse.ui.IEditorPart; 28 import org.eclipse.ui.IMemento; 29 import org.eclipse.ui.INavigationLocation; 30 import org.eclipse.ui.NavigationLocation; 31 32 33 39 public class SearchResultEditorNavigationLocation extends NavigationLocation 40 { 41 42 47 SearchResultEditorNavigationLocation( SearchResultEditor editor ) 48 { 49 super( editor ); 50 } 51 52 53 56 public String getText() 57 { 58 ISearch search = getSearch(); 59 if ( search != null ) 60 { 61 return "Search " + search.getName(); 62 } 63 else 64 { 65 return super.getText(); 66 } 67 } 68 69 70 73 public void saveState( IMemento memento ) 74 { 75 ISearch search = getSearch(); 76 memento.putString( "SEARCH", search.getName() ); 77 memento.putString( "CONNECTION", search.getConnection().getName() ); 78 } 79 80 81 84 public void restoreState( IMemento memento ) 85 { 86 IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection( 87 memento.getString( "CONNECTION" ) ); 88 ISearch search = connection.getSearchManager().getSearch( memento.getString( "SEARCH" ) ); 89 super.setInput( new SearchResultEditorInput( search ) ); 90 } 91 92 93 96 public void restoreLocation() 97 { 98 IEditorPart editorPart = getEditorPart(); 99 if ( editorPart != null && editorPart instanceof SearchResultEditor ) 100 { 101 SearchResultEditor searchResultEditor = ( SearchResultEditor ) editorPart; 102 searchResultEditor.setInput( ( SearchResultEditorInput ) getInput() ); 103 } 104 } 105 106 107 110 public boolean mergeInto( INavigationLocation currentLocation ) 111 { 112 if ( currentLocation == null ) 113 { 114 return false; 115 } 116 117 if ( getClass() != currentLocation.getClass() ) 118 { 119 return false; 120 } 121 122 SearchResultEditorNavigationLocation location = ( SearchResultEditorNavigationLocation ) currentLocation; 123 ISearch other = location.getSearch(); 124 ISearch search = getSearch(); 125 126 if ( other == null && search == null ) 127 { 128 return true; 129 } 130 else if ( other == null || search == null ) 131 { 132 return false; 133 } 134 else 135 { 136 return search.equals( other ); 137 } 138 } 139 140 141 144 public void update() 145 { 146 } 147 148 149 154 private ISearch getSearch() 155 { 156 157 Object editorInput = getInput(); 158 if ( editorInput != null && editorInput instanceof SearchResultEditorInput ) 159 { 160 SearchResultEditorInput searchResultEditorInput = ( SearchResultEditorInput ) editorInput; 161 ISearch search = searchResultEditorInput.getSearch(); 162 if ( search != null ) 163 { 164 return search; 165 } 166 } 167 168 return null; 169 } 170 171 172 175 public String toString() 176 { 177 return "" + getSearch(); 178 } 179 180 } 181 | Popular Tags |