"Image preview" - selection handling extensions

Motivation

The "Image preview" is a part of the "Multimedia attachments" perspective and shows the preview of a selected image. There are several potential selection providers for this view. Mainly this view was designed to support selections within the "Multimedia attachments" perspective. Since PIM version 8.0 this view supports also the selection of a thumbnail image in the "Merge preview".

images/download/attachments/72549910/image2014-12-1_13_53_44.png

The challange in the selection handling in the "Image preview" is, that there are many several types of selected elements which should be supported by this view. The "Image preview" extracts the image itself from the selected element. The "logic", how to extract the image, can't be located in the "Image preview" since this view doesn't "know" all possible types of selected elements (e.g. ArticleMediaAssetDocument in case of "Merge preview" selections). To prevent a "dependency salat" and to provide a possibility to define custom selections which should be handled by the "Image preview", we added a new extension point: com.heiler.ppm.mediaasset.ui.imagePreviewSelectionProviders

Extension point definition

The extension point com.heiler.ppm.mediaasset.ui.imagePreviewSelectionProviders provides only one contribution element: selectionProvider. This element provides the ID and the implementation class. The contribution implementations should implement the interface com.heiler.ppm.mediaasset.ui.views.ImagePreviewSelectionProvider which contains following methods:

public interface ImagePreviewSelectionProvider
{
/**
* Returns the {@link Predicate} which can be used to determine if a specific selection is provided
* @return a selection predicate (never <code>null</code>)
*/
Predicate< ISelection > getSelectionPredicate();
/**
* Determines if this selection provider can resolve any information for the given selection.
* @param viewPartId the ID of the selection view part (should not be <code>null</code>)
* @param selection the selection to resolve (should not be <code>null</code>)
* @return <code>true</code> if this provider is able to resolve the given selection
*/
boolean canResolveSelection( String viewPartId, ISelection selection );
/**
* Resolves the given selection and returns the image identifier and the quality of the selected image
* @param selection the selection to resolve
* @return a {@link SelectionInfo} object or <code>null</code> if the given selection can't be resolved
*/
SelectionInfo resolveSelection( Object viewPart, ISelection selection );
}
  • The method getSelectionPredicate() provides a predicate which defines whether the "Image preview" should react to a specific selection. Usually the selection predicates are entity type based. For example the predicate for the mediaasset selection looks like this:

    @Override
    public Predicate< ISelection > getSelectionPredicate()
    {
    return new SelectionPredicateFactory.EntityTypePredicate( MediaAssetCoreConst.ENTITY_TYPE_MEDIAASSET ); // <- "MediaAssetType"
    }
  • The method canResolveSelection() determines whether the specific selection provider supports the current selection. The implementations of this method can also use the parameter viewPartId to decide it. For example if the selection comes from the MediaAssetsOfItemTableView the corresponding selection provider can resolve it and extract the image identifier from the given selection. The "Image preview" iterates over all registered ImagePreviewSelectionProvider and calls this method. The first one which returns true will be used to resolve the current selection.

  • The last method: resolveSelection() cares about the extraction of the image information from the given selection. It receives also the view instance, because some implementations of this method need any specific logic of the causing view. The returned object SelectionInfo wrapps all required information which is necessary to load the image (image identifier, quality and - optionally - the entity for the coloring of the description area in the "Image preview", e.g. "Item"/"Product"/"Variant").

Standard implementations

In the standard PIM there is already a few implementations of ImagePreviewSelectionProvider which are contributed to the new extension point:

  • MediaAssetsOfItemImagePreviewSelectionProvider
    This implementation handles all selections of media assets within the "Multimedia attachments" view. The information required for the loading of the image will be extracted from the first document of the media asset. This implementaion was located previously directly in the "Image preview" class and was moved now to com.heiler.ppm.mediaasset.ui.views.MediaAssetsOfItemImagePreviewSelectionProvider.

  • MediaAssetsDocumentsImagePreviewSelectionProvider
    This implementation handles all selections of media asset documents within the "Multimedia documents" view. This implementaion was located previously directly in the "Image preview" class and was moved now to com.heiler.ppm.mediaasset.ui.views.MediaAssetsDocumentsImagePreviewSelectionProvider.

  • DocumentsOfCategoryImagePreviewSelectionProvider
    This implementation handles all selections of the file data within the "Documents" view. This implementaion was located previously directly in the "Image preview" class and was moved now to com.heiler.ppm.mediaasset.ui.views.DocumentsOfCategoryImagePreviewSelectionProvider.

  • ArticleMediaAssetDocumentImagePreviewSelectionProvider
    This implementation is view-independent. It handles all selections of type ArticleMediaAssetDocumentType. Currently the "Merge preview" notifies such selections if the user clicks on a thumbnail image.

  • MediaAssetFileImagePreviewSelectionProvider
    This implementation handles all selections of the media asset file within the "Media Asset File" view.

Custom implementations

To add a custom implementation of ImagePreviewSelectionProvider just contribute to the extension point com.heiler.ppm.mediaasset.ui.imagePreviewSelectionProviders and implement all methods of the ImagePreviewSelectionProvider. Note that the "Image preview" handles all registered selection providers in the same way. This means, if you contribute a new selection provider for the same type of selection as one exisitng standard implementation - then this is random which implementaion will be used.