Class Alert

java.lang.Object
overit.geocall.ui.Alert
All Implemented Interfaces:
SingleUseComponent

public class Alert extends Object implements SingleUseComponent
The class implements the user interface element that should be used to display on-screen messages that appear in popups and blocks the user interaction; they can be informational messages, question, warnings or error messages. The user must interact with the alert, even just by closing it, in order to proceed with the operation.
In addition to the message, the alert can contain buttons and radio params that allows the user to make a choice from a list of possibilities.
The class implements the SingleUseComponent interface.
  • Field Details

    • _sequence

      protected static AtomicLong _sequence
    • _id

      protected String _id
    • NONE

      public static final int NONE
      Defines a generic alert; no icons will appears in the body of the alert.
      See Also:
    • ERROR

      public static final int ERROR
      Defines an alert that contains an error message; in the body of the alert will appears an error icon.
      See Also:
    • WARNING

      public static final int WARNING
      Defines an alert that contains a warning message; in the body of the alert will appears a warning icon.
      See Also:
    • MESSAGE

      public static final int MESSAGE
      Defines an alert that contains an informational message; in the body of the alert will appears a info icon.
      See Also:
    • QUESTION

      public static final int QUESTION
      Defines an alert that contains a question message; in the body of the alert will appears a question icon.
      See Also:
    • _iAlertType

      protected int _iAlertType
    • _sTitle

      protected String _sTitle
    • _sMessage

      protected String _sMessage
    • _objects

      protected Object[] _objects
    • _params

      protected Map _params
    • _buttons

      protected ArrayList<Alert.Button> _buttons
    • _defaultButton

      protected int _defaultButton
    • _radios

      protected ArrayList<Alert.RadioParam> _radios
  • Constructor Details

    • Alert

      public Alert(Teacher teacher)
      Creates an error alert with empty title and message
      Parameters:
      teacher - The component that manage the translations (see Teacher)
    • Alert

      public Alert(int iType, Teacher teacher)
      Creates an alert of the type passed as parameter with empty title and messages
      Parameters:
      iType - The type of the alert, one of NONE, ERROR, WARNING, MESSAGE, QUESTION
      teacher - The component that manage the translations (see Teacher)
    • Alert

      public Alert(int type, String title, String message, Teacher teacher)
      Creates an alert of the type passed as parameter with the specific title and message
      Parameters:
      type - The type of the alert, one of NONE, ERROR, WARNING, MESSAGE, QUESTION
      title - The string that appears in the header of the alert
      message - The message that appears in the alert's body
      teacher - The component that manage the translations (see Teacher)
    • Alert

      public Alert(String title, Exception e, Teacher teacher)
      Creates an error alert starting from an exception
      Parameters:
      title - The string that appears in the header of the alert
      e - The exception of which we want to show the message
      teacher - The component that manage the translations (see Teacher)
    • Alert

      public Alert(String title, DAValidateException e, Teacher teacher)
      Creates a warning alert strating from a DAValidateException
      Parameters:
      title - The string that appears in the header of the alert
      e - The DAValidateException of which we want to show the message
      teacher - The component that manage the translations (see Teacher)
  • Method Details

    • getTeacher

      public Teacher getTeacher()
      Returns the Teacher, the object that manages the translations
      Returns:
      The Teacher that manages the translations
    • setAlertType

      public void setAlertType(int type)
      Sets the type of the alert
      Parameters:
      type - One of NONE, ERROR, WARNING, MESSAGE, QUESTION
    • setTitle

      public void setTitle(String message)
      Sets the title of the alert, the string that appears in the alert's header
      Parameters:
      message - The title that appears in the header
    • setMessage

      public void setMessage(String message)
      Sets the message of the alert, the string that appears in the alert's body
      Parameters:
      message - The message that appears in the body
    • setMessage

      public void setMessage(String message, Object... oo)
      Sets the message (see TextFormat) of the alert and the objects that will be used to fill in the message
      Parameters:
      message - The message that appears in the body
      oo - The objects that will be used to fill in the message
    • setMessage

      public void setMessage(String message, Map params)
      Sets the message (see MapFormat) of the alert and the map that will be used to fill in the message
      Parameters:
      message - The message that appears in the body
      params - The map that will be used to fill in the message
    • setCloseEvent

      public void setCloseEvent(String eventId)
      Sets an event to be triggered if the popup is closed
      Parameters:
      eventId - The event triggered when the user clicks on the button
    • setCloseEventParam

      public void setCloseEventParam(String param)
      Sets additional parameters for the event triggered when the popup is closed
      Parameters:
      param - The parameter passed to the event triggered when the user clicks the button
    • getAlertType

      public int getAlertType()
      Returns the alert's type
      Returns:
      One of NONE, ERROR, WARNING, MESSAGE, QUESTION
    • getTitle

      public String getTitle()
      Returns the alert's title
      Returns:
      The string that represents the alert title
    • getMessage

      public String getMessage()
      Returns the alert's message
      Returns:
      The string that represents the alert message
    • setDefaultButton

      public void setDefaultButton(int def)
      Sets wich one must be the default button for the alert
      Parameters:
      def - The integer that defines the position (from left to right) of the button that must be the default one
    • addButton

      public void addButton(String label, String icon, String event, String id)
      Adds a clickable button (Alert.Button) to the bottom of the alert
      Parameters:
      label - The label that appears on the button
      icon - The icon that appears on the button
      event - The event triggered when the user clicks on the button
      id - The target for the event
    • addButton

      public void addButton(String label, String icon, String event, String id, String param, String msg, String prompt)
      Adds a clickable button (Alert.Button) to the bottom of the alert
      Parameters:
      label - The label that appears on the button
      icon - The icon that appears on the button
      event - The event triggered when the user clicks on the button
      id - The target for the event
      param - The parameter passed to the event triggered when the user clicks the button
      msg - The string that appears as a message when the user clicks the button
      prompt - The string that appears as a prompt when the user clicks the button
    • addRadioParam

      public void addRadioParam(String label, String param, boolean def)
      Adds a radio param (Alert.RadioParam) to the body of the alert. Use this method to add multiple choices selectable with a single button, and prevent a large number of buttons.
      Parameters:
      label - The label string associated to the chioce
      param - The parameter associated to the chioce, passed to the event of the button of the alert
      def - true if this one must be the default selected choice when the alert appears, false otherwise
    • add

      public void add(Alert.Button button)
      Adds a Alert.Button to the bottom of the alert
      Parameters:
      button - The button to add to the alert
    • add

      public void add(Alert.RadioParam radio)
      Adds a Alert.RadioParam to the body of the alert
      Parameters:
      radio - The radio param to add to the alert
    • getButtons

      public ArrayList getButtons()
      Returns the list of Alert.Button of the alert
      Returns:
      The list of buttons
    • getHtml

      public org.apache.ecs.Element getHtml(EntitySet es, Window w)
      Returns the html code of the alert
      Specified by:
      getHtml in interface SingleUseComponent
      Parameters:
      es - the page entity set
      w - the window onto expose the alert
      Returns:
      The html code of the alert
    • getFooter

      protected org.apache.ecs.Element getFooter(EntitySet es, Window w)
    • getIcon

      public static IconHD getIcon(int type)
      Returns the theme-dependent icon associated to the alert type
      Parameters:
      type - The alert type, one of NONE, ERROR, WARNING, MESSAGE, QUESTION
      Returns:
      The icon associated to the alert type
    • setAltAttribute

      protected void setAltAttribute(Icon icon, int type)
    • getTitleBar

      protected org.apache.ecs.Element getTitleBar(String title, Window w)
    • buildSetupScript

      public void buildSetupScript(StringBuilder sb)
      Every component can add a script to the StringBuilder, script executed when the component is created The method add the script that manage the creation and showing of the alert
      Specified by:
      buildSetupScript in interface SingleUseComponent
      Parameters:
      sb - The StringBuilder on which we want to add the script