...
This the the base class for UI functionality. The salient features to note are introduced briefly below.
(1) Reference to the UiExtensionService:
Code Block | ||
---|---|---|
| ||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected UiExtensionService uiExtensionService; |
(2) List of application view descriptors, defining which category the view appears under in the GUI navigation pane (if not a hidden view), the display text for the link, and the internal identifier for the view:
Code Block | ||
---|---|---|
| ||
// List of application views
private final List<UiView> uiViews = ImmutableList.of(
new UiView(UiView.Category.OTHER, "sample", "Sample")
); |
(3) Declaration of a UiMessageHandlerFactory to generate message handlers on demand. The example factory generates a single handler each time, AppUiMessageHandler, described below:
Code Block | ||
---|---|---|
| ||
// Factory for UI message handlers
private final UiMessageHandlerFactory messageHandlerFactory =
() -> ImmutableList.of(
new AppUiMessageHandler()
); |
(4) Declaration of a UiExtension, configured with the previously declared UI view descriptors and message handler factory:
Code Block | ||
---|---|---|
| ||
// Application UI extension protected UiExtension extension = new UiExtension.Builder(getClass().getClassLoader(), uiViews) .messageHandlerFactory(messageHandlerFactory) .build(); |
(5) Activation and deactivation callbacks that register and unregister the UI extension at the appropriate times:
Code Block | ||
---|---|---|
| ||
@Activate protected void activate() { uiExtensionService.register(extension); log.info("Started"); } @Deactivate protected void deactivate() { uiExtensionService.unregister(extension); log.info("Stopped"); } |