org.eclipse.emf.edit.provider
Class ItemProviderAdapter

java.lang.Object
  |
  +--org.eclipse.emf.common.notify.impl.AdapterImpl
        |
        +--org.eclipse.emf.edit.provider.ItemProviderAdapter
All Implemented Interfaces:
Adapter, CreateChildCommand.Helper, IChangeNotifier, IDisposable, ResourceLocator
Direct Known Subclasses:
EObjectItemProvider, EStringToStringMapEntryItemProvider, GenBaseItemProvider, MappingItemProviderAdapter, ReflectiveItemProvider, ResourceItemProvider, ResourceSetItemProvider, TreeNodeItemProvider

public class ItemProviderAdapter
extends AdapterImpl
implements IChangeNotifier, IDisposable, CreateChildCommand.Helper, ResourceLocator

This adapter implementation provides a convenient reusable base for adapters that will be used as item providers. Default implementations for the following interfaces are provided: IItemLabelProvider, IItemPropertySource, IStructuredItemContentProvider, ITreeItemContentProvider, and IEditingDomainItemProvider. Also, IUpdateableItemText.getUpdateableText(java.lang.Object) is implemented to delegate to getText(java.lang.Object); often the editable text will be just the text, in which case this is a good default implementation.


Field Summary
protected  AdapterFactory adapterFactory
          This keeps track of the adapter factory that created this adaptor.
protected  IChangeNotifier changeNotifier
          This is used to implement IChangeNotifier.
protected  java.util.List childrenReferences
          This is used to store all the children references.
protected  java.util.List itemPropertyDescriptors
          This is used to store all the property descriptors.
protected  java.util.Collection targets
          This keeps track of all the targets to which this adapter is set.
 
Fields inherited from class org.eclipse.emf.common.notify.impl.AdapterImpl
target
 
Constructor Summary
ItemProviderAdapter(AdapterFactory adapterFactory)
          An instance is created from an adapter factory.
 
Method Summary
 void addListener(INotifyChangedListener listener)
          This adds another listener.
protected  void collectNewChildDescriptors(java.util.Collection newChildDescriptors, java.lang.Object object)
          This adds to newChildDescriptors, a collection of CommandParameters, parameters for possible children of the specified object, when viewed as an instance of the type for which this is an item provider.
protected  Command createAddCommand(EditingDomain domain, EObject owner, EReference feature, java.util.Collection collection, int index)
          This creates a primitive AddCommand.
protected  CommandParameter createChildParameter(java.lang.Object feature, java.lang.Object child)
          This is a convenience method that creates a CommandParameter for a given parent feature and child object.
 Command createCommand(java.lang.Object object, EditingDomain domain, java.lang.Class commandClass, CommandParameter commandParameter)
          This implements delegated command creation for the given object.
protected  Command createCopyCommand(EditingDomain domain, EObject owner, CopyCommand.Helper helper)
          This creates a primitive CopyCommand.
protected  Command createCreateChildCommand(EditingDomain domain, EObject owner, EReference feature, EObject value, int index, java.util.Collection collection)
          This creates a primitive CreateChildCommand.
protected  Command createCreateCopyCommand(EditingDomain domain, EObject owner, CopyCommand.Helper helper)
          This creates a primitive CreateCopyCommand.
protected  Command createDragAndDropCommand(EditingDomain domain, java.lang.Object owner, float location, int operations, int operation, java.util.Collection collection)
          This creates a primitive DragAndDropCommand.
protected  Command createInitializeCopyCommand(EditingDomain domain, EObject owner, CopyCommand.Helper helper)
          This creates a primitive InitializeCopyCommand.
protected  Command createMoveCommand(EditingDomain domain, EObject owner, EReference feature, EObject value, int index)
          This creates a primitive MoveCommand.
protected  Command createRemoveCommand(EditingDomain domain, EObject owner, EReference feature, java.util.Collection collection)
          This creates a primitive RemoveCommand.
protected  Command createReplaceCommand(EditingDomain domain, EObject owner, EReference feature, EObject value, java.util.Collection collection)
          This creates a primitive ReplaceCommand.
protected  Command createSetCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object value)
          This creates a primitive SetCommand.
 void dispose()
          This will remove this adapter from all its the targets.
protected  Command factorAddCommand(EditingDomain domain, CommandParameter commandParameter)
          This method factors an AddCommand for a collection of objects into one or more primitive add command, i.e., one per unique reference.
protected  Command factorMoveCommand(EditingDomain domain, CommandParameter commandParameter)
          This method factors a MoveCommand to determine the feature.
protected  Command factorRemoveCommand(EditingDomain domain, CommandParameter commandParameter)
          This method factors a RemoveCommand for a collection of objects into one or more primitive remove commands, i.e., one per unique reference.
 void fireNotifyChanged(Notification notification)
          This convenience method converts the arguments into an appropriate update call on the viewer.
 AdapterFactory getAdapterFactory()
          This provides access to the factory.
 java.net.URL getBaseURL()
          Get the base URL from the resource locator.
protected  EReference getChildReference(java.lang.Object object, java.lang.Object child)
          This returns the most appropriate feature of the object into which the given child could be added.
 java.util.Collection getChildren(java.lang.Object object)
          This implements ITreeItemContentProvider.getChildren by calling getChildrenReferences and using those to collect the children.
protected  java.util.Collection getChildrenReferences(java.lang.Object object)
          If this is defined to be something other than an empty list, it is used to implement getChildren and to deduce the EMF feature in the AddCommand and RemoveCommand in createCommand.
 java.lang.String getCreateChildDescription(java.lang.Object owner, java.lang.Object feature, java.lang.Object child, java.util.Collection selection)
          This returns the description for CreateChildCommand.
 java.lang.Object getCreateChildImage(java.lang.Object owner, java.lang.Object feature, java.lang.Object child, java.util.Collection selection)
          This returns the icon image for CreateChildCommand.
 java.util.Collection getCreateChildResult(java.lang.Object child)
          This returns the result collection for CreateChildCommand.
 java.lang.String getCreateChildText(java.lang.Object owner, java.lang.Object feature, java.lang.Object child, java.util.Collection selection)
          This returns the label for CreateChildCommand.
 java.lang.String getCreateChildToolTipText(java.lang.Object owner, java.lang.Object feature, java.lang.Object child, java.util.Collection selection)
          This returns the tool tip text for CreateChildCommand.
 java.lang.Object getEditableValue(java.lang.Object object)
          This implements IItemPropertySource.getEditableValue by simply returning the object itself.
 java.util.Collection getElements(java.lang.Object object)
          This implements IStructuredItemContentProvider.getElements by forwarding the call to getChildren.
protected  java.lang.String getFeatureText(java.lang.Object feature)
          This looks up the name of the specified feature.
 java.lang.Object getImage(java.lang.Object object)
          This implements IItemLabelProvider.getImage by returning null.
 java.lang.Object getImage(java.lang.String key)
          Get an image from the resource locator.
 java.util.Collection getNewChildDescriptors(java.lang.Object object, EditingDomain editingDomain, java.lang.Object sibling)
          This implements IEditingDomainItemProvider.getNewChildDescriptors, returning CommandParameters to describe all the possible children that can be added to the specified object.
 java.lang.Object getParent(java.lang.Object object)
          This implements ITreeItemContentProvider.getParent by returning the MOF object's container.
 IItemPropertyDescriptor getPropertyDescriptor(java.lang.Object object, java.lang.Object propertyId)
          This convenience method finds a particular descriptor given its property name.
 java.util.List getPropertyDescriptors(java.lang.Object object)
          This implements IItemPropertySource.getPropertyDescriptors by returning the locally stored vector of descriptors.
 java.lang.Object getPropertyValue(java.lang.Object object, java.lang.String property)
          This implements a PropertySource by delegating to the descriptor, which is assumed to support the IItemPropertyDescriptor interface
protected  java.lang.Object getReferenceValue(EObject object, EReference reference)
          This method is called by factorRemoveCommand to retrieve the children objects of the references returned from getChildrenReferences.
protected  ResourceLocator getResourceLocator()
          Get the resource locator for this adapter's resources.
protected  ResourceLocator getResourceLocator(java.lang.Object anyObject)
          Get the resource locator from the adapter of the object, if possible.
protected  EStructuralFeature getSetFeature(java.lang.Object object, java.lang.Object value)
          This returns the most appropriate feature of the object into which the value be set.
protected  java.util.Collection getSetFeatures(java.lang.Object object)
          If this is defined to be something other than an empty list, it is used to implement getSetFeature and to deduce the EMF feature in the SetCommand createCommand.
 java.lang.String getString(java.lang.String key)
          Get a translated string from the resource locator.
 java.lang.String getString(java.lang.String key, java.lang.Object[] substitutions)
          Get a translated string from the resource locator, with substitutions.
protected  java.lang.String getString(java.lang.String key, java.lang.String s0)
          Get a translated string from the resource locator, substituting another such translated string.
protected  java.lang.String getString(java.lang.String key, java.lang.String s0, java.lang.String s1)
          Get a translated string from the resource locator, substituting two other such translated strings.
 java.lang.String getText(java.lang.Object object)
          This implements IItemLabelProvider.getText by simply calling toString on the argument.
protected  java.lang.String getTypeText(java.lang.Object object)
          This looks up the name of the type of the specified object.
 java.lang.String getUpdateableText(java.lang.Object object)
          This implements IUpdateableItemText.getUpdateableText by simply calling getText(java.lang.Object).
 boolean hasChildren(java.lang.Object object)
          This implements ITreeItemContentProvider.hasChildren by simply testing whether getChildren returns any children.
 boolean isAdapterForType(java.lang.Object type)
          The adapter factory is used as the type key.
 boolean isPropertySet(java.lang.Object object, java.lang.String property)
          This implements PropertySource by delegating to the descriptor, which is assumed to support the IItemPropertyDescriptor interface
 void removeListener(INotifyChangedListener listener)
          This removes a listener.
 void resetPropertyValue(java.lang.Object object, java.lang.String property)
          This implements PropertySource.resetPropertyValue by delegating to the descriptor, which is assumed to support the IItemPropertyDescriptor interface
 void setPropertyValue(java.lang.Object object, java.lang.String property, java.lang.Object value)
          This implements PropertySource by delegating to the descriptor, which is assumed to support the IItemPropertyDescriptor interface
 void setTarget(Notifier target)
          Sets the target from which the adapter will receive notification.
 
Methods inherited from class org.eclipse.emf.common.notify.impl.AdapterImpl
getTarget, notifyChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

adapterFactory

protected AdapterFactory adapterFactory
This keeps track of the adapter factory that created this adaptor. It is also used as the key/type for this adapter.

itemPropertyDescriptors

protected java.util.List itemPropertyDescriptors
This is used to store all the property descriptors. Derived classes should add descriptors to this vector.

childrenReferences

protected java.util.List childrenReferences
This is used to store all the children references. Derived classes should add references to this vector.

changeNotifier

protected IChangeNotifier changeNotifier
This is used to implement IChangeNotifier.

targets

protected java.util.Collection targets
This keeps track of all the targets to which this adapter is set.
Constructor Detail

ItemProviderAdapter

public ItemProviderAdapter(AdapterFactory adapterFactory)
An instance is created from an adapter factory. The factory is used as a key so that we always know which factory created this adapter.
Method Detail

isAdapterForType

public boolean isAdapterForType(java.lang.Object type)
The adapter factory is used as the type key. This returns true, only if this adapter was created by the given factory.
Overrides:
isAdapterForType in class AdapterImpl
Following copied from class: org.eclipse.emf.common.notify.impl.AdapterImpl
Parameters:
type - the type.
Returns:
false

getAdapterFactory

public AdapterFactory getAdapterFactory()
This provides access to the factory.

addListener

public void addListener(INotifyChangedListener listener)
Description copied from interface: IChangeNotifier
This adds another listener.
Specified by:
addListener in interface IChangeNotifier

removeListener

public void removeListener(INotifyChangedListener listener)
Description copied from interface: IChangeNotifier
This removes a listener.
Specified by:
removeListener in interface IChangeNotifier

fireNotifyChanged

public void fireNotifyChanged(Notification notification)
This convenience method converts the arguments into an appropriate update call on the viewer. The event type is a value from the static constants in Notifier.
Specified by:
fireNotifyChanged in interface IChangeNotifier

getEditableValue

public java.lang.Object getEditableValue(java.lang.Object object)
This implements IItemPropertySource.getEditableValue by simply returning the object itself.

getPropertyDescriptors

public java.util.List getPropertyDescriptors(java.lang.Object object)
This implements IItemPropertySource.getPropertyDescriptors by returning the locally stored vector of descriptors. This vector could be populated in the constructor of a derived class but it's probably more efficient to create them only on demand by overriding this method. You'll probably want to call super.getPropertyDescriptors if you do this, since you may have one adapter derive from another.

getPropertyDescriptor

public IItemPropertyDescriptor getPropertyDescriptor(java.lang.Object object,
                                                     java.lang.Object propertyId)
This convenience method finds a particular descriptor given its property name.

getPropertyValue

public java.lang.Object getPropertyValue(java.lang.Object object,
                                         java.lang.String property)
This implements a PropertySource by delegating to the descriptor, which is assumed to support the IItemPropertyDescriptor interface

isPropertySet

public boolean isPropertySet(java.lang.Object object,
                             java.lang.String property)
This implements PropertySource by delegating to the descriptor, which is assumed to support the IItemPropertyDescriptor interface

resetPropertyValue

public void resetPropertyValue(java.lang.Object object,
                               java.lang.String property)
This implements PropertySource.resetPropertyValue by delegating to the descriptor, which is assumed to support the IItemPropertyDescriptor interface

setPropertyValue

public void setPropertyValue(java.lang.Object object,
                             java.lang.String property,
                             java.lang.Object value)
This implements PropertySource by delegating to the descriptor, which is assumed to support the IItemPropertyDescriptor interface

getElements

public java.util.Collection getElements(java.lang.Object object)
This implements IStructuredItemContentProvider.getElements by forwarding the call to getChildren. It seems that you almost always want getElements and getChildren to return the same thing, so this makes that easy.

getChildren

public java.util.Collection getChildren(java.lang.Object object)
This implements ITreeItemContentProvider.getChildren by calling getChildrenReferences and using those to collect the children.

hasChildren

public boolean hasChildren(java.lang.Object object)
This implements ITreeItemContentProvider.hasChildren by simply testing whether getChildren returns any children. This implementation will always be right, however, for efficiency you may want to override it to return false or to compute the result in some other efficient way.

getChildrenReferences

protected java.util.Collection getChildrenReferences(java.lang.Object object)
If this is defined to be something other than an empty list, it is used to implement getChildren and to deduce the EMF feature in the AddCommand and RemoveCommand in createCommand. If you override those, then you don't need to implement this.

getReferenceValue

protected java.lang.Object getReferenceValue(EObject object,
                                             EReference reference)
This method is called by factorRemoveCommand to retrieve the children objects of the references returned from getChildrenReferences.

getChildReference

protected EReference getChildReference(java.lang.Object object,
                                       java.lang.Object child)
This returns the most appropriate feature of the object into which the given child could be added. This default implementation returns the first reference returned by getChildrenReferences that has a type compatible with the child. You can override this to return a better result or to compute it more efficiently.

getSetFeatures

protected java.util.Collection getSetFeatures(java.lang.Object object)
If this is defined to be something other than an empty list, it is used to implement getSetFeature and to deduce the EMF feature in the SetCommand createCommand. If you override those, then you don't need to implement this.

getSetFeature

protected EStructuralFeature getSetFeature(java.lang.Object object,
                                           java.lang.Object value)
This returns the most appropriate feature of the object into which the value be set. This default implementation returns the first feature returned by getSetFeatures that has a type compatible with the value. You can override this to return a better result or to compute it more efficiently.

getParent

public java.lang.Object getParent(java.lang.Object object)
This implements ITreeItemContentProvider.getParent by returning the MOF object's container. This is used by certain commands to find an owner, where none is specified, and by the viewers, when trying to locate an arbitrary object within the view (i.e. during select and reveal operation).

getImage

public java.lang.Object getImage(java.lang.Object object)
This implements IItemLabelProvider.getImage by returning null. Most things really should have an icon, but not having one is technically correct too.

getText

public java.lang.String getText(java.lang.Object object)
This implements IItemLabelProvider.getText by simply calling toString on the argument. This will often be correct as is.

getUpdateableText

public java.lang.String getUpdateableText(java.lang.Object object)
This implements IUpdateableItemText.getUpdateableText by simply calling getText(java.lang.Object). This will often be correct as is.

getNewChildDescriptors

public java.util.Collection getNewChildDescriptors(java.lang.Object object,
                                                   EditingDomain editingDomain,
                                                   java.lang.Object sibling)
This implements IEditingDomainItemProvider.getNewChildDescriptors, returning CommandParameters to describe all the possible children that can be added to the specified object.

This implementation invokes collectNewChildDescriptors(java.util.Collection, java.lang.Object), which should be overridden by derived classes, to build this collection.

If sibling is non-null, an index is added to each CommandParameter with a multi-valued reference, to ensure that the new child object gets added in the right position.


collectNewChildDescriptors

protected void collectNewChildDescriptors(java.util.Collection newChildDescriptors,
                                          java.lang.Object object)
This adds to newChildDescriptors, a collection of CommandParameters, parameters for possible children of the specified object, when viewed as an instance of the type for which this is an item provider. This implementation adds nothing to the collection, but derived classes should override this method, invoking the superclass implementation and then adding to the collection.

createCommand

public Command createCommand(java.lang.Object object,
                             EditingDomain domain,
                             java.lang.Class commandClass,
                             CommandParameter commandParameter)
This implements delegated command creation for the given object.

createSetCommand

protected Command createSetCommand(EditingDomain domain,
                                   EObject owner,
                                   EStructuralFeature feature,
                                   java.lang.Object value)
This creates a primitive SetCommand.

createCopyCommand

protected Command createCopyCommand(EditingDomain domain,
                                    EObject owner,
                                    CopyCommand.Helper helper)
This creates a primitive CopyCommand.

createCreateCopyCommand

protected Command createCreateCopyCommand(EditingDomain domain,
                                          EObject owner,
                                          CopyCommand.Helper helper)
This creates a primitive CreateCopyCommand.

createInitializeCopyCommand

protected Command createInitializeCopyCommand(EditingDomain domain,
                                              EObject owner,
                                              CopyCommand.Helper helper)
This creates a primitive InitializeCopyCommand.

createRemoveCommand

protected Command createRemoveCommand(EditingDomain domain,
                                      EObject owner,
                                      EReference feature,
                                      java.util.Collection collection)
This creates a primitive RemoveCommand.

createReplaceCommand

protected Command createReplaceCommand(EditingDomain domain,
                                       EObject owner,
                                       EReference feature,
                                       EObject value,
                                       java.util.Collection collection)
This creates a primitive ReplaceCommand.

createAddCommand

protected Command createAddCommand(EditingDomain domain,
                                   EObject owner,
                                   EReference feature,
                                   java.util.Collection collection,
                                   int index)
This creates a primitive AddCommand.

createMoveCommand

protected Command createMoveCommand(EditingDomain domain,
                                    EObject owner,
                                    EReference feature,
                                    EObject value,
                                    int index)
This creates a primitive MoveCommand.

createDragAndDropCommand

protected Command createDragAndDropCommand(EditingDomain domain,
                                           java.lang.Object owner,
                                           float location,
                                           int operations,
                                           int operation,
                                           java.util.Collection collection)
This creates a primitive DragAndDropCommand.

createCreateChildCommand

protected Command createCreateChildCommand(EditingDomain domain,
                                           EObject owner,
                                           EReference feature,
                                           EObject value,
                                           int index,
                                           java.util.Collection collection)
This creates a primitive CreateChildCommand.

factorRemoveCommand

protected Command factorRemoveCommand(EditingDomain domain,
                                      CommandParameter commandParameter)
This method factors a RemoveCommand for a collection of objects into one or more primitive remove commands, i.e., one per unique reference.

factorAddCommand

protected Command factorAddCommand(EditingDomain domain,
                                   CommandParameter commandParameter)
This method factors an AddCommand for a collection of objects into one or more primitive add command, i.e., one per unique reference.

factorMoveCommand

protected Command factorMoveCommand(EditingDomain domain,
                                    CommandParameter commandParameter)
This method factors a MoveCommand to determine the feature.

setTarget

public void setTarget(Notifier target)
Description copied from interface: Adapter
Sets the target from which the adapter will receive notification. In general, an adapter may be shared by more than one notifier.
Overrides:
setTarget in class AdapterImpl
Following copied from interface: org.eclipse.emf.common.notify.Adapter
Parameters:
newTarget - the new notifier.
See Also:
Adapter.getTarget()

dispose

public void dispose()
This will remove this adapter from all its the targets.
Specified by:
dispose in interface IDisposable

createChildParameter

protected CommandParameter createChildParameter(java.lang.Object feature,
                                                java.lang.Object child)
This is a convenience method that creates a CommandParameter for a given parent feature and child object.

getCreateChildResult

public java.util.Collection getCreateChildResult(java.lang.Object child)
This returns the result collection for CreateChildCommand.
Specified by:
getCreateChildResult in interface CreateChildCommand.Helper

getCreateChildText

public java.lang.String getCreateChildText(java.lang.Object owner,
                                           java.lang.Object feature,
                                           java.lang.Object child,
                                           java.util.Collection selection)
This returns the label for CreateChildCommand.
Specified by:
getCreateChildText in interface CreateChildCommand.Helper

getCreateChildDescription

public java.lang.String getCreateChildDescription(java.lang.Object owner,
                                                  java.lang.Object feature,
                                                  java.lang.Object child,
                                                  java.util.Collection selection)
This returns the description for CreateChildCommand.
Specified by:
getCreateChildDescription in interface CreateChildCommand.Helper

getCreateChildToolTipText

public java.lang.String getCreateChildToolTipText(java.lang.Object owner,
                                                  java.lang.Object feature,
                                                  java.lang.Object child,
                                                  java.util.Collection selection)
This returns the tool tip text for CreateChildCommand.
Specified by:
getCreateChildToolTipText in interface CreateChildCommand.Helper

getCreateChildImage

public java.lang.Object getCreateChildImage(java.lang.Object owner,
                                            java.lang.Object feature,
                                            java.lang.Object child,
                                            java.util.Collection selection)
This returns the icon image for CreateChildCommand.
Specified by:
getCreateChildImage in interface CreateChildCommand.Helper

getTypeText

protected java.lang.String getTypeText(java.lang.Object object)
This looks up the name of the type of the specified object.

getFeatureText

protected java.lang.String getFeatureText(java.lang.Object feature)
This looks up the name of the specified feature.

getResourceLocator

protected ResourceLocator getResourceLocator()
Get the resource locator for this adapter's resources.

getResourceLocator

protected ResourceLocator getResourceLocator(java.lang.Object anyObject)
Get the resource locator from the adapter of the object, if possible. it can be any object, i.e., it may not the type object for which this adapter is applicable.

getBaseURL

public java.net.URL getBaseURL()
Get the base URL from the resource locator.
Specified by:
getBaseURL in interface ResourceLocator
Following copied from interface: org.eclipse.emf.common.util.ResourceLocator
Returns:
the URL from which all resources are based.

getImage

public java.lang.Object getImage(java.lang.String key)
Get an image from the resource locator.
Specified by:
getImage in interface ResourceLocator
Following copied from interface: org.eclipse.emf.common.util.ResourceLocator
Parameters:
key - the key of the image resource.
Returns:
the description on the image resource.

getString

public java.lang.String getString(java.lang.String key)
Get a translated string from the resource locator.
Specified by:
getString in interface ResourceLocator
Following copied from interface: org.eclipse.emf.common.util.ResourceLocator
Parameters:
key - the key of the string resource.
Returns:
the string resource associated with the key.

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.Object[] substitutions)
Get a translated string from the resource locator, with substitutions.
Specified by:
getString in interface ResourceLocator
Following copied from interface: org.eclipse.emf.common.util.ResourceLocator
Parameters:
key - the key of the string.
substitutions - the message substitutions.
Returns:
a string resource associated with the key.
See Also:
ResourceLocator.getString(String), MessageFormat.format(String, Object[])

getString

protected java.lang.String getString(java.lang.String key,
                                     java.lang.String s0)
Get a translated string from the resource locator, substituting another such translated string.

getString

protected java.lang.String getString(java.lang.String key,
                                     java.lang.String s0,
                                     java.lang.String s1)
Get a translated string from the resource locator, substituting two other such translated strings.

Copyright 2001-2003 IBM Corporation and others.
All Rights Reserved.