KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > preferences > PreferenceStoreAdapter


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.preferences;
12
13 import java.util.Set JavaDoc;
14
15 import org.eclipse.jface.preference.IPreferenceStore;
16 import org.eclipse.jface.util.IPropertyChangeListener;
17 import org.eclipse.jface.util.PropertyChangeEvent;
18
19 /**
20  * @since 3.1
21  */

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     /* (non-Javadoc)
37      * @see org.eclipse.ui.internal.preferences.PropertyMapAdapter#attachListener()
38      */

39     protected void attachListener() {
40         store.addPropertyChangeListener(listener);
41     }
42
43     /* (non-Javadoc)
44      * @see org.eclipse.ui.internal.preferences.PropertyMapAdapter#detachListener()
45      */

46     protected void detachListener() {
47         store.removePropertyChangeListener(listener);
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.ui.internal.preferences.IPropertyMap#keySet()
52      */

53     public Set JavaDoc keySet() {
54         throw new UnsupportedOperationException JavaDoc();
55     }
56
57     /* (non-Javadoc)
58      * @see org.eclipse.ui.internal.preferences.IPropertyMap#getValue(java.lang.String, java.lang.Class)
59      */

60     public Object JavaDoc getValue(String JavaDoc propertyId, Class JavaDoc propertyType) {
61         if (propertyType.isAssignableFrom(String JavaDoc.class)) {
62             return store.getString(propertyId);
63         }
64         
65         if (propertyType == Boolean JavaDoc.class) {
66             return store.getBoolean(propertyId) ? Boolean.TRUE : Boolean.FALSE;
67         }
68         
69         if (propertyType == Double JavaDoc.class) {
70             return new Double JavaDoc(store.getDouble(propertyId));
71         }
72         
73         if (propertyType == Float JavaDoc.class) {
74             return new Float JavaDoc(store.getFloat(propertyId));
75         }
76         
77         if (propertyType == Integer JavaDoc.class) {
78             return new Integer JavaDoc(store.getInt(propertyId));
79         }
80         
81         if (propertyType == Long JavaDoc.class) {
82             return new Long JavaDoc(store.getLong(propertyId));
83         }
84         
85         return null;
86     }
87
88     /* (non-Javadoc)
89      * @see org.eclipse.ui.internal.preferences.IPropertyMap#propertyExists(java.lang.String)
90      */

91     public boolean propertyExists(String JavaDoc propertyId) {
92         return store.contains(propertyId);
93     }
94
95     /* (non-Javadoc)
96      * @see org.eclipse.ui.internal.preferences.IPropertyMap#setValue(java.lang.String, java.lang.Object)
97      */

98     public void setValue(String JavaDoc propertyId, Object JavaDoc newValue) {
99         if (newValue instanceof String JavaDoc) {
100             store.setValue(propertyId, (String JavaDoc)newValue);
101         } else if (newValue instanceof Integer JavaDoc) {
102             store.setValue(propertyId, ((Integer JavaDoc)newValue).intValue());
103         } else if (newValue instanceof Boolean JavaDoc) {
104             store.setValue(propertyId, ((Boolean JavaDoc)newValue).booleanValue());
105         } else if (newValue instanceof Double JavaDoc) {
106             store.setValue(propertyId, ((Double JavaDoc)newValue).doubleValue());
107         } else if (newValue instanceof Float JavaDoc) {
108             store.setValue(propertyId, ((Float JavaDoc)newValue).floatValue());
109         } else if (newValue instanceof Integer JavaDoc) {
110             store.setValue(propertyId, ((Integer JavaDoc)newValue).intValue());
111         } else if (newValue instanceof Long JavaDoc) {
112             store.setValue(propertyId, ((Long JavaDoc)newValue).longValue());
113         }
114     }
115
116 }
117
Popular Tags