Creating a Reusable Widget Group for Use on Separate Host Machines
In the Backoffice Application you can reuse a group of widgets within a single instance. Such group can only be used from a single host machine because the grouping is externalized as a jar file in the machine's filesystem. Widget groups can be made reusable for sharing with other developers and used on separate host machines.
Procedure
- From the Application Orchestrator, create the widget configuration that you want to reuse.
For this example, a Border Layout containing two test widgets will be made into a reusable group.
- The Border Layout widget was given the ID nonGroupedWidgetsContainer. The east slot was disabled.
- InputTestWidget and OutputTestWidget were added to the remaining two slots and were given the IDs nonGroupedInput and nonGroupedOutput respectively.
- The InputTestWidget's singleoutput socket was connected to the OutputTestWidget's genericInput socket.
The following screenshot illustrates the symbolic view for the example. The elements in the red box represent what will become the reusable widget group.
If you click the hybris logo → Show widgets.xml, part of the file should contain the nonGroupedWidgetsContainer widget configuration, with its two child widgets, nonGroupedInput and nonGroupedOutput, as shown in the following example.
widgets.xml... <widget id="nonGroupedWidgetsContainer" widgetDefinitionId="com.hybris.cockpitng.borderlayout" slotId="centerSlot" template="false"> <widget id="nonGroupedInput" widgetDefinitionId="com.hybris.cockpitng.inputtestwidget" slotId="leftSlot" template="false"> <setting key="defaultScript" value="" type="String"/> <setting key="socketDataType_$T" value="java.lang.Object" type="String"/> <setting key="widgetStyleAttribute" value="" type="String"/> <setting key="textAreaHeight" value="300" type="Integer"/> <setting key="widgetStyleClass" value="" type="String"/> <virtual-sockets/> </widget> <widget id="nonGroupedOutput" widgetDefinitionId="com.hybris.cockpitng.outputtestwidget" slotId="centerSlot" template="false"> <setting key="widgetStyleAttribute" value="" type="String"/> <setting key="widgetStyleClass" value="" type="String"/> <virtual-sockets/> </widget> <setting key="opaqueBG" value="true" type="String"/> <setting key="southHeight" value="50px" type="String"/> <setting key="widgetStyleAttribute" value="" type="String"/> <setting key="northHeight" value="50px" type="String"/> <setting key="westBorder" value="none" type="String"/> <setting key="northBorder" value="none" type="String"/> <setting key="eastDisabled" value="true" type="Boolean"/> <setting key="southBorder" value="none" type="String"/> <setting key="southDisabled" value="true" type="Boolean"/> <setting key="eastBorder" value="none" type="String"/> <setting key="northDisabled" value="true" type="Boolean"/> <setting key="eastWidth" value="25%" type="String"/> <setting key="westCollapsible" value="true" type="Boolean"/> <setting key="widgetStyleClass" value="" type="String"/> <setting key="southCollapsible" value="true" type="Boolean"/> <setting key="northCollapsible" value="true" type="Boolean"/> <setting key="border" value="none" type="String"/> <setting key="westWidth" value="300px" type="String"/> <setting key="centerBorder" value="none" type="String"/> <setting key="westDisabled" value="false" type="Boolean"/> <setting key="eastCollapsible" value="true" type="Boolean"/> <virtual-sockets/> </widget>
The widgets.xml file should also list the socket connection definition after the widget definitions as follows:
widgets.xml
... <widget-connection sourceWidgetId="nonGroupedInput" outputId="singleoutput" targetWidgetId="nonGroupedOutput" inputId="genericInput"/> ...
- Create the widget resources folder and add the definition.xml and widgets.xml files.
- Add your widget definition to definition.xml. In the following example, the category defined through the keyword element is Groups, but you can use any category.
definition.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <widget-definition id="com.hybris.cockpitng.widgetgroupdemo"> <sockets/> <name>Widget Group Demo</name> <description>Shows how to create reusable widget groups</description> <version>1.0</version> <keywords> <keyword>Groups</keyword> </keywords> </widget-definition> - Copy the widget wiring for nonGroupedWidgetsContainer from Show widgets.xml, and paste itinto your newly-created widgets.xml file. Change the settings:
- The widget parent ID should match the definition ID for the widget - in this example: widget id="com.hybris.cockpitng.widgetgroupdemo".
- By convention, the widget parent's slotId should be set up to composedRootSlot.
widgets.xml<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <widgets> <widget id="com.hybris.cockpitng.widgetgroupdemo" widgetDefinitionId="com.hybris.cockpitng.borderlayout" slotId="composedRootSlot" template="false"> <widget id="nonGroupedInput" widgetDefinitionId="com.hybris.cockpitng.inputtestwidget" slotId="leftSlot" template="false"> <setting key="defaultScript" value="" type="String"/> <setting key="widgetStyleAttribute" value="" type="String"/> <setting key="textAreaHeight" value="300" type="Integer"/> <setting key="widgetStyleClass" value="" type="String"/> <virtual-sockets/> </widget> <widget id="nonGroupedOutput" widgetDefinitionId="com.hybris.cockpitng.outputtestwidget" slotId="centerSlot" template="false"> <setting key="widgetStyleAttribute" value="" type="String"/> <setting key="widgetStyleClass" value="" type="String"/> <virtual-sockets/> </widget> <setting key="opaqueBG" value="true" type="String"/> <setting key="southHeight" value="50px" type="String"/> <setting key="widgetStyleAttribute" value="" type="String"/> <setting key="northHeight" value="50px" type="String"/> <setting key="westBorder" value="none" type="String"/> <setting key="northBorder" value="none" type="String"/> <setting key="eastDisabled" value="true" type="Boolean"/> <setting key="southBorder" value="none" type="String"/> <setting key="southDisabled" value="true" type="Boolean"/> <setting key="eastBorder" value="none" type="String"/> <setting key="northDisabled" value="true" type="Boolean"/> <setting key="eastWidth" value="25%" type="String"/> <setting key="westCollapsible" value="true" type="Boolean"/> <setting key="widgetStyleClass" value="" type="String"/> <setting key="southCollapsible" value="true" type="Boolean"/> <setting key="northCollapsible" value="true" type="Boolean"/> <setting key="border" value="none" type="String"/> <setting key="westWidth" value="300px" type="String"/> <setting key="centerBorder" value="none" type="String"/> <setting key="westDisabled" value="false" type="Boolean"/> <setting key="eastCollapsible" value="true" type="Boolean"/> <virtual-sockets/> </widget> </widgets>
- Copy the widget connection definition <widget-connection ... /> to the end of your widgets.xml file, between the closing </widget> and </widgets> elements, as shown.
widgets.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <widgets> <widget id="com.hybris.cockpitng.widgetgroupdemo" widgetDefinitionId="com.hybris.cockpitng.borderlayout" slotId="composedRootSlot" template="false"> ... </widget> <widget-connection sourceWidgetId="nonGroupedInput" outputId="singleoutput" targetWidgetId="nonGroupedOutput" inputId="genericInput"/> </widgets>
- Rebuild your system.
You can now add the new group widget to your application.
- To add the widget group from the Application Orchestrator, click the Add Widgets
button, then look for your widget under the category specified in the definition.xml file. In this example Groups. Click the Add & close button in the Choose widget window.
In the following example, the reusable widget group was added to the right slot of a Border Layout widget and is automatically set to be a widget group. The individual parts of the widget group are visible but not editable until you ungroup the widget.
- To add the widget group to another custom widget, use the widget group ID, as shown in the following example.
<widget id="groupingDemoSlot" widgetDefinitionId="com.hybris.cockpitng.borderlayout" slotId="grouping_demo" template="false"> ... <widget id="groupedWidgetsContainer" widgetDefinitionId="com.hybris.cockpitng.widgetgroupdemo" slotId="centerSlot" template="false"> <setting key="/com.hybris.cockpitng.widgetgroupdemo/northHeight" value="50px" type="String"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/eastBorder" value="none" type="String"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/southHeight" value="50px" type="String"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/northBorder" value="none" type="String"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/opaqueBG" value="true" type="String"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/westCollapsible" value="true" type="Boolean"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/westDisabled" value="false" type="Boolean"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/westBorder" value="none" type="String"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/southBorder" value="none" type="String"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/eastWidth" value="25%" type="String"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/westWidth" value="50%" type="String"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/southCollapsible" value="true" type="Boolean"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/eastDisabled" value="true" type="Boolean"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/centerBorder" value="none" type="String"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/northCollapsible" value="true" type="Boolean"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/southDisabled" value="true" type="Boolean"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/border" value="none" type="String"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/northDisabled" value="true" type="Boolean"/> <setting key="/com.hybris.cockpitng.widgetgroupdemo/eastCollapsible" value="true" type="Boolean"/> <setting key="widgetStyleAttribute" value="" type="String"/> <setting key="widgetStyleClass" value="" type="String"/> <virtual-sockets/> </widget> ... </widget>
- To add the widget group from the Application Orchestrator, click the Add Widgets