Customizing the Widgets Structure in the Backoffice-Based Application

As a widget developer, you have a possibility to extend and modify an application configuration within its custom extension.

You can proceed through the following activities:

  • Adding widgets to the existing application configuration, for example adding a widget to a specific widget node
  • Removing or replacing a widget in the existing application configuration
  • Moving a widget from one container to another without losing connection information
  • Changing a setting of a given widget

This document guides you through the basic customization steps in terms of widgets structure, starting with generating the custom extension, myextension. Next, it is recommended to follow the steps in each section to customize your perspective. However, you can perform the steps from the first section, generating a custom extension, and then follow the steps described only in one of the following sections. The last three sections are optional: each of them just presents the alternatives available in the application based on the backoffice extension.

Overview

The purpose of this tutorial is to create the custom application based on the existing Backoffice application and modify widgets structure there. This requires to modify the application configuration. The below figures show the default mash-up of the Backoffice Administration Cockpit and the Application Orchestrator view. The widgets are presented with their widgetId tags.

Figure: Default layout of Backoffice Application - end user view.

Figure: Default layout of Backoffice Application - Application Orchestrator view.

In the following sections you can find how to do the following:

  • Move the Explorer Tree widget from the left-hand side to right-hand side in your custom application
  • Remove the Editor Area widget
  • Add the Portal Layout widget on the left-hand side where the Explorer Tree widget was placed
  • Add other widgets to the Portal Layout widget.

Creating a Custom Extension

Create a custom Backoffice extension to build your project and manage widgets in the Backoffice application.

To start working on your Backoffice application project you need to have a custom Backoffice extension. Follow the steps described in Creating a Custom Backoffice Extension and then move to the next steps described in this topic.

Building Project

In this procedure, you will build your project using the command prompt.

Procedure

  1. Open the command prompt.
  2. Navigate to the <HYBRIS_BIN_DIR> /platform directory.
  3. Make sure that a compliant version is used:
    • On the Windows operating system, call the <HYBRIS_BIN_DIR> /platform/setantenv.bat file. Do not close the command prompt after this call as the settings are transient and would get lost if the command prompt is closed.
    • On the Unix operating system, call the <HYBRIS_BIN_DIR> /platform/setantenv.sh file, such as: . ./setantenv.sh.
  4. Call ant clean all to build the entireSAP Commerce Cloud.

Starting the Application Server for Custom Extension

In this procedure, you start the application server.

Context

Optionally, you may want to deactivate the ybackoffice template extension in your localextensions.xml file. If you do so, the Backoffice template area is not displayed in the application, only your custom application.

Procedure

  1. In the command prompt, navigate to the <HYBRIS_BIN_DIR>/platform directory.
  2. Depending on your operating system, run the following command:
    • For Microsoft Windows systems: hybrisserver.bat

    • For Linux-based systems: hybrisserver.sh

  3. Press ENTER.
  4. Open Backoffice application.

    The newly created myextension extension is the place where you should create your custom components.

Moving the Explorer Tree Widget

In this procedure, you move the Explorer Tree Widget from the left-hand side and place it on the right-hand side of your Backoffice.

Context

To move the Explorer Tree Widget, do the following tasks:

  1. Make the east section enabled for the Border Layout widget using widgetId="hmc2" tag.
  2. Move the Explorer Tree widget to the right place.

Procedure

  1. Add the following code snippet to your <myextension>-backoffice-widgets.xml file.

    /resources/myextension-backoffice-widgets.xml

    <widget-extension widgetId="hmc2" >
           <setting key="eastDisabled" type="Boolean" value="false"/>
    </widget-extension>
    <widget-extension widgetId="explorerTree">
        <move widgetId="leftSlotContainer" targetWidgetId="hmc2" targetSlotId="rightSlot" failOnError="true" />
    </widget-extension>
  2. Press F4 on your keyboard to go to the Application Orchestrator view.
  3. In the Application Orchestrator view, expand the menu in the top-right corner.
  4. From the expanded menu, select the Reset Everything option.
  5. In the pop-up window Reset Configuration, click Yes button.

    When you press F4 on your keyboard, you should see the result as below:

    Figure: The Explorer Tree widget moved to the right-hand side.

  6. For more information, see the Explorer Tree Widget.

Removing the Editor Area Widget

To remove a widget, declare the widgetId of the widget to be removed from a given widget declaring an appropriate widgetId. In the example below, you can find how to remove the Editor Area widget within the widgetId="editorArea from the Collapsible Container widget.

Procedure

  1. Add the following code snippet to your myextension-backoffice-widgets.xml file:

    /resources/myextension-backoffice-widgets.xml

    <widget-extension widgetId="collapsibleContainer">
            <remove widgetId="editorArea"/>
        </widget-extension>
  2. Press F4 on your keyboard to go to the Application Orchestrator view.
  3. In the Application Orchestrator view, expand the menu in the top-right corner.
  4. From the expanded menu, select the Reset Everything option.
  5. In the pop-up window Reset Configuration, click Yes button.

    When you press F4 on your keyboard, you should see the result as below:

    Figure: The Editor Area widget removed from the Collapsible Container widget.

  6. For more information, see:

Adding the Portal Layout Widget

If you want to place the Portal Layout widget on the left-hand side, add it to the left slot of the Border Layout widget.

Procedure

  1. Add the below code snippet to your myextension-backoffice-widgets.xml file:

    /resources/myextension-backoffice-widgets.xml

    <widget-extension widgetId="hmc2">
         <widget id="portal" widgetDefinitionId="com.hybris.cockpitng.defaultportalwidget" slotId="leftSlot"/>
     </widget-extension>
  2. Press F4 on your keyboard to go to the Application Orchestrator view.
  3. In the Application Orchestrator view, expand the menu in the top-right corner.
  4. From the expanded menu, select the Reset Everything option.
  5. In the pop-up window Reset Configuration, click Yes.

    When you press F4 on your keyboard, you should see the result as below:

    Figure: The Explorer Tree widget moved to the right-hand side, the Editor Area widget removed, and the Portal Layout widget added on the left-hand side.

Adding Widgets to the Portal Layout Widget

In this procedure, you add widgets to the Portal Layout widget.

Context

The code snippet shown below adds the InputTestWidget widget and OutputTestWidget widget to your custom application. However, in the same way you can add any other widget specifying appropriately the widgetDefinitionId in the myextension-backoffice-widgets.xml file.

Procedure

  1. Add the below code snippet to your myextension-backoffice-widgets.xml file:

    /resources/myextension-backoffice-widgets.xml

    <widget-extension widgetId="portal">
            <widget id="Input" widgetDefinitionId="com.hybris.cockpitng.inputtestwidget" slotId="children"/>
            <widget id="Output" widgetDefinitionId="com.hybris.cockpitng.outputtestwidget" slotId="children"/>
        </widget-extension>
  2. Press F4 on your keyboard to go to the Application Orchestrator view.
  3. Expand the menu in the top-right corner.
  4. From the expanded menu, select the Reset Everything option.
  5. In the pop-up window Reset Configuration, click Yes.

    When you press F4 on your keyboard, you should see the result as below:

    Figure: Two widgets added to the Portal Layout widget.

Optional Steps for Customizing the Widgets Structure

There are some optional steps which can be done to customize the widgets structure.

Those steps are:

Changing the Order of Perspectives

You can change the order of perspectives such as Adaptive Search or your custom perspective displayed in the Backoffice Main Layout widget. Changing a position of the area means that you change a position of a given widget in the widgetchildren collection. You can accomplish that declaring a position in the move tag.

Context

For the purpose of the steps below, it is assumed that you have the Adaptive Search perspective with all its dependencies available in the Backoffice Application. It is available with SAP Commerce Cloud or with Commerce Search Module.

Procedure

  1. Add the following code snippet to your myextension-backoffice-widgets.xml file to change the order of Backoffice Administration Cockpit and Adaptive Search in your custom application:

    /resources/myextension-backoffice-widgets.xml

    <widget-extension widgetId="adaptiveSearch">
        <move widgetId="backofficeMainSlot" targetWidgetId="backofficeMainSlot" targetSlotId="perspectives" position="0"/>
        </widget-extension>
  2. Press F4 on your keyboard to go to the Application Orchestrator view.
  3. Expand the menu in the top-right corner.
  4. From the expanded menu, select the Reset Everything option.
  5. In the pop-up window Reset Configuration, click Yes.

    As a result, the Adaptive Search perspective is displayed as the first one after logging in.

Removing Widgets from the Portal Layout Widget

This procedure shows how to remove all children widgets from a given widget. It can be done by using the remove-all tag.

Procedure

  1. Add the following code snippet to your myextension-backoffice-widgets.xml file to remove all children widgets from the Portal Layout widget:
    <widget-extension widgetId="portal">
            <remove-all/>
        </widget-extension>

    Below, you can find an example of configuration of the myextension-backoffice-widgets.xml file:

    myextension-backoffice-widgets.xml

    <widget-extension widgetId="hmc2" >
            <setting key="eastDisabled" type="Boolean" value="false"/>
        </widget-extension>
    
        <widget-extension widgetId="explorerTree">
            <move widgetId="hmc2" targetWidgetId="hmc2" targetSlotId="rightSlot" failOnError="true"/>
        </widget-extension>
     
    <widget-extension widgetId="collapsibleContainer">
            <remove widgetId="editorArea"/>
        </widget-extension>
     
     <widget-extension widgetId="hmc2">
         <widget id="portal" widgetDefinitionId="com.hybris.cockpitng.defaultportalwidget" slotId="leftSlot"/>
     </widget-extension>  
     
     <widget-extension widgetId="portal">
            <widget id="Input" widgetDefinitionId="com.hybris.cockpitng.inputtestwidget" slotId="children"/>
            <widget id="Output" widgetDefinitionId="com.hybris.cockpitng.outputtestwidget" slotId="children"/>
        </widget-extension>
     
    <widget-extension widgetId="portal">
            <remove-all/>
        </widget-extension>
  2. Press F4 on your keyboard to go to the Application Orchestrator view.
  3. Expand the menu in the top-right corner.
  4. From the expanded menu, select the Reset Everything option.
  5. In the pop-up window Reset Configuration, click Yes.

    The result is the following:

Defining Widgets Virtual Sockets

If you want to define any virtual sockets to a given widget, you can use virtual-sockets tag. In this procedure, it is presented how to define the input and output sockets (both of type java.lang.String) in the Portal Layout widget.

Procedure

  1. Add the following code snippet to the myextension-backoffice-widgets.xml file:

    /resources/myextension-backoffice-widgets.xml

    <widget-extension widgetId="portal">
            <virtual-sockets>
    			<input id="extendingInputSocket" type="java.lang.String" />
    			<output id="extendingOutputSocket" type="java.lang.String" />
            </virtual-sockets>
    	</widget-extension>

    Below, you can find an example of configuration of the myextension-backoffice-widgets.xml file:

    myextension-backoffice-widgets.xml

    <widget-extension widgetId="hmc2" >
            <setting key="eastDisabled" type="Boolean" value="false"/>
        </widget-extension>
    
        <widget-extension widgetId="explorerTree">
            <move widgetId="hmc2" targetWidgetId="hmc2" targetSlotId="rightSlot" failOnError="true"/>
        </widget-extension>
     
    <widget-extension widgetId="collapsibleContainer">
            <remove widgetId="editorArea"/>
        </widget-extension>
     
     <widget-extension widgetId="hmc2">
         <widget id="portal" widgetDefinitionId="com.hybris.cockpitng.defaultportalwidget" slotId="leftSlot"/>
     </widget-extension>  
     
     <widget-extension widgetId="portal">
            <widget id="Input" widgetDefinitionId="com.hybris.cockpitng.inputtestwidget" slotId="children"/>
            <widget id="Output" widgetDefinitionId="com.hybris.cockpitng.outputtestwidget" slotId="children"/>
        </widget-extension>
     
    <widget-extension widgetId="portal">
            <remove-all/>
        </widget-extension>
     
    <widget-extension widgetId="portal">
            <virtual-sockets>
    			<input id="extendingInputSocket" type="java.lang.String" />
    			<output id="extendingOutputSocket" type="java.lang.String" />
            </virtual-sockets>
    	</widget-extension>
  2. Press F4 on your keyboard to go to the Application Orchestrator view.
  3. Expand the menu in the top-right corner.
  4. From the expanded menu, select the Reset Everything option.
  5. In the pop-up window Reset Configuration, click Yes.
  6. Click the Widget Settings icon of the Portal Layout widget, navigate to the Virtual sockets tab.

    Tthe results of the procedure are shown.

  7. For more information about virtual sockets, see the Virtual Sockets.