KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > handlers > RegistryRadioState


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.ui.handlers;
13
14 import java.util.Hashtable JavaDoc;
15
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.core.runtime.IExecutableExtension;
18 import org.eclipse.jface.commands.RadioState;
19
20 /**
21  * <p>
22  * A radio state that can be read from the registry. This stores a piece of
23  * boolean state information that is grouped with other boolean state to form a
24  * radio group. In a single radio group, there can be at most one state who
25  * value is {@link Boolean#TRUE} all the others must be {@link Boolean#FALSE}.
26  * </p>
27  * <p>
28  * When parsing from the registry, this state understands three parameters:
29  * <code>default</code>, which is the default value for this item;
30  * <code>persisted</code>, which is whether the state should be persisted
31  * between sessions; <code>id</code>, which is the identifier of the group to
32  * which this radio handler belongs. The <code>default</code> parameter
33  * defaults to <code>false</code>, and the <code>persisted</code> parameter
34  * defaults to <code>true</code>. If only one parameter is passed (i.e.,
35  * using the class name followed by a colon), then it is assumed to be the
36  * <code>id</code> parameter. The <code>id</code> is required for this class
37  * to function properly.
38  * </p>
39  * <p>
40  * Clients may instantiate this class, but must not extend.
41  * </p>
42  *
43  * @since 3.2
44  */

45 public final class RegistryRadioState extends RadioState implements
46         IExecutableExtension {
47
48     /**
49      * Reads the <code>default</code> parameter from the given string. This
50      * converts the string to a boolean, using <code>true</code> as the
51      * default.
52      *
53      * @param defaultString
54      * The string to parse; may be <code>null</code>.
55      */

56     private final void readDefault(final String JavaDoc defaultString) {
57         if ("true".equalsIgnoreCase(defaultString)) { //$NON-NLS-1$
58
setValue(Boolean.TRUE);
59         }
60     }
61
62     /**
63      * Reads the <code>persisted</code> parameter from the given string. This
64      * converts the string to a boolean, using <code>true</code> as the
65      * default.
66      *
67      * @param persistedString
68      * The string to parse; may be <code>null</code>.
69      */

70     private final void readPersisted(final String JavaDoc persistedString) {
71         if ("false".equalsIgnoreCase(persistedString)) { //$NON-NLS-1$
72
setShouldPersist(false);
73         }
74
75         setShouldPersist(true);
76     }
77
78     public final void setInitializationData(
79             final IConfigurationElement configurationElement,
80             final String JavaDoc propertyName, final Object JavaDoc data) {
81         if (data instanceof String JavaDoc) {
82             // This is the default value.
83
setRadioGroupIdentifier((String JavaDoc) data);
84             setValue(Boolean.FALSE);
85             setShouldPersist(true);
86
87         } else if (data instanceof Hashtable JavaDoc) {
88             final Hashtable JavaDoc parameters = (Hashtable JavaDoc) data;
89
90             final Object JavaDoc defaultObject = parameters.get("default"); //$NON-NLS-1$
91
if (defaultObject instanceof String JavaDoc) {
92                 readDefault((String JavaDoc) defaultObject);
93             }
94
95             final Object JavaDoc persistedObject = parameters.get("persisted"); //$NON-NLS-1$
96
if (persistedObject instanceof String JavaDoc) {
97                 readPersisted((String JavaDoc) persistedObject);
98             }
99
100             final Object JavaDoc idObject = parameters.get("id"); //$NON-NLS-1$
101
if (idObject instanceof String JavaDoc) {
102                 setRadioGroupIdentifier((String JavaDoc) idObject);
103             }
104
105         } else {
106             setShouldPersist(true);
107             
108         }
109     }
110 }
111
Popular Tags