Compare View Widget

Compare View widget allows the user to compare attributes values of multiple items. The widget performs a comparison of a reference object and all other provided items. The result of the comparison is displayed in a form of a grid report.

Widget Definition

Name Compare View widget
ID com.hybris.cockpitng.widgets.compare
Category Data Manipulation
Description Compare View widget displays a report of attribute values and the differences between them for all provided items
Applied In Backoffice Administration Cockpit, Backoffice Product Content Management
Based On Not applicable.
Author SAP
Inputs Details of input sockets:
  • referenceObject
    • Type: java.lang.Object
    • Multiplicity: Single
    • Description: Allows to change the reference object. When there was no such object, it is added.
  • setObjects
    • Type: java.lang.Object
    • Multiplicity: Collection
    • Description: Changes the collection of objects to be compared - if the current reference object is not included in the collection, the first element is considered as a new reference object
  • addObjects
    • Type: java.lang.Object
    • Multiplicity: Collection
    • Description: Adds a collection of objects to the comparison. If there are no items currently in the comparison, the first item from the collection becomes the reference object
  • removeObjects
    • Type: java.lang.Object
    • Multiplicity: Collection
    • Description: Removes a collection of object from the comparison - if the current reference object is also removed, the first element of remaining objects is considered as a new reference object.
Outputs Details of output sockets:
  • selectedItem
    • Type: com.hybris.cockpitng.data.TypeAwareSelectionContext
    • Multiplicity: Single
    • Description: Sends an object whenever the user clicks on the compared item hyperlink. The data that is sent contains the clicked object as a selectedItem and all compared objects as availableItems.
  • addItemsRequest
    • Type: com.hybris.cockpitng.data.TypeAwareSelectionContext
    • Multiplicity: Single
    • Description: Sends an object whenever the user clicks the addItems component. The data that is sent contains the reference object as selectedItem and all compared objects as availableItems.
  • objectsListUpdated
    • Type: org.apache.commons.lang3.tuple.Pair
    • Multiplicity: Single
    • Description: Sent whenever a list of compared objects is changed. The pair sent contains objects compared before and aftter the change.
Generated Events Not applicable

Configuration

Configuration of the Compare View widget is defined by the compare-view.xsd file.

The following elements can be used in your configuration file:

  • compare-view: root element
    • editor-area-ctx: derived configuration from the Editor Area widget. It allows loading the Editor Area widget configuration as a base for the Compare View configuration. If used and the @use attribute is set to true, then the @ctx configuration is loaded and the tabs are represented as sections with attributes extracted from this tab. Usage: optional, minOccurs=0, maxOccurs=1
      • @ctx (java.lang.String): editor area context. Default value: editor-area
      • @use (java.lang.Boolean): determines if the context should be loaded and used. Default value: true
    • grid-view-ctx: derived configuration from the grid view. It allows loading the grid view configuration as a base for the Compare View configuration. If used and the @use attribute is set to true, then the @ctx configuration is loaded and interpreted as the Compare View header config. Usage: optional, minOccurs=0, maxOccurs=1
      • @ctx (java.lang.String): grid view context. Default value: grid-view
      • @use (java.lang.Boolean): determines if the context should be loaded and used. Default value: true
    • header: configures the header row of the Compare View widget. Usage: optional, minOccurs=0, maxOccurs=1. Final configuration is merged with the grid-view-ctx context, if it is used.
      • @display-thumbnail (java.lang.Boolean): when set to true, the thumbnail image is displayed. Default value: true
      • @display-preview (java.lang.Boolean): when set to true, a pop-up preview with a higher resolution is displayed on a mouse hover. Default value: false
      • @display-default-image (java.lang.Boolean): when set to true, the element, defined in the @default-image parameter, is displayed in a case when there is no image provided.
      • @default-image (java.lang.String): a path to an image file that should be displayed as a default image in the header row when an item does not have an image assigned, or the assigned image cannot be resolved for any reason. Usage: optional
      • additional-renderer: a list of renderers that are responsible for rendering additional content of the header row
        • @spring-bean (java.lang.Spring): an ID of renderer's spring bean. Usage: required
        • @position (java.lang.int): order number of the renderer. Usage: optional
        • @merge-mode (java.lang.String): defines configuration merging mode. Possible values: MERGE, REPLACE, REMOVE. Default value: MERGE, usage: optional
        • parameter: a list of renderer's parameters. Usage: optional, minOccurs=1
          • name (java.lang.String): name of the parameter. Usage: required
          • value (java.lang.String): value of the parameter. Usage: required
    • section List of sections to proceed. Usage: optional, minOccurs=0: the final configuration is merged with the tabs from the editor-area-ctx context, if it is used.
      • @name (java.lang.String): the key for a localized section name. Usage: required
      • @tooltipText (java.lang.String): the key for a localized tooltip text. Usage: optional
      • @renderer (java.lang.String): an ID of renderer's spring bean. Usage: optional
      • @merge-mode (java.lang.String): defines configuration merging mode. Possible values: MERGE, REPLACE, REMOVE. Default value: MERGE, usage: optional
      • attribute: a list of attributes to be processed. Usage: optional, minOccurs=0
        • @qualifier (java.lang.String): the attribute qualifier. Usage: required
        • @label (java.lang.String): the key for a localized attribute name. Value is looked up in the localization bundles. If this String is blank, the attribute is named according to the qualifier. Usage: optional
        • @renderer (java.lang.String): an ID of attribute renderer's spring bean. Usage: optional
        • @position (java.lang.int): order number of the attribute. Usage: optional
        • @merge-mode (java.lang.String): defines configuration merging mode. Possible values: MERGE, REPLACE, REMOVE. Default value: MERGE, usage: optional
        • @editor (java.lang.String): Specifies the editor's ID to define an explicit editor to be used

Basing on the schema above, you can have, for example, the following configuration:

cockpit-config.xml

<!-- ... -->
<context type="typecode" component="compare-view">
    <com:compare-view xmlns:com="http://www.hybris.com/cockpitng/component/compareview">
      <!--Optional:-->
      <com:editor-area-ctx ctx="editor-area" use="true"/>
      <!--Optional:-->
      <com:grid-view-ctx ctx="grid-view" use="true"/>
      <!--Optional:-->
      <com:header display-thumbnail="true" display-preview="false" display-default-image="true" default-image="image.url">
        <!--Zero or more repetitions:-->
        <com:additional-renderer position="100" spring-bean="customRenderer" merge-mode="MERGE">
          <!--Zero or more repetitions:-->
          <com:parameter>
            <com:name>parameter1</com:name>
            <com:value>valueOfParameter1</com:value>
          </com:parameter>
        </com:additional-renderer>
      </com:header>
      <!--Zero or more repetitions:-->
      <com:section merge-mode="MERGE" name="sectionName" tooltipText="tooltip" renderer="sectionRenderer">
        <!--Zero or more repetitions:-->
        <com:attribute position="100" merge-mode="MERGE" qualifier="attributeQualifier" label="label" renderer="attributeRenderer"/>
      </com:section>
    </com:compare-view>
</context>
<!-- ... -->

Configuration Adapter

There is a configuration adapter which can merge an existing editor area and grid view configurations elements into the appropriate Compare View widget's configuration elements.

Configuration elements from the Editor Area widget, and from the grid view mold configuration are overridden by the user specified compare view configuration.

There are five default implementation classes:

  • com.hybris.cockpitng.widgets.compare.adapter.DefaultCompareViewConfigAdapter
  • com.hybris.cockpitng.widgets.compare.adapter.extractors.DefaultEditorAreaAttributeExtractor
  • com.hybris.cockpitng.widgets.compare.adapter.converters.DefaultTabToSectionConverter
  • com.hybris.cockpitng.widgets.compare.adapter.converters.DefaultAttributeToAttributeConverter
  • com.hybris.cockpitng.widgets.compare.adapter.converters.DefaultGridViewToHeaderConverter

The DefaultCompareViewConfigAdapter configuration adapter has six required properties to configure:

  • cockpitConfigurationService, of com.hybris.cockpitng.core.config.CockpitConfigurationService type, with a purpose to load configurations
  • mergeUtils, of com.hybris.cockpitng.core.util.impl.MergeUtils type, with a purpose to merge the Compare View widget configuration provided by the user with Editor Area and Grid View configurations
  • positionedSort, of com.hybris.cockpitng.dataaccess.services.PositionedSort type, with a purpose to align sections and attributes by their order
  • editorAreaAttributeExtractor, of com.hybris.cockpitng.widgets.compare.adapter.extractors.EditorAreaAttributeExtractor type, with a purpose to extract attributes from the Editor Area widget configuration
  • attributeToAttributeConverter, of com.hybris.cockpitng.widgets.compare.adapter.converters.CompareViewConverter type, with a purpose to convert the Editor Area widget attribute configuration to the Compare View widget attribute configuration.
  • tabToSectionConverter, of com.hybris.cockpitng.widgets.compare.adapter.converters.CompareViewConverter type, with a purpose to convert the Editor Area widget tab configuration to the Compare View widget section configuration
  • gridViewToHeaderConverter, of com.hybris.cockpitng.widgets.compare.adapter.converters.CompareViewConverter type, with a purpose to convert the Grid View mold configuration to the Compare View widget header configuration

Below, you can see a default adapter spring configuration:

<alias name="defaultCompareViewConfigAdapter" alias="compareViewConfigAdapter"/>
<bean id="defaultCompareViewConfigAdapter"
     class="com.hybris.cockpitng.widgets.compare.adapter.DefaultCompareViewConfigAdapter">
   <property name="cockpitConfigurationService" ref="cockpitConfigurationService"/>
   <property name="attributeToAttributeConverter" ref="attributeToAttributeConverter"/>
   <property name="gridViewToHeaderConverter" ref="gridViewToHeaderConverter"/>
   <property name="tabToSectionConverter" ref="tabToSectionConverter"/>
   <property name="editorAreaAttributeExtractor" ref="editorAreaAttributeExtractor"/>
   <property name="mergeUtils" ref="cockpitConfigMergeUtils"/>
   <property name="positionedSort" ref="positionedSortAlgorithm"/>
</bean>
 
<alias name="defaultAttributeToAttributeConverter" alias="attributeToAttributeConverter"/>
<bean id="defaultAttributeToAttributeConverter"
     class="com.hybris.cockpitng.widgets.compare.adapter.converters.DefaultAttributeToAttributeConverter"/>
 
<alias name="defaultgridViewToHeaderConverter" alias="gridViewToHeaderConverter"/>
<bean id="defaultgridViewToHeaderConverter"
     class="com.hybris.cockpitng.widgets.compare.adapter.converters.DefaultGridViewToHeaderConverter"/>
 
<alias name="defaulttabToSectionConverter" alias="tabToSectionConverter"/>
<bean id="defaulttabToSectionConverter"
     class="com.hybris.cockpitng.widgets.compare.adapter.converters.DefaultTabToSectionConverter"/>
 
<alias name="defaulteditorAreaAttributeExtractor" alias="editorAreaAttributeExtractor"/>
<bean id="defaulteditorAreaAttributeExtractor"
     class="com.hybris.cockpitng.widgets.compare.adapter.extractors.DefaultEditorAreaAttributeExtractor"/>

The default implementation takes the Editor Area widget configuration, then creates a new Compare View configuration with sections converted from the Editor Area configuration and attributes in sections converted from all attributes in editor area tab configuration. Created configuration is then merged with the original Compare View section configuration. As a result, the configuration derived from the Editor Area is overridden by the user's configuration.

The default implementation takes the Grid View's mold configuration and creates a new Compare View configuration with the header configuration converted from the Grid View's mold configuration. Created configuration is then merged with the original Compare View header configuration. As a result, the header configuration derived from the Grid View's mold configuration is overridden by the user's configuration.

Widget Preview

See how Compare View allows you to quickly compare items on an example of products.

Compare View consists of:

  1. Sticky header row and header column, with a summary cell on their crossing
  2. Embossed reference item, in this case a product.
  3. Pin and Delete from the comparison buttons.
  4. Add items button
  5. Show Diff only button.
  6. Summary Bar
  7. Difference Mark
  8. Expanded section
  9. Differences between attributes marked by the red color.
  10. Show more button

Settings

Use already provided settings for the Compare View widget.

Setting Type Description
layout java.lang.String Defines a bean, which will be used instead of the default one, to create the layout.
defaultTypeCode java.lang.String Allows to set a type of items that can be chosen for the comparison.

Widget Slots

slotID Multiplicity Type Slots Composition
cockpitWidgetChildrenInvisible multi Not applicable. A general purpose slot available for widgets. Any widget placed on this slot is not displayed in the application view but can be accessed through its socket API.

Components Marking

The Compare View widget uses components marking functionality, which is provided by the com.hybris.cockpitng.util.ComponentMarkingUtils utils.

The components of the Compare View widget are marked in their renderers and, after that, listeners are added to the marked components in the com.hybris.cockpitng.widgets.compare.CompareViewController controller class.

Below, you can find a list of components that use the marking feature:

  • pin feature- com.hybris.cockpitng.widgets.compare.CompareViewController#MARK_NAME_PIN
  • hyperlinks feature- com.hybris.cockpitng.widgets.compare.CompareViewController#MARK_NAME_HYPERLINK
  • add item feature- com.hybris.cockpitng.widgets.compare.CompareViewController#MARK_NAME_ADD_ITEM
  • remove item feature- com.hybris.cockpitng.widgets.compare.CompareViewController#MARK_NAME_REMOVE_ITEM

Comparison Engine

The Compare View widget relies on the comparison engine.

To calculate the differences between the objects, Compare View uses the com.hybris.cockpitng.compare.impl.DefaultItemComparisonService service. A getCompareViewResult method, which uses final Object referenceObject, final Collection compareObjects, and final Collection<CompareAttributeDescriptor> attributeDescriptors as parameters, returns a structure of differences between the reference object and compared objects for the particular attributes. The Compare View widget invokes this method at the beginning of the rendering process and passes the results to particular renderers.

Autowrapping Mode in Compare View Widget

Autowrapping mode is a feature which automatically wraps all editors in the Compare View widget. The wrap means that an editor is nested within the other one and enriches its traits.

To know more about nested editors, please, see the Nested Editors document.

By default, all editors are wrapped by Instant Editor. In order to control it, the Compare View widget has introduced a setting called editorWrapperTemplate. If it is not empty, autowrapping is enabled. The default value of the setting is com.hybris.cockpitng.editor.instanteditor(%s). The (%s) string is required in the template value because it is replaced by the nested editor. This string indicates the editor with what is going to be wrapped.

Wrapping is performed for the following scenarios:

  • The editor is not defined for the qualifier:

    If the user declares the qualifier without an editor argument, for example,
    <compare-view:attribute qualifier="name" />
    then the default qualifier type editor is automatically wrapped by Instant Editor (com.hybris.cockpitng.editor.instanteditor). For this configuration, the result of autowrapping process is:
    <compare-view:attribute qualifier="name" editor="com.hybris.cockpitng.editor.instanteditor(com.hybris.cockpitng.editor.localized(com.hybris.cockpitng.editor.defaulttext))" />
  • The editor is already wrapped by the setting value:

    If the user declares a qualifier with already wrapped editor, for example:
    <compare-view:attribute qualifier="name" editor="com.hybris.cockpitng.editor.instanteditor(com.hybris.cockpitng.editor.localized(com.hybris.cockpitng.editor.defaulttext))" />
    nothing changes and the configured editor is applied.
  • editor is defined for qualifier
    If the user declares a qualifier with the editor argument, for example:
    <compare-view:attribute qualifier="name" editor="com.hybris.cockpitng.editor.defaulttext" />
    then the configured editor is automatically wrapped by Instant Editor. For this particular configuration, the result of autowrapping process is:
    <compare-view:attribute qualifier="name" editor="com.hybris.cockpitng.editor.instanteditor(com.hybris.cockpitng.editor.localized(com.hybris.cockpitng.editor.defaulttext))" />

Compare View Widget Label Renderers

Compare View widget introduces the following label renderers for Instant Editor:

  • itemPreviewLabelRenderer- displays a thumbnail of an item next to its label
  • compareViewMapLabelRenderer- displays map entries as key and value pairs
  • collapsibleCollectionLabelRenderer- makes large collections and maps collapsible.