Class AbstractTreeElementType

java.lang.Object
com.amalgamasimulation.desktop.appelements.tree.AbstractTreeElementType

public abstract class AbstractTreeElementType extends Object
Type of a tree element: an icon, a name and whether the property panel has a page for it. Each type created with a name is added to values(), a list shared by all subclasses. forObject(Object) searches this list for the type of an object by the predicate given in the constructor.
  • Field Details

    • iconPath

      protected String iconPath
      Path to the icon inside the bundle.
    • name

      protected String name
      Name shown in the tree.
    • existProperty

      protected boolean existProperty
      Whether the property panel has a page for this type.
    • suitableObject

      protected Predicate<Object> suitableObject
      Predicate that matches(Object) uses to check an object.
    • values

      protected static List<AbstractTreeElementType> values
      All types created with a name, in order of creation.
  • Constructor Details

    • AbstractTreeElementType

      protected AbstractTreeElementType()
      Creates a type without a name or icon and does not add it to values(). Subclasses that e4 creates only to run @PostConstruct use it.
    • AbstractTreeElementType

      protected AbstractTreeElementType(String iconPath, String name, boolean existProperty)
      Creates a type and adds it to values(). No object matches this type, so forObject(Object) never returns it.
      Parameters:
      iconPath - path to the icon inside the bundle
      name - name shown in the tree
      existProperty - whether the property panel has a page for this type
    • AbstractTreeElementType

      protected AbstractTreeElementType(String iconPath, String name, boolean existProperty, Predicate<Object> suitableObject)
      Creates a type and adds it to values().
      Parameters:
      iconPath - path to the icon inside the bundle
      name - name shown in the tree
      existProperty - whether the property panel has a page for this type
      suitableObject - predicate for objects of this type, not null
  • Method Details

    • getIconPath

      public String getIconPath()
      Returns the path to the icon inside the bundle.
      Returns:
      the path to the icon inside the bundle
    • getIconURI

      public String getIconURI()
      Returns the icon URI for e4 model elements such as parts and menu items, or an empty string if the icon is not found.
      Returns:
      the icon URI, or an empty string
    • getName

      public String getName()
      Returns the name shown in the tree.
      Returns:
      the name shown in the tree
    • setName

      public void setName(String name)
      Sets the name shown in the tree.
      Parameters:
      name - the name shown in the tree
    • hasPropertyPage

      public boolean hasPropertyPage()
      Returns whether the property panel has a page for this type. If not, selecting the element sends the type itself to the property panel.
      Returns:
      true if the property panel has a page for this type
    • matches

      public boolean matches(Object object)
      Returns whether the object matches this type by the predicate given in the constructor.
      Parameters:
      object - the object to check
      Returns:
      true if the object matches this type
    • values

      public static List<AbstractTreeElementType> values()
      Returns all types of all subclasses created with a name, in order of creation.
      Returns:
      the shared list itself
    • forObject

      public static <T extends AbstractTreeElementType> T forObject(Object object)
      Returns the first type in values() that the object matches, or null if the object is null or no type matches.
      Type Parameters:
      T - expected type of the result
      Parameters:
      object - the object whose type is needed, may be null
      Returns:
      the type of the object, or null
    • toString

      public String toString()
      Returns getName().
      Overrides:
      toString in class Object
      Returns:
      the name of the type