1 20 21 package org.apache.directory.ldapstudio.browser.common; 22 23 24 import java.util.HashMap ; 25 import java.util.Map ; 26 27 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeValueProviderRelation; 28 import org.apache.directory.ldapstudio.browser.core.model.schema.SyntaxValueProviderRelation; 29 import org.apache.directory.ldapstudio.browser.core.utils.Utils; 30 31 import org.eclipse.jface.preference.IPreferenceStore; 32 33 34 40 public class ValueEditorsPreferences 41 { 42 43 44 private Map <String , String > attributeValueEditorCache; 45 46 47 private Map <String , String > syntaxValueEditorCache; 48 49 50 56 public Map getAttributeValueEditorMap() 57 { 58 if ( attributeValueEditorCache == null ) 59 { 60 attributeValueEditorCache = new HashMap <String , String >(); 61 AttributeValueProviderRelation[] relations = getAttributeValueProviderRelations(); 62 for ( int i = 0; i < relations.length; i++ ) 63 { 64 if ( relations[i].getAttributeNumericOidOrType() != null ) 65 { 66 attributeValueEditorCache.put( relations[i].getAttributeNumericOidOrType() 67 .toLowerCase(), relations[i].getValueProviderClassname() ); 68 } 69 } 70 } 71 return attributeValueEditorCache; 72 } 73 74 75 81 public AttributeValueProviderRelation[] getAttributeValueProviderRelations() 82 { 83 AttributeValueProviderRelation[] avpr = ( AttributeValueProviderRelation[] ) load( BrowserCommonConstants.PREFERENCE_ATTRIBUTE_VALUEPROVIDER_RELATIONS ); 84 return avpr; 85 } 86 87 88 94 public void setAttributeValueProviderRelations( AttributeValueProviderRelation[] attributeValueProviderRelations ) 95 { 96 store( BrowserCommonConstants.PREFERENCE_ATTRIBUTE_VALUEPROVIDER_RELATIONS, attributeValueProviderRelations ); 97 attributeValueEditorCache = null; 98 } 99 100 101 107 public AttributeValueProviderRelation[] getDefaultAttributeValueProviderRelations() 108 { 109 AttributeValueProviderRelation[] avpr = ( AttributeValueProviderRelation[] ) loadDefault( BrowserCommonConstants.PREFERENCE_ATTRIBUTE_VALUEPROVIDER_RELATIONS ); 110 return avpr; 111 } 112 113 114 120 public void setDefaultAttributeValueProviderRelations( 121 AttributeValueProviderRelation[] attributeValueProviderRelations ) 122 { 123 storeDefault( BrowserCommonConstants.PREFERENCE_ATTRIBUTE_VALUEPROVIDER_RELATIONS, attributeValueProviderRelations ); 124 } 125 126 127 128 134 public Map getSyntaxValueEditorMap() 135 { 136 if ( syntaxValueEditorCache == null ) 137 { 138 syntaxValueEditorCache = new HashMap <String , String >(); 139 SyntaxValueProviderRelation[] relations = getSyntaxValueProviderRelations(); 140 for ( int i = 0; i < relations.length; i++ ) 141 { 142 if ( relations[i].getSyntaxOID() != null ) 143 { 144 syntaxValueEditorCache.put( relations[i].getSyntaxOID().toLowerCase(), relations[i] 145 .getValueProviderClassname() ); 146 } 147 } 148 } 149 return syntaxValueEditorCache; 150 } 151 152 153 159 public void setSyntaxValueProviderRelations( SyntaxValueProviderRelation[] syntaxValueProviderRelations ) 160 { 161 store( BrowserCommonConstants.PREFERENCE_SYNTAX_VALUEPROVIDER_RELATIONS, syntaxValueProviderRelations ); 162 syntaxValueEditorCache = null; 163 } 164 165 166 172 public SyntaxValueProviderRelation[] getSyntaxValueProviderRelations() 173 { 174 SyntaxValueProviderRelation[] svpr = ( SyntaxValueProviderRelation[] ) load( BrowserCommonConstants.PREFERENCE_SYNTAX_VALUEPROVIDER_RELATIONS ); 175 return svpr; 176 } 177 178 179 185 public SyntaxValueProviderRelation[] getDefaultSyntaxValueProviderRelations() 186 { 187 SyntaxValueProviderRelation[] svpr = ( SyntaxValueProviderRelation[] ) loadDefault( BrowserCommonConstants.PREFERENCE_SYNTAX_VALUEPROVIDER_RELATIONS ); 188 return svpr; 189 } 190 191 192 198 public void setDefaultSyntaxValueProviderRelations( SyntaxValueProviderRelation[] syntaxValueProviderRelations ) 199 { 200 storeDefault( BrowserCommonConstants.PREFERENCE_SYNTAX_VALUEPROVIDER_RELATIONS, syntaxValueProviderRelations ); 201 } 202 203 204 212 private static Object load( String key ) 213 { 214 IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); 215 String s = store.getString( key ); 216 return Utils.deserialize( s ); 217 } 218 219 220 228 private static void store( String key, Object o ) 229 { 230 IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); 231 String s = Utils.serialize( o ); 232 store.setValue( key, s ); 233 } 234 235 236 244 private static Object loadDefault( String key ) 245 { 246 IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); 247 String s = store.getDefaultString( key ); 248 return Utils.deserialize( s ); 249 } 250 251 252 260 private static void storeDefault( String key, Object o ) 261 { 262 IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); 263 String s = Utils.serialize( o ); 264 store.setDefault( key, s ); 265 } 266 } 267 | Popular Tags |