Custom Dialog Notification For Use In -rt Module Part

I spent some time figuring out how to implement custom dialog notifications in the ddctCommunity-rt module part for logging plugin messages and thought it might be useful for others :sweat_smile:. This allows you to log results the same way running a robot does. However you can customise the dialog layout with BWidget elements however you please.

Here’s a quick reference guide:

Raising the Notification

To raise a custom dialog notification, you can use the following code snippet:

BDialogNotification notification = new BDialogNotification();
notification.setDialogTitle("Alarm Extensions");
notification.setDialogMessage("Your message or log results......");
notification.raise(false); //If you do not set false the notification will be raised to all connected clients.

BDialogNotification for Module -rt Part

To create a BDialogNotification for the -rt module part, you can define the notification class as follows. This allows assigning the agent view from the -wb part.

package com.ddccommunity.ddctCommunity.notifications;

import javax.baja.nre.annotations.NiagaraProperty;
import javax.baja.nre.annotations.NiagaraType;
import javax.baja.util.BNotification;
import javax.baja.sys.Property;
import javax.baja.sys.Sys;
import javax.baja.sys.Type;

@NiagaraType
@NiagaraProperty(
        name = "dialogTitle",
        type = "String",
        defaultValue = ""
)
@NiagaraProperty(
        name = "dialogMessage",
        type = "String",
        defaultValue = ""
)
public class BDialogNotification extends BNotification {
//region /*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/
//@formatter:off
/*@ $com.ddccommunity.ddctCommunity.notifications.BDialogNotification(1009021973)1.0$ @*/
/* Generated Mon Aug 05 14:24:20 AEST 2024 by Slot-o-Matic (c) Tridium, Inc. 2012-2024 */

  //region Property "dialogTitle"

  /**
   * Slot for the {@code dialogTitle} property.
   * @see #getDialogTitle
   * @see #setDialogTitle
   */
  public static final Property dialogTitle = newProperty(0, "", null);

  /**
   * Get the {@code dialogTitle} property.
   * @see #dialogTitle
   */
  public String getDialogTitle() { return getString(dialogTitle); }

  /**
   * Set the {@code dialogTitle} property.
   * @see #dialogTitle
   */
  public void setDialogTitle(String v) { setString(dialogTitle, v, null); }

  //endregion Property "dialogTitle"

  //region Property "dialogMessage"

  /**
   * Slot for the {@code dialogMessage} property.
   * @see #getDialogMessage
   * @see #setDialogMessage
   */
  public static final Property dialogMessage = newProperty(0, "", null);

  /**
   * Get the {@code dialogMessage} property.
   * @see #dialogMessage
   */
  public String getDialogMessage() { return getString(dialogMessage); }

  /**
   * Set the {@code dialogMessage} property.
   * @see #dialogMessage
   */
  public void setDialogMessage(String v) { setString(dialogMessage, v, null); }

  //endregion Property "dialogMessage"

  //region Type

  @Override
  public Type getType() { return TYPE; }
  public static final Type TYPE = Sys.loadType(BDialogNotification.class);

  //endregion Type

//@formatter:on
//endregion /*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/
    public BDialogNotification(){}
}

Custom Notification Handler

The custom notification handler processes the notification and displays it in a dialog. Below is the code for the handler and goes in the -wb module part:

package com.ddctalk.ddctCommunity.ui.dialogs;

import com.ddccommunity.ddctCommunity.notifications.BDialogNotification;

import javax.baja.nre.annotations.AgentOn;
import javax.baja.nre.annotations.NiagaraType;
import javax.baja.sys.Context;
import javax.baja.ui.BDialog;
import javax.baja.ui.pane.BTextEditorPane;
import javax.baja.ui.text.BTextEditor;
import javax.baja.util.BNotification;
import javax.baja.workbench.BWbShell;
import javax.baja.workbench.util.BNotificationHandler;
import javax.baja.sys.Sys;
import javax.baja.sys.Type;

@NiagaraType(
        agent = @AgentOn(types = "ddctCommunity:DialogNotification")
)
public class BDialogNotificationHandler extends BNotificationHandler {

//region /*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/
//@formatter:off
/*@ $com.ddctalk.ddctCommunity.ui.dialogs.BDialogNotificationHandler(2581040743)1.0$ @*/
/* Generated Mon Aug 05 14:24:17 AEST 2024 by Slot-o-Matic (c) Tridium, Inc. 2012-2024 */

  //region Type

  @Override
  public Type getType() { return TYPE; }
  public static final Type TYPE = Sys.loadType(BDialogNotificationHandler.class);

  //endregion Type

//@formatter:on
//endregion /*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/
public BDialogNotificationHandler(){}

    @Override
    public void handle(BWbShell shell, BNotification notify, Context cx) {
        BDialogNotification item = (BDialogNotification)notify;

        BTextEditor textEditor = new BTextEditor(item.getDialogMessage(), false);
        BTextEditorPane textEditorPane = new BTextEditorPane(textEditor, 20, 80);

        BDialog.message(shell, item.getDialogTitle(), textEditorPane);
    }
}

Summary

  • Raising the Notification: Use the BDialogNotification class to set the title and message, then raise the notification.
  • Custom Notification Class: Define the BDialogNotification class in the -rt module part with properties for the dialog title and message.
  • Notification Handler: Implement the BDialogNotificationHandler class to handle the notification and display the dialog in the agent view from the -wb part.
3 Likes