Package org.eclipse.core.commands
Class ParameterType
- java.lang.Object
-
- org.eclipse.core.commands.common.EventManager
-
- org.eclipse.core.commands.common.HandleObject
-
- org.eclipse.core.commands.ParameterType
-
- All Implemented Interfaces:
Comparable
,IIdentifiable
public final class ParameterType extends HandleObject implements Comparable
Provides information about the type of a command parameter. Clients can use a parameter type to check if an object matches the type of the parameter with
isCompatible(Object)
and can get anAbstractParameterValueConverter
to convert between objects matching the parameter type and strings that encode the object's identity.A command parameter is not required to declare a type. To determine if a given parameter has a type, check if an
IParameter
implementsITypedParameter
and if so, useITypedParameter.getParameterType()
like this:IParameter parameter = // ... get IParameter from Command if (parameter instanceof ITypedParameter) { ParameterType type = ((ITypedParameter)parameter).getParameterType(); if (type != null) { // this parameter has a ParameterType } }
- Since:
- 3.2
- See Also:
IParameter
,ITypedParameter.getParameterType()
-
-
Field Summary
-
Fields inherited from class org.eclipse.core.commands.common.HandleObject
defined, id, string
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(IParameterTypeListener listener)
Adds a listener to this parameter type that will be notified when its state changes.int
compareTo(Object object)
Compares this parameter type with another object by comparing each of the non-transient attributes.void
define(String type, AbstractParameterValueConverter parameterTypeConverter)
Defines this parameter type, setting the defined property totrue
.AbstractParameterValueConverter
getValueConverter()
Returns the value converter associated with this parameter, if any.boolean
isCompatible(Object value)
Returns whether the provided value is compatible with this parameter type.void
removeListener(IParameterTypeListener listener)
Unregisters listener for changes to properties of this parameter type.String
toString()
The string representation of this parameter type.void
undefine()
Makes this parameter type become undefined.-
Methods inherited from class org.eclipse.core.commands.common.HandleObject
equals, getId, hashCode, isDefined
-
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
-
-
-
-
Method Detail
-
addListener
public final void addListener(IParameterTypeListener listener)
Adds a listener to this parameter type that will be notified when its state changes.- Parameters:
listener
- The listener to be added; must not benull
.
-
compareTo
public final int compareTo(Object object)
Compares this parameter type with another object by comparing each of the non-transient attributes.- Specified by:
compareTo
in interfaceComparable
- Parameters:
object
- The object with which to compare; must be an instance ofParameterType
.- Returns:
- A negative integer, zero or a positive integer, if the object is greater than, equal to or less than this parameter type.
-
define
public final void define(String type, AbstractParameterValueConverter parameterTypeConverter)
Defines this parameter type, setting the defined property to
true
.Notification is sent to all listeners that something has changed.
- Parameters:
type
- a string identifying the Java object type for this parameter type;null
is interpreted as"java.lang.Object"
parameterTypeConverter
- anAbstractParameterValueConverter
to perform string/object conversions for parameter values; may benull
-
getValueConverter
public final AbstractParameterValueConverter getValueConverter() throws NotDefinedException
Returns the value converter associated with this parameter, if any.- Returns:
- The parameter value converter, or
null
if there is no value converter for this parameter. - Throws:
NotDefinedException
- if the parameter type is not currently defined
-
isCompatible
public boolean isCompatible(Object value) throws NotDefinedException
Returns whether the provided value is compatible with this parameter type. An object is compatible with a parameter type if the object is an instance of the class defined as the parameter's type class.- Parameters:
value
- an object to check for compatibility with this parameter type; may benull
.- Returns:
true
if the value is compatible with this type,false
otherwise- Throws:
NotDefinedException
- if the parameter type is not currently defined
-
removeListener
public final void removeListener(IParameterTypeListener listener)
Unregisters listener for changes to properties of this parameter type.- Parameters:
listener
- the instance to unregister. Must not benull
. If an attempt is made to unregister an instance which is not already registered with this instance, no operation is performed.
-
toString
public final String toString()
The string representation of this parameter type. For debugging purposes only. This string should not be shown to an end user.- Specified by:
toString
in classHandleObject
- Returns:
- The string representation; never
null
.
-
undefine
public final void undefine()
Makes this parameter type become undefined. Notification is sent to all listeners.- Specified by:
undefine
in classHandleObject
-
-