Class TableToolBar<V>
java.lang.Object
com.amalgamasimulation.desktop.ui.editor.tables.TableToolBar<V>
- Type Parameters:
V- the type of table rows
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTableToolBar(TableToolBarProperties<V> properties, Supplier<List<V>> rows) 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 voidCreates and adds an element when the create button has no action of its own.protected abstract voiddefaultCopyElementAction(CopyElementToolItemProperties<V> item, V selectedElement) Adds a copy of the selected element when the copy button has no action of its own.protected abstract voiddefaultMoveDownElementAction(MoveDownElementToolItemProperties<V> item, int index, V selectedElement) Moves the selected element one row down when the button has no action of its own.protected abstract voiddefaultMoveUpElementAction(MoveUpElementToolItemProperties<V> item, int index, V selectedElement) Moves the selected element one row up when the button has no action of its own.protected abstract voidRefreshes the table when the refresh button has no action of its own.protected abstract voiddefaultRemoveElementsAction(RemoveElementToolItemProperties<V> item, org.eclipse.jface.viewers.IStructuredSelection selection) Removes the selected rows when the remove button has no action of its own.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 voidselectElement(V element) Selects the element and scrolls to it.protected abstract voidLets the user pick the table elements for the SelectElementsFromTableToolItemProperties button.protected voidselectRow(int index) Selects a row after rows are removed.voidSets the table the buttons work on.voidEnables the buttons whose settings allow it and updates the state of check buttons.protected abstract voidRefreshes the table after the SelectObjectsFromTableToolItemProperties button has saved the user's choice.
-
Field Details
-
table
Table set in setTable.
-
-
Constructor Details
-
TableToolBar
Creates a toolbar; call create to show it.- Parameters:
properties- the toolbar buttonsrows- 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 buttonselection- the selected rows, not empty
-
defaultAddElementAction
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 buttonselectedElement- 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 buttonindex- the index of the element in the rows, greater than 0selectedElement- 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 buttonindex- the index of the element in the rows, less than the last indexselectedElement- the element to move
-
defaultRefreshTableAction
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
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
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
Runs the action of a button of a type the toolbar does not know. Does nothing by default.- Parameters:
toolItem- the pressed button
-