Package org.eclipse.jface.preference
Class PreferenceMemento
- java.lang.Object
-
- org.eclipse.jface.preference.PreferenceMemento
-
public class PreferenceMemento extends Object
A utility to change and remember preference values and later restore there original value. The first time a preference value is changed its current value is stored. Later you can reset all preference values (which are changed through this class) to the state they had when creating the memento.This class is most useful for testing to prevent leakage of preference changes between individual tests.
- Since:
- 3.18
-
-
Constructor Summary
Constructors Constructor Description PreferenceMemento()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
resetPreferences()
Reset every preference changed by this utility to its state before the first change.<T> void
setValue(IPreferenceStore store, String name, T value)
Set the value for the given preference on the given store.
-
-
-
Method Detail
-
setValue
public <T> void setValue(IPreferenceStore store, String name, T value)
Set the value for the given preference on the given store.The first time this preference is changed its value before change is remembered and can later be restored using
resetPreferences()
.- Type Parameters:
T
- the preference value type. The type must have a correspondingIPreferenceStore
setter.- Parameters:
store
- the preference store to manipulate (notnull
)name
- the name of the preference (notnull
)value
- the new current value of the preference.- Throws:
IllegalArgumentException
- when setting a type which is not supported byIPreferenceStore
- See Also:
IPreferenceStore.setValue(String, double)
,IPreferenceStore.setValue(String, float)
,IPreferenceStore.setValue(String, int)
,IPreferenceStore.setValue(String, long)
,IPreferenceStore.setValue(String, boolean)
,IPreferenceStore.setValue(String, String)
,resetPreferences()
-
resetPreferences
public void resetPreferences()
Reset every preference changed by this utility to its state before the first change. After this the instance can still be used as if it was just created.
-
-