001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.preferences;
011:
012: import org.eclipse.core.runtime.ListenerList;
013:
014: import org.eclipse.jface.preference.IPreferenceStore;
015: import org.eclipse.jface.util.IPropertyChangeListener;
016: import org.eclipse.jface.util.PropertyChangeEvent;
017:
018: /**
019: * Mockup preference store, for registering listeners and firing events,
020: * without being an actual store.
021: * <p>
022: * All methods except firing, adding and removing listeners throw
023: * an {@link java.lang.UnsupportedOperationException}.
024: * </p>
025: *
026: * @since 3.0
027: */
028: public class MockupPreferenceStore implements IPreferenceStore {
029:
030: /** Listeners on this store */
031: private ListenerList fListeners = new ListenerList(
032: ListenerList.IDENTITY);
033:
034: /**
035: * {@inheritDoc}
036: */
037: public void addPropertyChangeListener(
038: IPropertyChangeListener listener) {
039: fListeners.add(listener);
040: }
041:
042: /**
043: * {@inheritDoc}
044: */
045: public void removePropertyChangeListener(
046: IPropertyChangeListener listener) {
047: fListeners.remove(listener);
048: }
049:
050: /**
051: * {@inheritDoc}
052: */
053: public boolean contains(String name) {
054: throw new UnsupportedOperationException();
055: }
056:
057: /**
058: * {@inheritDoc}
059: */
060: public void firePropertyChangeEvent(String name, Object oldValue,
061: Object newValue) {
062: firePropertyChangeEvent(this , name, oldValue, newValue);
063: }
064:
065: /**
066: * Fires a property change event with the given source, property name, old and new value. Used
067: * when the event source should be different from this mockup preference store.
068: * @param source The event source
069: * @param name The property name
070: * @param oldValue The property's old value
071: * @param newValue The property's new value
072: */
073: public void firePropertyChangeEvent(Object source, String name,
074: Object oldValue, Object newValue) {
075: PropertyChangeEvent event = new PropertyChangeEvent(source,
076: name, oldValue, newValue);
077: Object[] listeners = fListeners.getListeners();
078: for (int i = 0; i < listeners.length; i++)
079: ((IPropertyChangeListener) listeners[i])
080: .propertyChange(event);
081: }
082:
083: /**
084: * {@inheritDoc}
085: */
086: public boolean getBoolean(String name) {
087: throw new UnsupportedOperationException();
088: }
089:
090: /**
091: * {@inheritDoc}
092: */
093: public boolean getDefaultBoolean(String name) {
094: throw new UnsupportedOperationException();
095: }
096:
097: /**
098: * {@inheritDoc}
099: */
100: public double getDefaultDouble(String name) {
101: throw new UnsupportedOperationException();
102: }
103:
104: /**
105: * {@inheritDoc}
106: */
107: public float getDefaultFloat(String name) {
108: throw new UnsupportedOperationException();
109: }
110:
111: /**
112: * {@inheritDoc}
113: */
114: public int getDefaultInt(String name) {
115: throw new UnsupportedOperationException();
116: }
117:
118: /**
119: * {@inheritDoc}
120: */
121: public long getDefaultLong(String name) {
122: throw new UnsupportedOperationException();
123: }
124:
125: /**
126: * {@inheritDoc}
127: */
128: public String getDefaultString(String name) {
129: throw new UnsupportedOperationException();
130: }
131:
132: /**
133: * {@inheritDoc}
134: */
135: public double getDouble(String name) {
136: throw new UnsupportedOperationException();
137: }
138:
139: /**
140: * {@inheritDoc}
141: */
142: public float getFloat(String name) {
143: throw new UnsupportedOperationException();
144: }
145:
146: /**
147: * {@inheritDoc}
148: */
149: public int getInt(String name) {
150: throw new UnsupportedOperationException();
151: }
152:
153: /**
154: * {@inheritDoc}
155: */
156: public long getLong(String name) {
157: throw new UnsupportedOperationException();
158: }
159:
160: /**
161: * {@inheritDoc}
162: */
163: public String getString(String name) {
164: throw new UnsupportedOperationException();
165: }
166:
167: /**
168: * {@inheritDoc}
169: */
170: public boolean isDefault(String name) {
171: throw new UnsupportedOperationException();
172: }
173:
174: /**
175: * {@inheritDoc}
176: */
177: public boolean needsSaving() {
178: throw new UnsupportedOperationException();
179: }
180:
181: /**
182: * {@inheritDoc}
183: */
184: public void putValue(String name, String value) {
185: throw new UnsupportedOperationException();
186: }
187:
188: /**
189: * {@inheritDoc}
190: */
191: public void setDefault(String name, double value) {
192: throw new UnsupportedOperationException();
193: }
194:
195: /**
196: * {@inheritDoc}
197: */
198: public void setDefault(String name, float value) {
199: throw new UnsupportedOperationException();
200: }
201:
202: /**
203: * {@inheritDoc}
204: */
205: public void setDefault(String name, int value) {
206: throw new UnsupportedOperationException();
207: }
208:
209: /**
210: * {@inheritDoc}
211: */
212: public void setDefault(String name, long value) {
213: throw new UnsupportedOperationException();
214: }
215:
216: /**
217: * {@inheritDoc}
218: */
219: public void setDefault(String name, String defaultObject) {
220: throw new UnsupportedOperationException();
221: }
222:
223: /**
224: * {@inheritDoc}
225: */
226: public void setDefault(String name, boolean value) {
227: throw new UnsupportedOperationException();
228: }
229:
230: /**
231: * {@inheritDoc}
232: */
233: public void setToDefault(String name) {
234: throw new UnsupportedOperationException();
235: }
236:
237: /**
238: * {@inheritDoc}
239: */
240: public void setValue(String name, double value) {
241: throw new UnsupportedOperationException();
242: }
243:
244: /**
245: * {@inheritDoc}
246: */
247: public void setValue(String name, float value) {
248: throw new UnsupportedOperationException();
249: }
250:
251: /**
252: * {@inheritDoc}
253: */
254: public void setValue(String name, int value) {
255: throw new UnsupportedOperationException();
256: }
257:
258: /**
259: * {@inheritDoc}
260: */
261: public void setValue(String name, long value) {
262: throw new UnsupportedOperationException();
263: }
264:
265: /**
266: * {@inheritDoc}
267: */
268: public void setValue(String name, String value) {
269: throw new UnsupportedOperationException();
270: }
271:
272: /**
273: * {@inheritDoc}
274: */
275: public void setValue(String name, boolean value) {
276: throw new UnsupportedOperationException();
277: }
278:
279: }
|