net.sourceforge.java.feednread.frontend.components.favoritestree
Class NewsFeedFavoritesTreeLabelProvider

java.lang.Object
  extended byorg.eclipse.core.commands.common.EventManager
      extended byorg.eclipse.jface.viewers.LabelProvider
          extended bynet.sourceforge.java.feednread.frontend.components.favoritestree.NewsFeedFavoritesTreeLabelProvider
All Implemented Interfaces:
IBaseLabelProvider, IFontProvider, ILabelDecorator, ILabelProvider

public class NewsFeedFavoritesTreeLabelProvider
extends LabelProvider
implements IFontProvider, ILabelDecorator

LabelProvider implementation used to convert Favorite and Category objects to gui representations that are displayable in the NewsFeedFavoriteTree component.

Author:
Sebastian Machhausen

Nested Class Summary
private  class NewsFeedFavoritesTreeLabelProvider.ImageLoader
           Thread to load the icon Image of a Favorite in the background.
 
Field Summary
private  ImageRegistry decoratedImages
           ImageRegistry to cache decorated Images
private  Hashtable favoriteIconLoaders
           The Hashtable that maps Favorites to their corresponding icon Image loading Thread.
private  TreeViewer viewer
           The TreeViewer that this label provider converts domain to gui representations for.
 
Fields inherited from class org.eclipse.core.commands.common.EventManager
 
Constructor Summary
NewsFeedFavoritesTreeLabelProvider(TreeViewer viewer)
           Creates a new NewsFeedFavoritesTreeLabelProvider for the specified TreeViewer.
 
Method Summary
 Image decorateImage(Image image, Object element)
           Returns an image that is based on the given image, but decorated with additional information relating to the state of the provided element.
 String decorateText(String text, Object element)
           Returns a text label that is based on the given text label, but decorated with additional information relating to the state of the provided element.
 void dispose()
           Disposes all resources claimed by this NewsFeedFavoritesTreeLabelProvider.
private  Image getDefaultImage(Favorite favorite)
           Gets a default Image for the specified Favorite depending on its status.
 Font getFont(Object element)
          Return the Font for element or null if there is none set.
 Image getImage(Object element)
           Gets the Image to display for the specified domain object.
 String getText(Object element)
           Gets the textual representation to display for the specified domain object.
private  boolean isDefaultFavoriteImage(Image img)
           Returns true if the specified Image is the default Favorite Image.
 
Methods inherited from class org.eclipse.jface.viewers.LabelProvider
addListener, fireLabelProviderChanged, isLabelProperty, removeListener
 
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jface.viewers.IBaseLabelProvider
addListener, isLabelProperty, removeListener
 

Field Detail

viewer

private TreeViewer viewer

The TreeViewer that this label provider converts domain to gui representations for.


favoriteIconLoaders

private Hashtable favoriteIconLoaders

The Hashtable that maps Favorites to their corresponding icon Image loading Thread. We use the synchronized Hashtable in here since thread safe access has to be guaranteed.


decoratedImages

private ImageRegistry decoratedImages

ImageRegistry to cache decorated Images

Constructor Detail

NewsFeedFavoritesTreeLabelProvider

public NewsFeedFavoritesTreeLabelProvider(TreeViewer viewer)

Creates a new NewsFeedFavoritesTreeLabelProvider for the specified TreeViewer.

Parameters:
viewer - the TreeViewer for which to create the NewsFeedFavoritesTreeLabelProvider
Method Detail

getImage

public Image getImage(Object element)

Gets the Image to display for the specified domain object.

Specified by:
getImage in interface ILabelProvider
Parameters:
element - the domain object to get the for
Returns:
the for the specified domain object
See Also:
ILabelProvider.getImage(Object)

getText

public String getText(Object element)

Gets the textual representation to display for the specified domain object.

Specified by:
getText in interface ILabelProvider
Parameters:
element - the domain object to get the textual representation for
Returns:
the textual representaion
See Also:
ILabelProvider.getText(Object)

getFont

public Font getFont(Object element)
Return the Font for element or null if there is none set.

Specified by:
getFont in interface IFontProvider
Parameters:
element - gets the Font for the specified element
Returns:
Font or null

dispose

public void dispose()

Disposes all resources claimed by this NewsFeedFavoritesTreeLabelProvider.

Specified by:
dispose in interface IBaseLabelProvider

decorateImage

public Image decorateImage(Image image,
                           Object element)

Returns an image that is based on the given image, but decorated with additional information relating to the state of the provided element. Text and image decoration updates can occur as a result of other updates within the workbench including deferred decoration by background processes. Clients should handle labelProviderChangedEvents for the given element to get the complete decoration.

Specified by:
decorateImage in interface ILabelDecorator
Parameters:
image - the input image to decorate, or null if the element has no image
element - the element whose image is being decorated
Returns:
the decorated image, or null if no decoration is to be applied
See Also:
LabelProviderChangedEvent, IBaseLabelProvider.addListener(org.eclipse.jface.viewers.ILabelProviderListener), CompositeImageDescriptor

decorateText

public String decorateText(String text,
                           Object element)

Returns a text label that is based on the given text label, but decorated with additional information relating to the state of the provided element. Text and image decoration updates can occur as a result of other updates within the workbench including deferred decoration by background processes. Clients should handle labelProviderChangedEvents for the given element to get the complete decoration.

Specified by:
decorateText in interface ILabelDecorator
Parameters:
text - the input text label to decorate
element - the element whose image is being decorated
Returns:
the decorated text label, or null if no decoration is to be applied
See Also:
LabelProviderChangedEvent, IBaseLabelProvider.addListener(org.eclipse.jface.viewers.ILabelProviderListener)

getDefaultImage

private Image getDefaultImage(Favorite favorite)

Gets a default Image for the specified Favorite depending on its status.

Parameters:
favorite - the Favorite to get a default Image for
Returns:
a default Image for the specified Favorite

isDefaultFavoriteImage

private boolean isDefaultFavoriteImage(Image img)

Returns true if the specified Image is the default Favorite Image.

Parameters:
img - the Image to test
Returns:
true if the specified Image is the default Favorite Image; false otherwise