1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.schemabrowser; 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.schema.AttributeTypeDescription; 27 import org.apache.directory.ldapstudio.browser.core.model.schema.LdapSyntaxDescription; 28 import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleDescription; 29 import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleUseDescription; 30 import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription; 31 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaPart; 32 import org.eclipse.ui.IEditorPart; 33 import org.eclipse.ui.IMemento; 34 import org.eclipse.ui.INavigationLocation; 35 import org.eclipse.ui.NavigationLocation; 36 37 38 44 public class SchemaBrowserNavigationLocation extends NavigationLocation 45 { 46 47 52 SchemaBrowserNavigationLocation( SchemaBrowser schemaBrowser ) 53 { 54 super( schemaBrowser ); 55 } 56 57 58 61 public String getText() 62 { 63 SchemaPart schemaElement = getSchemElement(); 64 if ( schemaElement != null ) 65 { 66 if(schemaElement instanceof ObjectClassDescription) 67 { 68 return "Object Class " + schemaElement.toString(); 69 } 70 else if(schemaElement instanceof AttributeTypeDescription ) 71 { 72 return "Attribute Type " + schemaElement.toString(); 73 } 74 else if(schemaElement instanceof LdapSyntaxDescription ) 75 { 76 return "Syntax " + schemaElement.toString(); 77 } 78 else if(schemaElement instanceof MatchingRuleDescription) 79 { 80 return "Matching Rule " + schemaElement.toString(); 81 } 82 else if(schemaElement instanceof MatchingRuleUseDescription ) 83 { 84 return "Matching Rule Use " + schemaElement.toString(); 85 } 86 else 87 { 88 return schemaElement.getNumericOID(); 89 } 90 } 91 else 92 { 93 return super.getText(); 94 } 95 } 96 97 98 101 public void saveState( IMemento memento ) 102 { 103 IConnection connection = getConnection(); 104 SchemaPart schemaElement = getSchemElement(); 105 memento.putString( "CONNECTION", connection.getName() ); 106 memento.putString( "SCHEMAELEMENTYPE", schemaElement.getClass().getName() ); 107 memento.putString( "SCHEMAELEMENTOID", schemaElement.getNumericOID() ); 108 } 109 110 111 114 public void restoreState( IMemento memento ) 115 { 116 IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection( 117 memento.getString( "CONNECTION" ) ); 118 String schemaElementType = memento.getString( "SCHEMAELEMENTYPE" ); 119 String schemaElementOid = memento.getString( "SCHEMAELEMENTOID" ); 120 SchemaPart schemaElement = null; 121 if(ObjectClassDescription.class.getName().equals( schemaElementType ) ) 122 { 123 schemaElement = connection.getSchema().getObjectClassDescription( schemaElementOid ); 124 } 125 else if(AttributeTypeDescription.class.getName().equals( schemaElementType ) ) 126 { 127 schemaElement = connection.getSchema().getAttributeTypeDescription( schemaElementOid ); 128 } 129 else if(LdapSyntaxDescription.class.getName().equals( schemaElementType ) ) 130 { 131 schemaElement = connection.getSchema().getLdapSyntaxDescription( schemaElementOid ); 132 } 133 else if(MatchingRuleDescription.class.getName().equals( schemaElementType ) ) 134 { 135 schemaElement = connection.getSchema().getMatchingRuleDescription( schemaElementOid ); 136 } 137 else if(MatchingRuleUseDescription.class.getName().equals( schemaElementType ) ) 138 { 139 schemaElement = connection.getSchema().getMatchingRuleUseDescription( schemaElementOid ); 140 } 141 142 super.setInput( new SchemaBrowserInput( connection, schemaElement ) ); 143 } 144 145 146 149 public void restoreLocation() 150 { 151 IEditorPart editorPart = getEditorPart(); 152 if ( editorPart != null && editorPart instanceof SchemaBrowser ) 153 { 154 SchemaBrowser schemaBrowser = ( SchemaBrowser ) editorPart; 155 Object input = getInput(); 156 if(input != null && input instanceof SchemaBrowserInput) 157 { 158 SchemaBrowserInput sbi = (SchemaBrowserInput)input; 159 if(sbi.getConnection() != null && sbi.getSchemaElement() != null) 160 { 161 schemaBrowser.setInput( sbi ); 162 } 163 } 164 } 165 } 166 167 168 171 public boolean mergeInto( INavigationLocation currentLocation ) 172 { 173 if ( currentLocation == null ) 174 { 175 return false; 176 } 177 178 if ( getClass() != currentLocation.getClass() ) 179 { 180 return false; 181 } 182 183 SchemaBrowserNavigationLocation location = ( SchemaBrowserNavigationLocation ) currentLocation; 184 SchemaPart other = location.getSchemElement(); 185 SchemaPart element = getSchemElement(); 186 187 if ( other == null && element == null ) 188 { 189 return true; 190 } 191 else if ( other == null || element == null ) 192 { 193 return false; 194 } 195 else 196 { 197 return element.equals( other ); 198 } 199 } 200 201 202 205 public void update() 206 { 207 } 208 209 210 215 private SchemaPart getSchemElement() 216 { 217 218 Object editorInput = getInput(); 219 if ( editorInput != null && editorInput instanceof SchemaBrowserInput ) 220 { 221 SchemaBrowserInput schemaBrowserInput = ( SchemaBrowserInput ) editorInput; 222 SchemaPart schemaElement = schemaBrowserInput.getSchemaElement(); 223 if ( schemaElement != null ) 224 { 225 return schemaElement; 226 } 227 } 228 229 return null; 230 } 231 232 233 238 private IConnection getConnection() 239 { 240 241 Object editorInput = getInput(); 242 if ( editorInput != null && editorInput instanceof SchemaBrowserInput ) 243 { 244 SchemaBrowserInput schemaBrowserInput = ( SchemaBrowserInput ) editorInput; 245 return schemaBrowserInput.getConnection(); 246 } 247 248 return null; 249 } 250 251 252 255 public String toString() 256 { 257 return "" + getSchemElement(); 258 } 259 260 } 261 | Popular Tags |