dsto.dfc.swt.viewers
Class SelectionBinding

java.lang.Object
  extended by dsto.dfc.swt.viewers.SelectionBinding
All Implemented Interfaces:
org.eclipse.jface.viewers.ISelectionChangedListener

public class SelectionBinding
extends Object
implements org.eclipse.jface.viewers.ISelectionChangedListener

Binds the selected entry/entries of a JFace Viewer to the value of a property on a target object.

Subclasses may override getTargetValue(IStructuredSelection) and translate(Object) to customize behaviour.

Version:
$Revision$
Author:
mpp

Field Summary
protected static int ARRAY
           
protected static int LIST
           
protected  Class multiValueType
          The container type for multi-value properties (null for single value)
protected  Class propertyType
          The type of the property, or type of an element for multi-value properties
protected static int SINGLE
           
protected  Object target
           
protected  String targetProperty
           
protected  int targetType
          One of the TYPE_* constants.
protected  org.eclipse.jface.viewers.Viewer viewer
           
 
Constructor Summary
SelectionBinding(org.eclipse.jface.viewers.Viewer viewer, Object target, String targetProperty)
           
SelectionBinding(org.eclipse.jface.viewers.Viewer viewer, Object target, String targetProperty, boolean allowMultipleValues)
          Create a new instance.
 
Method Summary
protected  boolean compatibleType(Object value)
          Test if a value is a compatible type for the property.
 void dispose()
           
protected  Object getTargetValue(org.eclipse.jface.viewers.IStructuredSelection selection)
          Get the value that should be applied to the target for a given selection.
 void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event)
           
protected  Object translate(Object selectedObject)
          Translate a selected value into the form that the target object expects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SINGLE

protected static final int SINGLE
See Also:
Constant Field Values

LIST

protected static final int LIST
See Also:
Constant Field Values

ARRAY

protected static final int ARRAY
See Also:
Constant Field Values

viewer

protected org.eclipse.jface.viewers.Viewer viewer

target

protected Object target

targetProperty

protected String targetProperty

targetType

protected int targetType
One of the TYPE_* constants.


multiValueType

protected Class multiValueType
The container type for multi-value properties (null for single value)


propertyType

protected Class propertyType
The type of the property, or type of an element for multi-value properties

Constructor Detail

SelectionBinding

public SelectionBinding(org.eclipse.jface.viewers.Viewer viewer,
                        Object target,
                        String targetProperty)

SelectionBinding

public SelectionBinding(org.eclipse.jface.viewers.Viewer viewer,
                        Object target,
                        String targetProperty,
                        boolean allowMultipleValues)
Create a new instance.

Parameters:
viewer - The viewer to read the selection from.
target - The target object to set the value on.
targetProperty - The property (with a setter method) to copy the value to.
allowMultipleValues - True if multiple values can be passed to the property. If true, the property must must be compatible with either java.util.List or Object [].
Method Detail

dispose

public void dispose()

getTargetValue

protected Object getTargetValue(org.eclipse.jface.viewers.IStructuredSelection selection)
Get the value that should be applied to the target for a given selection. Default implementation returns the first element (or null) for single valued properties or the List or Object [] version if multi valued. Subclasses may override.

See Also:
translate(Object)

compatibleType

protected boolean compatibleType(Object value)
Test if a value is a compatible type for the property. Default is to allow null and any value assignable to the property type. Subclasses may override.


translate

protected Object translate(Object selectedObject)
Translate a selected value into the form that the target object expects. Default is no translation. Subclasses may override.


selectionChanged

public void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event)
Specified by:
selectionChanged in interface org.eclipse.jface.viewers.ISelectionChangedListener


Copyright © 2008 Commonwealth of Australia