KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > menus > TextState


1 /*******************************************************************************
2  * Copyright (c) 2005, 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
12 package org.eclipse.jface.menus;
13
14 import org.eclipse.core.commands.INamedHandleStateIds;
15 import org.eclipse.jface.commands.PersistentState;
16 import org.eclipse.jface.preference.IPreferenceStore;
17
18 /**
19  * <p>
20  * A piece of state carrying a single {@link String}.
21  * </p>
22  * <p>
23  * If this state is registered using {@link INamedHandleStateIds#NAME} or
24  * {@link INamedHandleStateIds#DESCRIPTION}, then this allows the handler to
25  * communicate a textual change for a given command. This is typically used by
26  * graphical applications to allow more specific text to be displayed in the
27  * menus. For example, "Undo" might become "Undo Typing" through the use of a
28  * {@link TextState}.
29  * </p>
30  * <p>
31  * Clients may instantiate this class, but must not extend.
32  * </p>
33  *
34  * @since 3.2
35  * @see INamedHandleStateIds
36  */

37 public class TextState extends PersistentState {
38
39     public final void load(final IPreferenceStore store,
40             final String JavaDoc preferenceKey) {
41         final String JavaDoc value = store.getString(preferenceKey);
42         setValue(value);
43     }
44
45     public final void save(final IPreferenceStore store,
46             final String JavaDoc preferenceKey) {
47         final Object JavaDoc value = getValue();
48         if (value instanceof String JavaDoc) {
49             store.setValue(preferenceKey, ((String JavaDoc) value));
50         }
51     }
52
53     public void setValue(final Object JavaDoc value) {
54         if (!(value instanceof String JavaDoc)) {
55             throw new IllegalArgumentException JavaDoc(
56                     "TextState takes a String as a value"); //$NON-NLS-1$
57
}
58
59         super.setValue(value);
60     }
61
62 }
63
Popular Tags