Class PNActions

All Implemented Interfaces:
EventListener, IGProp<GProp<?>[]>, IPropCnr, Cloneable

public class PNActions extends PropCnr
The ordered container of the PNAction children of a PNMessageProp, i.e. the actions array of the browser showNotification(title,options) call.

Index is relevant here, and it is the only push container for which it is. The actions of a notification are displayed as buttons in the order the caller gave them, so the order is part of what is delivered and usesPropIndex() returns true - the same choice ArrayProp and ActionActors make for the same reason. That makes the order part of the wire contract as well as of the XML: the transaction that streams this container to the client carries the child index.

Contrast PNSpoolerRoot, which returns false: the spool has no positional access, its replay order comes from a sort on load, and its children churn constantly because a retry removes and re-adds an entry. Here nothing churns - a notification's actions are built once, before it is sent, and are never edited afterwards - so keeping the index costs nothing and buying the order is worth it.

An empty actions container is not written to XML, so a notification without actions costs no element. It is recreated empty by PNMessageProp's predefined properties on the way back in, which is why omitting it does not change the reloaded tree.

JS-facing. This container streams to the JavaScript client and needs no new JavaScript class: it is reconstructed by the generic PropCnr JavaScript, which is what the jsclient="PropCnr" registration in base-properties.xml selects.

Author:
Christopher Mindus
  • Field Details

    • ACTION_BASE_NAME

      public static final String ACTION_BASE_NAME
      The base name used to generate a unique atom for a new action child: "action".
      See Also:
  • Constructor Details

    • PNActions

      public PNActions()
      Creates a push notification actions container without name and with a null value.
    • PNActions

      public PNActions(Atom propertyAtom)
      Creates a push notification actions container with the specified name with a null value.
      Parameters:
      propertyAtom - The property atom.
  • Method Details

    • clone

      public PNActions clone()
      Creates a clone out of this property.
      Overrides:
      clone in class PropCnr
      Returns:
      The clone of the push notification actions container.
    • usesPropIndex

      public final boolean usesPropIndex()
      Use of index for this property container is enabled: the display order of the action buttons is part of what is delivered.
      Specified by:
      usesPropIndex in interface IPropCnr
      Overrides:
      usesPropIndex in class PropCnr
      Returns:
      true for this container.
    • getActions

      public PNAction[] getActions()
      Gets the actions in order.
      Returns:
      The actions, in the order they will be displayed; an empty array when there are none, never null.
    • getActionCount

      public int getActionCount()
      Gets the number of actions.
      Returns:
      The action count.
    • addAction

      public PNAction addAction(String action, String title, String icon, String navigate) throws PropException
      Appends a new action at the end of the container, i.e. after every action added so far.

      The child is given a generated unique atom, because an action has no natural name - its identity to the service worker is the value of its PNAction.ACTION property, not its property name, and its identity to the user is its position.

      Parameters:
      action - The service-worker action identifier, or null to leave unset.
      title - The button label, or null to leave unset.
      icon - The icon URL, or null to leave unset.
      navigate - The navigation URL, or null to leave unset.
      Returns:
      The new action, already added to this container.
      Throws:
      PropException - If the action cannot be added.
    • shouldSerializeToXML

      protected boolean shouldSerializeToXML(int programType)
      Checks whether this container should be written to XML: an empty actions container is not, because PNMessageProp recreates it as a predefined property on load and an empty element would only add noise to every spooled notification.
      Overrides:
      shouldSerializeToXML in class GProp<GProp<?>[]>
      Parameters:
      programType - From PropFactory.getProgramType(): 0=PropFactory.CLIENT, 1=PropFactory.SERVER or 2=PropFactory.EDITOR.
      Returns:
      true to save to XML, false to skip this container.