Class DefaultLogixNG

java.lang.Object
jmri.implementation.AbstractNamedBean
jmri.jmrit.logixng.implementation.DefaultLogixNG
All Implemented Interfaces:
Comparable<NamedBean>, PropertyChangeProvider, Base, LogixNG, NamedBean

public class DefaultLogixNG
extends AbstractNamedBean
implements LogixNG
The default implementation of LogixNG.
  • Constructor Details

  • Method Details

    • getParent

      public Base getParent()
      Get the parent.

      The following rules apply

      • LogixNGs has no parent. The method throws an UnsupportedOperationException if called.
      • Expressions and actions has the male socket that they are connected to as their parent.
      • Male sockets has the female socket that they are connected to as their parent.
      • The parent of a female sockets is the LogixNG, expression or action that has this female socket.
      • The parent of a male sockets is the same parent as the expression or action that it contains.
      Specified by:
      getParent in interface Base
      Returns:
      the parent of this object
    • setParent

      public void setParent​(Base parent)
      Set the parent.

      The following rules apply

      • ExecutionGroups has no parent. The method throws an UnsupportedOperationException if called.
      • LogixNGs has the execution group as its parent.
      • Expressions and actions has the male socket that they are connected to as their parent.
      • Male sockets has the female socket that they are connected to as their parent.
      • The parent of a female sockets is the LogixNG, expression or action that has this female socket.
      • The parent of a male sockets is the same parent as the expression or action that it contains.
      Specified by:
      setParent in interface Base
      Parameters:
      parent - the new parent of this object
    • getBeanType

      public String getBeanType()
      Description copied from interface: NamedBean
      For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.
      Specified by:
      getBeanType in interface NamedBean
      Returns:
      a string of the bean type, eg Turnout, Sensor etc
    • setState

      public void setState​(int s) throws JmriException
      Description copied from interface: NamedBean
      Provide generic access to internal state.

      This generally shouldn't be used by Java code; use the class-specific form instead (e.g. setCommandedState in Turnout). This is provided to make scripts access easier to read.

      Specified by:
      setState in interface NamedBean
      Parameters:
      s - the state
      Throws:
      JmriException - general error when setting the state fails
    • getState

      public int getState()
      Description copied from interface: NamedBean
      Provide generic access to internal state.

      This generally shouldn't be used by Java code; use the class-specific form instead (e.g. getCommandedState in Turnout). This is provided to make scripts easier to read.

      Specified by:
      getState in interface NamedBean
      Returns:
      the state
    • getShortDescription

      public String getShortDescription​(Locale locale)
      Description copied from interface: Base
      Get a short description of this item.
      Specified by:
      getShortDescription in interface Base
      Parameters:
      locale - The locale to be used
      Returns:
      a short description
    • getLongDescription

      public String getLongDescription​(Locale locale)
      Description copied from interface: Base
      Get a long description of this item.
      Specified by:
      getLongDescription in interface Base
      Parameters:
      locale - The locale to be used
      Returns:
      a long description
    • getChild

      Description copied from interface: Base
      Get a child of this item
      Specified by:
      getChild in interface Base
      Parameters:
      index - the index of the child to get
      Returns:
      the child
      Throws:
      IllegalArgumentException - if the index is less than 0 or greater or equal with the value returned by getChildCount()
      UnsupportedOperationException
    • getChildCount

      public int getChildCount()
      Description copied from interface: Base
      Get the number of children.
      Specified by:
      getChildCount in interface Base
      Returns:
      the number of children
    • getCategory

      Description copied from interface: Base
      Get the category.
      Specified by:
      getCategory in interface Base
      Returns:
      the category
    • isExternal

      public boolean isExternal()
      Description copied from interface: Base
      Is this external? Does it affects or is dependent on external things, like turnouts and sensors? Timers are considered as internal since they behavies the same on every computer on every layout.
      Specified by:
      isExternal in interface Base
      Returns:
      true if this is external
    • setup

      public final void setup()
      Setup this object and its children. This method is used to lookup system names for child sockets, turnouts, sensors, and so on.
      Specified by:
      setup in interface Base
    • setEnabled

      public void setEnabled​(boolean enable)
      Set whenether this LogixNG is enabled or disabled.

      This method must call registerListeners() / unregisterListeners() and also call execute() if enable is true.

      Specified by:
      setEnabled in interface LogixNG
      Parameters:
      enable - true if this LogixNG should be enabled, false otherwise
    • isEnabled

      public boolean isEnabled()
      Determines whether this LogixNG is enabled.
      Specified by:
      isEnabled in interface Base
      Specified by:
      isEnabled in interface LogixNG
      Returns:
      true if the LogixNG is enabled, false otherwise
    • getConditionalNG_SystemName

      public String getConditionalNG_SystemName​(int index)
      Set the system name for the conditionalNG at the specified position in this list
      Specified by:
      getConditionalNG_SystemName in interface LogixNG
      Parameters:
      index - index of the element to set the system name
      Returns:
      the system name
    • setConditionalNG_SystemName

      public void setConditionalNG_SystemName​(int index, String systemName)
      Set the system name for the conditionalNG at the specified position in this list
      Specified by:
      setConditionalNG_SystemName in interface LogixNG
      Parameters:
      index - index of the element to set the system name
      systemName - the new system name
    • getNumConditionalNGs

      public int getNumConditionalNGs()
      Get number of ConditionalNGs for this LogixNG.
      Specified by:
      getNumConditionalNGs in interface LogixNG
      Returns:
      the number of conditionals
    • swapConditionalNG

      public void swapConditionalNG​(int nextInOrder, int row)
      Move 'row' to 'nextInOrder' and shift all between 'nextInOrder' and 'row' up one position. Requires row > nextInOrder.
      Specified by:
      swapConditionalNG in interface LogixNG
      Parameters:
      nextInOrder - target order for ConditionalNG at row
      row - position of ConditionalNG to move
    • getConditionalNG

      public ConditionalNG getConditionalNG​(int order)
      Returns the conditionalNG that will calculate in the specified order. This is also the order the ConditionalNG is listed in the Add/Edit LogixNG dialog. If 'order' is greater than the number of ConditionalNGs for this LogixNG, null is returned.
      Specified by:
      getConditionalNG in interface LogixNG
      Parameters:
      order - order in which the ConditionalNG calculates
      Returns:
      the conditionalNG or null
    • addConditionalNG

      public boolean addConditionalNG​(ConditionalNG conditionalNG)
      Add a child ConditionalNG to the parent LogixNG.

      The first part handles adding conditionalNGs to the LogixNG list during file loading.

      The second part handles normal additions using the GUI, Logix imports or tests.

      Specified by:
      addConditionalNG in interface LogixNG
      Parameters:
      conditionalNG - The ConditionalNG object.
      Returns:
      true if the ConditionalNG was added, false otherwise.
    • getConditionalNG

      public ConditionalNG getConditionalNG​(String systemName)
      Get a ConditionalNG belonging to this LogixNG.
      Specified by:
      getConditionalNG in interface LogixNG
      Parameters:
      systemName - The name of the ConditionalNG object.
      Returns:
      the ConditionalNG object or null if not found.
    • getConditionalNGByUserName

      Get a ConditionalNG belonging to this LogixNG.
      Specified by:
      getConditionalNGByUserName in interface LogixNG
      Parameters:
      userName - The name of the ConditionalNG object.
      Returns:
      the ConditionalNG object or null if not found.
    • deleteConditionalNG

      public void deleteConditionalNG​(ConditionalNG conditionalNG)
      Delete a ConditionalNG from this LogixNG.

      Note: Since each LogixNG must have at least one ConditionalNG, the last ConditionalNG will not be deleted.

      Returns An array of names used in an error message explaining why ConditionalNG should not be deleted.

      Specified by:
      deleteConditionalNG in interface LogixNG
      Parameters:
      conditionalNG - The ConditionalNG to delete
    • isActive

      public boolean isActive()
      Is this item active? If this item is enabled and all the parents are enabled, this item is active.
      Specified by:
      isActive in interface Base
      Returns:
      true if active, false otherwise.
    • execute

      public void execute()
      Execute all ConditionalNGs if the LogixNG is enabled and activated.
      Specified by:
      execute in interface LogixNG
    • execute

      public void execute​(boolean allowRunDelayed)
      Execute all ConditionalNGs if the LogixNG is enabled and activated.
      Specified by:
      execute in interface LogixNG
      Parameters:
      allowRunDelayed - true if it's ok to run delayed, false otherwise
    • getConditionalNG

      Get the ConditionalNG of this item.
      Specified by:
      getConditionalNG in interface Base
      Returns:
      the ConditionalNG that owns this item
    • getLogixNG

      public LogixNG getLogixNG()
      Get the LogixNG of this item.
      Specified by:
      getLogixNG in interface Base
      Returns:
      the LogixNG that owns this item
    • getRoot

      public final Base getRoot()
      Get the root of the tree that this item belongs to.
      Specified by:
      getRoot in interface Base
      Returns:
      the top most item in the tree
    • setParentForAllChildren

      public boolean setParentForAllChildren​(List<String> errors)
      Set the parent for all the children.
      Specified by:
      setParentForAllChildren in interface Base
      Parameters:
      errors - a list of potential errors
      Returns:
      true if success, false otherwise
    • registerListeners

      public void registerListeners()
      Register listeners if this object needs that.

      Important: This method may be called more than once. Methods overriding this method must ensure that listeners are not registered more than once.

      Specified by:
      registerListeners in interface Base
    • unregisterListeners

      public void unregisterListeners()
      Unregister listeners if this object needs that.

      Important: This method may be called more than once. Methods overriding this method must ensure that listeners are not unregistered more than once.

      Specified by:
      unregisterListeners in interface Base
    • printTreeRow

      protected void printTreeRow​(Base.PrintTreeSettings settings, Locale locale, PrintWriter writer, String currentIndent, MutableInt lineNumber)
    • printTree

      public void printTree​(Base.PrintTreeSettings settings, PrintWriter writer, String indent, MutableInt lineNumber)
      Print the tree to a stream.
      Specified by:
      printTree in interface Base
      Parameters:
      settings - settings for what to print
      writer - the stream to print the tree to
      indent - the indentation of each level
      lineNumber - the line number
    • printTree

      public void printTree​(Base.PrintTreeSettings settings, Locale locale, PrintWriter writer, String indent, MutableInt lineNumber)
      Print the tree to a stream.
      Specified by:
      printTree in interface Base
      Parameters:
      settings - settings for what to print
      locale - The locale to be used
      writer - the stream to print the tree to
      indent - the indentation of each level
      lineNumber - the line number
    • printTree

      public void printTree​(Base.PrintTreeSettings settings, Locale locale, PrintWriter writer, String indent, String currentIndent, MutableInt lineNumber)
      Print the tree to a stream.
      Specified by:
      printTree in interface Base
      Parameters:
      settings - settings for what to print
      locale - The locale to be used
      writer - the stream to print the tree to
      indent - the indentation of each level
      currentIndent - the current indentation
      lineNumber - the line number
    • getDeepCopy

      public Base getDeepCopy​(Map<String,​String> systemNames, Map<String,​String> userNames)
      Description copied from interface: Base
      Create a deep copy of myself and my children The item needs to try to lookup itself in both systemNames and userNames to see if the user has given a new system name and/or a new user name.If no new system name is given, an auto system name is used. If no user name is given, a null user name is used.
      Specified by:
      getDeepCopy in interface Base
      Parameters:
      systemNames - a map of old and new system name
      userNames - a map of old system name and new user name
      Returns:
      a deep copy
    • deepCopyChildren

      public Base deepCopyChildren​(Base original, Map<String,​String> systemNames, Map<String,​String> userNames) throws JmriException
      Description copied from interface: Base
      Do a deep copy of children from the original to me.
      Specified by:
      deepCopyChildren in interface Base
      Parameters:
      original - the item to copy from
      systemNames - a map of old and new system name
      userNames - a map of old system name and new user name
      Returns:
      myself
      Throws:
      JmriException - in case of an error
    • getUsageReport

      Get a list of references for the specified bean.
      Specified by:
      getUsageReport in interface NamedBean
      Parameters:
      bean - The bean to be checked.
      Returns:
      a list of NamedBeanUsageReports or an empty ArrayList.
    • getUsageTree

      public void getUsageTree​(int level, NamedBean bean, List<NamedBeanUsageReport> report, NamedBean cdl)
      Navigate the LogixNG tree.
      Specified by:
      getUsageTree in interface Base
      Parameters:
      level - The current recursion level for debugging.
      bean - The named bean that is the object of the search.
      report - A list of NamedBeanUsageReport usage reports.
      cdl - The current ConditionalNG bean. Null for Module searches since there is no conditional
    • getUsageDetail

      public void getUsageDetail​(int level, NamedBean bean, List<NamedBeanUsageReport> report, NamedBean cdl)
      Add a new NamedBeanUsageReport to the report list if there are any matches in this action or expresssion.

      NamedBeanUsageReport Usage keys:

      • LogixNGAction
      • LogixNGExpression
      Specified by:
      getUsageDetail in interface Base
      Parameters:
      level - The current recursion level for debugging.
      bean - The named bean that is the object of the search.
      report - A list of NamedBeanUsageReport usage reports.
      cdl - The current ConditionalNG bean. Null for Module searches since there is no conditional