1 11 package org.eclipse.ui.internal.preferences; 12 13 import java.util.Set ; 14 15 import org.eclipse.jface.preference.IPreferenceStore; 16 import org.eclipse.jface.util.IPropertyChangeListener; 17 import org.eclipse.jface.util.PropertyChangeEvent; 18 19 22 public final class PreferenceStoreAdapter extends PropertyMapAdapter { 23 24 private IPreferenceStore store; 25 26 private IPropertyChangeListener listener = new IPropertyChangeListener() { 27 public void propertyChange(PropertyChangeEvent event) { 28 firePropertyChange(event.getProperty()); 29 } 30 }; 31 32 public PreferenceStoreAdapter(IPreferenceStore toConvert) { 33 this.store = toConvert; 34 } 35 36 39 protected void attachListener() { 40 store.addPropertyChangeListener(listener); 41 } 42 43 46 protected void detachListener() { 47 store.removePropertyChangeListener(listener); 48 } 49 50 53 public Set keySet() { 54 throw new UnsupportedOperationException (); 55 } 56 57 60 public Object getValue(String propertyId, Class propertyType) { 61 if (propertyType.isAssignableFrom(String .class)) { 62 return store.getString(propertyId); 63 } 64 65 if (propertyType == Boolean .class) { 66 return store.getBoolean(propertyId) ? Boolean.TRUE : Boolean.FALSE; 67 } 68 69 if (propertyType == Double .class) { 70 return new Double (store.getDouble(propertyId)); 71 } 72 73 if (propertyType == Float .class) { 74 return new Float (store.getFloat(propertyId)); 75 } 76 77 if (propertyType == Integer .class) { 78 return new Integer (store.getInt(propertyId)); 79 } 80 81 if (propertyType == Long .class) { 82 return new Long (store.getLong(propertyId)); 83 } 84 85 return null; 86 } 87 88 91 public boolean propertyExists(String propertyId) { 92 return store.contains(propertyId); 93 } 94 95 98 public void setValue(String propertyId, Object newValue) { 99 if (newValue instanceof String ) { 100 store.setValue(propertyId, (String )newValue); 101 } else if (newValue instanceof Integer ) { 102 store.setValue(propertyId, ((Integer )newValue).intValue()); 103 } else if (newValue instanceof Boolean ) { 104 store.setValue(propertyId, ((Boolean )newValue).booleanValue()); 105 } else if (newValue instanceof Double ) { 106 store.setValue(propertyId, ((Double )newValue).doubleValue()); 107 } else if (newValue instanceof Float ) { 108 store.setValue(propertyId, ((Float )newValue).floatValue()); 109 } else if (newValue instanceof Integer ) { 110 store.setValue(propertyId, ((Integer )newValue).intValue()); 111 } else if (newValue instanceof Long ) { 112 store.setValue(propertyId, ((Long )newValue).longValue()); 113 } 114 } 115 116 } 117 | Popular Tags |