Class ContentProvider

  • All Implemented Interfaces:
    IProviderFlagsChangeListener, EventListener, org.eclipse.core.runtime.IAdaptable, org.eclipse.jface.viewers.IContentProvider, org.eclipse.jface.viewers.ISelectionChangedListener, org.eclipse.jface.viewers.IStructuredContentProvider, org.eclipse.jface.viewers.ITreeContentProvider, org.eclipse.ui.navigator.ICommonContentProvider, org.eclipse.ui.navigator.IMementoAware, org.eclipse.ui.navigator.IPipelinedTreeContentProvider, org.eclipse.ui.navigator.IPipelinedTreeContentProvider2

    public class ContentProvider
    extends java.lang.Object
    implements IProviderFlagsChangeListener, EventListener, org.eclipse.jface.viewers.ISelectionChangedListener, org.eclipse.ui.navigator.IPipelinedTreeContentProvider2, org.eclipse.core.runtime.IAdaptable
    The iizi Explorer using Common Navigator.

    References:

    • http://www.techjava.de/topics/2009/04/eclipse-common-navigator-framework/
    • http://cvalcarcel.wordpress.com/2010/06/29/writing-an-eclipse-plug-in-the-missing-zip-files/
    • http://git.eclipse.org/c/gmp/org.eclipse.gmp.graphiti.git/tree/examples/org.eclipse.graphiti.examples.common/src/org/eclipse/graphiti/examples/common/navigator
    Author:
    Christopher Mindus
    • Field Summary

      Fields 
      Modifier and TypeFieldDescription
      static java.lang.Object[]EMPTY_ARRAY
      An empty array.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voiddispose()
      Disposes of this content provider.
      <T> TgetAdapter​(java.lang.Class<T> adapter)
      Adapts the content provider.
      java.lang.Object[]getChildren​(java.lang.Object element)
      Returns the child elements of the given parent element.
      java.lang.Object[]getElements​(java.lang.Object element)
      Returns the elements to display in the viewer when its input is set to the given element.
      intgetFlags()
      Gets the flags.
      static org.eclipse.jface.viewers.StructuredViewergetLastViewer()
      Gets the viewer that was last used to set the selection.
      java.lang.ObjectgetParent​(java.lang.Object element)
      Returns the parent for the given element, or null indicating that the parent can't be computed.
      voidgetPipelinedChildren​(java.lang.Object aParent, java.util.Set theCurrentChildren)
      Intercept the children that would be contributed to the viewer and determine how to change the shape of those children.
      voidgetPipelinedElements​(java.lang.Object anInput, java.util.Set theCurrentElements)
      Intercept the elements that would be contributed to the root of the viewer and determine how to change the shape of those children.
      java.lang.ObjectgetPipelinedParent​(java.lang.Object anObject, java.lang.Object aSuggestedParent)
      Intercept requests for a parent of the given object.
      booleanhasChildren​(java.lang.Object element)
      Returns whether the given element has children.
      booleanhasPipelinedChildren​(java.lang.Object anInput, boolean currentHasChildren)
      Intercept the fact of having children and optionally modify this.
      voidinit​(org.eclipse.ui.navigator.ICommonContentExtensionSite aConfig)
      Initialize the content provider with the given configuration.
      voidinputChanged​(org.eclipse.jface.viewers.Viewer v, java.lang.Object oldInput, java.lang.Object newInput)
      Notifies this content provider that the given viewer's input has been switched to a different element.
      org.eclipse.ui.navigator.PipelinedShapeModificationinterceptAdd​(org.eclipse.ui.navigator.PipelinedShapeModification anAddModification)
      Intercept attempts to add elements directly to the viewer.
      booleaninterceptRefresh​(org.eclipse.ui.navigator.PipelinedViewerUpdate aRefreshSynchronization)
      Intercept calls to viewer refresh() methods.
      org.eclipse.ui.navigator.PipelinedShapeModificationinterceptRemove​(org.eclipse.ui.navigator.PipelinedShapeModification aRemoveModification)
      Intercept attempts to remove elements directly from the viewer.
      booleaninterceptUpdate​(org.eclipse.ui.navigator.PipelinedViewerUpdate anUpdateSynchronization)
      Intercept calls to viewer update() methods.
      voidonEvent​(GEvent e)
      An iizi-event processed here to see if the viewer needs update.
      voidonNewFlags​(int flags)
      Called when the flags changed.
      voidrestoreState​(org.eclipse.ui.IMemento aMemento)
      Restore the previous state of any actions using the flags in aMemento.
      voidsaveState​(org.eclipse.ui.IMemento aMemento)
      Save flags in aMemento to remember the state of any actions that persist from session to session.
      voidselectionChanged​(org.eclipse.jface.viewers.SelectionChangedEvent event)
      Selection changes in the viewer, forwarded to the ActionExecutor class.
      voidsetFlags​(int flags)
      Sets the flags.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EMPTY_ARRAY

        public static final java.lang.Object[] EMPTY_ARRAY
        An empty array.
    • Constructor Detail

      • ContentProvider

        public ContentProvider()
        Constructor.
      • ContentProvider

        public ContentProvider​(int flags)
        Constructor.
        Parameters:
        flags - The flags for the information.
    • Method Detail

      • onNewFlags

        public void onNewFlags​(int flags)
        Called when the flags changed.
        Specified by:
        onNewFlags in interface IProviderFlagsChangeListener
        Parameters:
        flags - The flags from INavigatorPresentation.
      • setFlags

        public void setFlags​(int flags)
        Sets the flags.
      • getFlags

        public int getFlags()
        Gets the flags.
      • init

        public void init​(org.eclipse.ui.navigator.ICommonContentExtensionSite aConfig)
        Initialize the content provider with the given configuration.
        Specified by:
        init in interface org.eclipse.ui.navigator.ICommonContentProvider
      • restoreState

        public void restoreState​(org.eclipse.ui.IMemento aMemento)
        Restore the previous state of any actions using the flags in aMemento. This method allows the state of any actions that persist from session to session to be restored.
        Specified by:
        restoreState in interface org.eclipse.ui.navigator.IMementoAware
      • saveState

        public void saveState​(org.eclipse.ui.IMemento aMemento)
        Save flags in aMemento to remember the state of any actions that persist from session to session.
        Specified by:
        saveState in interface org.eclipse.ui.navigator.IMementoAware
      • dispose

        public void dispose()
        Disposes of this content provider. This is called by the viewer when it is disposed.

        The viewer should not be updated during this call, as it is in the process of being disposed.

        Specified by:
        dispose in interface org.eclipse.jface.viewers.IContentProvider
      • inputChanged

        public void inputChanged​(org.eclipse.jface.viewers.Viewer v,
                                 java.lang.Object oldInput,
                                 java.lang.Object newInput)
        Notifies this content provider that the given viewer's input has been switched to a different element.

        A typical use for this method is registering the content provider as a listener to changes on the new input (using model-specific means), and de-registering the viewer from the old input. In response to these change notifications, the content provider should update the viewer (see the add, remove, update and refresh methods on the viewers).

        The viewer should not be updated during this call, as it might be in the process of being disposed.

        Specified by:
        inputChanged in interface org.eclipse.jface.viewers.IContentProvider
        Parameters:
        v - The viewer.
        oldInput - The old input element, or null if the viewer did not previously have an input.
        newInput - The new input element, or null if the viewer does not have an input.
      • getElements

        public java.lang.Object[] getElements​(java.lang.Object element)
        Returns the elements to display in the viewer when its input is set to the given element.
        Specified by:
        getElements in interface org.eclipse.jface.viewers.IStructuredContentProvider
        Specified by:
        getElements in interface org.eclipse.jface.viewers.ITreeContentProvider
        Parameters:
        element - The input element.
        Returns:
        the array of elements to display in the viewer.
      • getChildren

        public java.lang.Object[] getChildren​(java.lang.Object element)
        Returns the child elements of the given parent element.

        The difference between this method and IStructuredContentProvider.getElements is that getElements is called to obtain the tree viewer's root elements, whereas getChildren is used to obtain the children of a given parent element in the tree (including a root).

        The result is not modified by the viewer.

        Specified by:
        getChildren in interface org.eclipse.jface.viewers.ITreeContentProvider
        Parameters:
        element - the parent element
        Returns:
        an array of child elements
      • getParent

        public java.lang.Object getParent​(java.lang.Object element)
        Returns the parent for the given element, or null indicating that the parent can't be computed. In this case the tree-structured viewer can't expand a given node correctly if requested.
        Specified by:
        getParent in interface org.eclipse.jface.viewers.ITreeContentProvider
        Parameters:
        element - The element.
        Returns:
        the parent element, or null if it has none or if the parent cannot be computed.
      • hasChildren

        public boolean hasChildren​(java.lang.Object element)
        Returns whether the given element has children.

        Intended as an optimization for when the viewer does not need the actual children. Implementation is more efficient than getChildren.

        Specified by:
        hasChildren in interface org.eclipse.jface.viewers.ITreeContentProvider
        Parameters:
        element - The element.
        Returns:
        true if the given element has children, and false if it has no children.
      • onEvent

        public void onEvent​(GEvent e)
        An iizi-event processed here to see if the viewer needs update. This call can be done from any thread, so it must be "queued" over to the viewer for processing.
        Specified by:
        onEvent in interface EventListener
        Parameters:
        e - The event.
      • selectionChanged

        public void selectionChanged​(org.eclipse.jface.viewers.SelectionChangedEvent event)
        Selection changes in the viewer, forwarded to the ActionExecutor class.
        Specified by:
        selectionChanged in interface org.eclipse.jface.viewers.ISelectionChangedListener
        Parameters:
        event -
      • getLastViewer

        public static org.eclipse.jface.viewers.StructuredViewer getLastViewer()
        Gets the viewer that was last used to set the selection.
      • getPipelinedElements

        public void getPipelinedElements​(java.lang.Object anInput,
                                         java.util.Set theCurrentElements)
        Intercept the elements that would be contributed to the root of the viewer and determine how to change the shape of those children. The given set of elements should be modified to contain the correct elements to return to the viewer.
        Specified by:
        getPipelinedElements in interface org.eclipse.ui.navigator.IPipelinedTreeContentProvider
        Parameters:
        anInput - An input from the viewer.
        theCurrentElements - The set of children contributed thus far from upstream content providers.
      • getPipelinedChildren

        public void getPipelinedChildren​(java.lang.Object aParent,
                                         java.util.Set theCurrentChildren)
        Intercept the children that would be contributed to the viewer and determine how to change the shape of those children. The set of children should be modified to contain the correct children to return to the viewer.
        Specified by:
        getPipelinedChildren in interface org.eclipse.ui.navigator.IPipelinedTreeContentProvider
        Parameters:
        aParent - A parent from the viewer.
        theCurrentChildren - The set of children contributed thus far from upstream content providers.
      • hasPipelinedChildren

        public boolean hasPipelinedChildren​(java.lang.Object anInput,
                                            boolean currentHasChildren)
        Intercept the fact of having children and optionally modify this. This calculation should match whether children will be actually provided.
        Specified by:
        hasPipelinedChildren in interface org.eclipse.ui.navigator.IPipelinedTreeContentProvider2
        Parameters:
        anInput - An input from the viewer.
        currentHasChildren - The current proposed setting of hasChildren thus far from the upstream content providers.
        Returns:
        The new value for hasChildren.
      • getPipelinedParent

        public java.lang.Object getPipelinedParent​(java.lang.Object anObject,
                                                   java.lang.Object aSuggestedParent)
        Intercept requests for a parent of the given object.
        Specified by:
        getPipelinedParent in interface org.eclipse.ui.navigator.IPipelinedTreeContentProvider
        Parameters:
        anObject - The object being queried for a parent.
        aSuggestedParent - The parent already suggested from upstream extensions.
        Returns:
        The intended parent from this pipelined content provider. If you wish to not influence the parent, then return the aSuggestedParent value.
      • interceptAdd

        public org.eclipse.ui.navigator.PipelinedShapeModification interceptAdd​(org.eclipse.ui.navigator.PipelinedShapeModification anAddModification)
        Intercept attempts to add elements directly to the viewer.

        * For content extensions that reshape the structure of children in a viewer, their overridden extensions may sometimes use optimized refreshes to add elements to the tree. These attempts must be intercepted and mapped to the correct set of model elements in the overriding extension. Clients may add, remove, or modify elements in the given set of added children. Clients should return a set for downstream extensions to massage further.

        * Clients may change what parent the reshaped elements are added to, so long as that parent is not the root of the viewer.

        Clients should never create their own pipeline shape modifications, but instead return the shape modification that was passed in with appropriate changes.

        Clients should not call any of the add, remove, refresh, or update methods on the viewer from this method or any code invoked by the implementation of this method.

        Specified by:
        interceptAdd in interface org.eclipse.ui.navigator.IPipelinedTreeContentProvider
        Parameters:
        anAddModification - The shape modification which contains the current suggested parent and children. Clients may modify this parameter directly and return it as the new shape modification.
        Returns:
        The new shape modification to use. Clients should never return null from this method.
      • interceptRemove

        public org.eclipse.ui.navigator.PipelinedShapeModification interceptRemove​(org.eclipse.ui.navigator.PipelinedShapeModification aRemoveModification)
        Intercept attempts to remove elements directly from the viewer.

        For content extensions that reshape the structure of children in a viewer, their overridden extensions may sometimes use optimized refreshes to remove elements to the tree. These attempts must be intercepted and mapped to the correct set of model elements in the overriding extension. Clients may add, remove, or modify elements in the given set of removed children. Clients should return a set for downstream extensions to massage further.

        The parent will be null for remove modifications. Clients should never create their own pipeline shape modifications, but instead return the shape modification that was passed in with appropriate changes.

        Clients should not call any of the add, remove, refresh, or update methods on the viewer from this method or any code invoked by the implementation of this method.

        Specified by:
        interceptRemove in interface org.eclipse.ui.navigator.IPipelinedTreeContentProvider
        Parameters:
        aRemoveModification - The shape modification which contains the current suggested parent and children. Clients may modify this parameter directly and return it as the new shape modification.
        Returns:
        The new shape modification to use. Clients should never return null from this method.
      • interceptRefresh

        public boolean interceptRefresh​(org.eclipse.ui.navigator.PipelinedViewerUpdate aRefreshSynchronization)
        Intercept calls to viewer refresh() methods.

        Clients may modify the given update to add or remove the elements to be refreshed. Clients may return the same instance that was passed in for the next downstream extension.

        Clients should not call any of the add, remove, refresh, or update methods on the viewer from this method or any code invoked by the implementation of this method.

        Specified by:
        interceptRefresh in interface org.eclipse.ui.navigator.IPipelinedTreeContentProvider
        Parameters:
        aRefreshSynchronization - The (current) refresh update to execute against the viewer.
        Returns:
        True if the viewer update was modified.
      • interceptUpdate

        public boolean interceptUpdate​(org.eclipse.ui.navigator.PipelinedViewerUpdate anUpdateSynchronization)
        Intercept calls to viewer update() methods.

        Clients may modify the given update to add or remove the elements to be updated. Clients may also add or remove properties for the given targets to optimize the refresh. Clients may return the same instance that was passed in for the next downstream extension.

        Clients should not call any of the add, remove, refresh, or update methods on the viewer from this method or any code invoked by the implementation of this method.

        Specified by:
        interceptUpdate in interface org.eclipse.ui.navigator.IPipelinedTreeContentProvider
        Parameters:
        anUpdateSynchronization - The (current) update to execute against the viewer.
        Returns:
        True if the viewer update was modified.
      • getAdapter

        public <T> T getAdapter​(java.lang.Class<T> adapter)
        Adapts the content provider.
        Specified by:
        getAdapter in interface org.eclipse.core.runtime.IAdaptable
        Parameters:
        adapter - The adapter class.
        Returns:
        The object adapting to the class.