Class TableToolBar<V>

java.lang.Object
com.amalgamasimulation.desktop.ui.editor.tables.TableToolBar<V>
Type Parameters:
V - the type of table rows

public abstract class TableToolBar<V> extends Object
Toolbar above a table, with the buttons set in TableToolBarProperties. A button runs its own action if one is set, otherwise the matching default method of the subclass.
Author:
Ionov Ivan
  • Field Details

    • table

      protected Table<V> table
      Table set in setTable.
  • Constructor Details

    • TableToolBar

      public TableToolBar(TableToolBarProperties<V> properties, Supplier<List<V>> rows)
      Creates a toolbar; call create to show it.
      Parameters:
      properties - the toolbar buttons
      rows - returns the current table rows
  • Method Details

    • defaultRemoveElementsAction

      protected abstract void defaultRemoveElementsAction(RemoveElementToolItemProperties<V> item, org.eclipse.jface.viewers.IStructuredSelection selection)
      Removes the selected rows when the remove button has no action of its own.
      Parameters:
      item - the remove button
      selection - the selected rows, not empty
    • defaultAddElementAction

      protected abstract void defaultAddElementAction(CreateElementToolItemProperties<V> item)
      Creates and adds an element when the create button has no action of its own. The method selects the new element itself.
      Parameters:
      item - the create button
    • defaultCopyElementAction

      protected abstract void defaultCopyElementAction(CopyElementToolItemProperties<V> item, V selectedElement)
      Adds a copy of the selected element when the copy button has no action of its own. The method selects the copy itself.
      Parameters:
      item - the copy button
      selectedElement - the element to copy
    • defaultMoveUpElementAction

      protected abstract void defaultMoveUpElementAction(MoveUpElementToolItemProperties<V> item, int index, V selectedElement)
      Moves the selected element one row up when the button has no action of its own.
      Parameters:
      item - the move up button
      index - the index of the element in the rows, greater than 0
      selectedElement - the element to move
    • defaultMoveDownElementAction

      protected abstract void defaultMoveDownElementAction(MoveDownElementToolItemProperties<V> item, int index, V selectedElement)
      Moves the selected element one row down when the button has no action of its own.
      Parameters:
      item - the move down button
      index - the index of the element in the rows, less than the last index
      selectedElement - the element to move
    • defaultRefreshTableAction

      protected abstract void defaultRefreshTableAction(RefreshToolItemProperties<V> item)
      Refreshes the table when the refresh button has no action of its own.
      Parameters:
      item - the refresh button
    • selectElementsFromTableAction

      protected abstract void selectElementsFromTableAction(SelectElementsFromTableToolItemProperties<V> item)
      Lets the user pick the table elements for the SelectElementsFromTableToolItemProperties button.
      Parameters:
      item - the button
    • updateTable

      protected abstract void updateTable()
      Refreshes the table after the SelectObjectsFromTableToolItemProperties button has saved the user's choice.
    • create

      public void create(org.eclipse.swt.widgets.Composite parent)
      Creates the toolbar in the parent. Call it before creating the table, 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 and updates the state of check buttons. Call it when the selection or the data changes.
    • setTable

      public void setTable(Table<V> table)
      Sets the table the buttons work on. If the toolbar has a remove button, the Delete key removes the selected rows.
      Parameters:
      table - the table 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 table is set and not disposed
    • selectElement

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

      protected void selectRow(int index)
      Selects a row after rows are removed.
      Parameters:
      index - the row index, or -1
    • 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