Class TreeToolBar<V>
java.lang.Object
com.amalgamasimulation.desktop.ui.editor.trees.TreeToolBar<V>
- Type Parameters:
V- the type of tree elements
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 -
Constructor Summary
ConstructorsConstructorDescriptionTreeToolBar(TreeToolBarProperties<V> properties) Creates a toolbar; call create to show it. -
Method Summary
Modifier and TypeMethodDescriptionvoidcreate(org.eclipse.swt.widgets.Composite parent) Creates the toolbar in the parent.protected abstract VdefaultAddElementAction(Supplier<V> createNewElement) Adds the new element when the create button has no action of its own.protected abstract voiddefaultMoveElementAction(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 voiddefaultRemoveElementsAction(List<V> elements) Removes the selected elements when the remove button has no action of its own.getSiblings(V element) Returns the elements on the same level as the element, including it, in tree order.protected booleanReturns whether the buttons can run their actions now.protected voidrunOtherAction(ToolItemProperties<?> toolItem) Runs the action of a button of a type the toolbar does not know.protected voidselectAfterRemove(V element) Selects the neighbor of the removed elements: the next element on the same level, otherwise the previous one.protected voidselectElement(V element) Selects the element and scrolls to it.voidSets the tree the buttons work on.voidEnables the buttons whose settings allow it.
-
Field Details
-
tree
Tree set in setTree.
-
-
Constructor Details
-
TreeToolBar
Creates a toolbar; call create to show it.- Parameters:
properties- the toolbar buttons
-
-
Method Details
-
defaultAddElementAction
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
Removes the selected elements when the remove button has no action of its own.- Parameters:
elements- the selected elements, not empty
-
getSiblings
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
Puts the element in the place of its neighbor when the move button has no action of its own.- Parameters:
element- the element to movetarget- 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
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
Selects the element and scrolls to it.- Parameters:
element- the element to select
-
selectAfterRemove
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
Runs the action of a button of a type the toolbar does not know. Does nothing by default.- Parameters:
toolItem- the pressed button
-