org.eclipse.jface.commands.PersistentState Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2005, 2015 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jface.commands;
import org.eclipse.core.commands.State;
import org.eclipse.jface.preference.IPreferenceStore;
/**
*
* This is a state that can be made persistent. A state is persisted to a
* preference store.
*
*
* Clients may extend this class.
*
*
* @since 3.2
*/
public abstract class PersistentState extends State {
/**
* Whether this state should be persisted.
*/
private boolean persisted;
/**
* Loads this state from the preference store, given the location at which
* to look. This method must be symmetric with a call to
* {@link #save(IPreferenceStore, String)}.
*
* @param store
* The store from which to read; must not be null
.
* @param preferenceKey
* The key at which the state is stored; must not be
* null
.
*/
public abstract void load(final IPreferenceStore store,
final String preferenceKey);
/**
* Saves this state to the preference store, given the location at which to
* write. This method must be symmetric with a call to
* {@link #load(IPreferenceStore, String)}.
*
* @param store
* The store to which the state should be written; must not be
* null
.
* @param preferenceKey
* The key at which the state should be stored; must not be
* null
.
*/
public abstract void save(final IPreferenceStore store,
final String preferenceKey);
/**
* Sets whether this state should be persisted.
*
* @param persisted
* Whether this state should be persisted.
*/
public void setShouldPersist(final boolean persisted) {
this.persisted = persisted;
}
/**
* Whether this state should be persisted. Subclasses should check this
* method before loading or saving.
*
* @return true
if this state should be persisted;
* false
otherwise.
*/
public boolean shouldPersist() {
return persisted;
}
}