Class TreeToolBar<V>

java.lang.Object
com.amalgamasimulation.desktop.ui.editor.trees.TreeToolBar<V>
Type Parameters:
V - the type of tree elements

public abstract class TreeToolBar<V> extends Object
Toolbar above a tree, with the buttons set in TreeToolBarProperties. A button runs its own action if one is set, otherwise the default one.
Author:
Ionov Ivan
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Tree<V>
    Tree set in setTree.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a toolbar; call create to show it.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    create(org.eclipse.swt.widgets.Composite parent)
    Creates the toolbar in the parent.
    protected abstract V
    defaultAddElementAction(Supplier<V> createNewElement)
    Adds the new element when the create button has no action of its own.
    protected abstract void
    defaultMoveElementAction(V element, V target)
    Puts the element in the place of its neighbor when the move button has no action of its own.
    protected abstract void
    Removes the selected elements when the remove button has no action of its own.
    protected abstract List<V>
    getSiblings(V element)
    Returns the elements on the same level as the element, including it, in tree order.
    protected boolean
    Returns whether the buttons can run their actions now.
    protected void
    Runs the action of a button of a type the toolbar does not know.
    protected void
    Selects the neighbor of the removed elements: the next element on the same level, otherwise the previous one.
    protected void
    selectElement(V element)
    Selects the element and scrolls to it.
    void
    setTree(Tree<V> tree)
    Sets the tree the buttons work on.
    void
    Enables the buttons whose settings allow it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • tree

      protected Tree<V> tree
      Tree set in setTree.
  • Constructor Details

    • TreeToolBar

      public TreeToolBar(TreeToolBarProperties<V> properties)
      Creates a toolbar; call create to show it.
      Parameters:
      properties - the toolbar buttons
  • Method Details

    • defaultAddElementAction

      protected abstract V defaultAddElementAction(Supplier<V> createNewElement)
      Adds the new element when the create button has no action of its own.
      Parameters:
      createNewElement - creates the element
      Returns:
      the added element, which the toolbar then selects, or null
    • defaultRemoveElementsAction

      protected abstract void defaultRemoveElementsAction(List<V> elements)
      Removes the selected elements when the remove button has no action of its own.
      Parameters:
      elements - the selected elements, not empty
    • getSiblings

      protected abstract List<V> getSiblings(V element)
      Returns the elements on the same level as the element, including it, in tree order. The toolbar uses them to move an element and to choose what to select after a removal.
      Parameters:
      element - the element
      Returns:
      the elements on the same level
    • defaultMoveElementAction

      protected abstract void defaultMoveElementAction(V element, V target)
      Puts the element in the place of its neighbor when the move button has no action of its own.
      Parameters:
      element - the element to move
      target - the previous element when moving up, the next one when moving down
    • create

      public void create(org.eclipse.swt.widgets.Composite parent)
      Creates the toolbar in the parent. Call it before creating the tree, so the toolbar is placed above it.
      Parameters:
      parent - the composite for the toolbar
    • updateEnabled

      public void updateEnabled()
      Enables the buttons whose settings allow it. Call it when the selection or the data changes.
    • setTree

      public void setTree(Tree<V> tree)
      Sets the tree the buttons work on. If the toolbar has a remove button, the Delete key removes the selected elements.
      Parameters:
      tree - the tree under the toolbar
    • isActionAvailable

      protected boolean isActionAvailable()
      Returns whether the buttons can run their actions now. Subclasses add their own conditions.
      Returns:
      true if the tree is set and not disposed
    • selectElement

      protected void selectElement(V element)
      Selects the element and scrolls to it.
      Parameters:
      element - the element to select
    • selectAfterRemove

      protected void selectAfterRemove(V element)
      Selects the neighbor of the removed elements: the next element on the same level, otherwise the previous one.
      Parameters:
      element - the neighbor to select
    • runOtherAction

      protected void runOtherAction(ToolItemProperties<?> toolItem)
      Runs the action of a button of a type the toolbar does not know. Does nothing by default.
      Parameters:
      toolItem - the pressed button