All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.ui.handlers.RegistryRadioState Maven / Gradle / Ivy

Go to download

This plug-in contains the bulk of the Workbench implementation, and depends on JFace, SWT, and Core Runtime. It cannot be used independently from org.eclipse.ui. Workbench client plug-ins should not depend directly on this plug-in.

The newest version!
/*******************************************************************************
 * Copyright (c) 2005, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.ui.handlers;

import java.util.Hashtable;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.jface.commands.RadioState;

/**
 * 

* A radio state that can be read from the registry. This stores a piece of * boolean state information that is grouped with other boolean state to form a * radio group. In a single radio group, there can be at most one state who * value is {@link Boolean#TRUE} all the others must be {@link Boolean#FALSE}. *

*

* When parsing from the registry, this state understands three parameters: * default, which is the default value for this item; * persisted, which is whether the state should be persisted * between sessions; id, which is the identifier of the group to * which this radio handler belongs. The default parameter * defaults to false, and the persisted parameter * defaults to true. If only one parameter is passed (i.e., * using the class name followed by a colon), then it is assumed to be the * id parameter. The id is required for this class * to function properly. *

*

* Clients may instantiate this class, but must not extend. *

* * @since 3.2 */ public final class RegistryRadioState extends RadioState implements IExecutableExtension { /** * Reads the default parameter from the given string. This * converts the string to a boolean, using true as the * default. * * @param defaultString * The string to parse; may be null. */ private final void readDefault(final String defaultString) { if ("true".equalsIgnoreCase(defaultString)) { //$NON-NLS-1$ setValue(Boolean.TRUE); } } /** * Reads the persisted parameter from the given string. This * converts the string to a boolean, using true as the * default. * * @param persistedString * The string to parse; may be null. */ private final void readPersisted(final String persistedString) { if ("false".equalsIgnoreCase(persistedString)) { //$NON-NLS-1$ setShouldPersist(false); } setShouldPersist(true); } public final void setInitializationData( final IConfigurationElement configurationElement, final String propertyName, final Object data) { if (data instanceof String) { // This is the default value. setRadioGroupIdentifier((String) data); setValue(Boolean.FALSE); setShouldPersist(true); } else if (data instanceof Hashtable) { final Hashtable parameters = (Hashtable) data; final Object defaultObject = parameters.get("default"); //$NON-NLS-1$ if (defaultObject instanceof String) { readDefault((String) defaultObject); } final Object persistedObject = parameters.get("persisted"); //$NON-NLS-1$ if (persistedObject instanceof String) { readPersisted((String) persistedObject); } final Object idObject = parameters.get("id"); //$NON-NLS-1$ if (idObject instanceof String) { setRadioGroupIdentifier((String) idObject); } } else { setShouldPersist(true); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy