TemplateJTree

class TemplateJTree(val originalTemplateList: TemplateList, var currentTemplateList: TemplateList) : Tree(source)

A tree containing Templates and Schemes.

Changes made through this tree's interface (e.g. adding, removing, copying) are immediately reflected in the currentTemplateList. The originalTemplateList is used only as a reference point to determine what changes have occurred, for example when isModified is called or when the end user requests that changes are (partially) reverted.

If changes are made outside of this tree's interface (i.e. by directly operating on the currentTemplateList instance that was passed in the constructor), this tree's internal model becomes desynchronized, and must be resynchronized by invoking reload. Except for reload, the behaviour of this tree is undefined while desynchronized.

Internally, the currentTemplateList is loaded into a TemplateJTreeModel. The TemplateJTree class is the corresponding user interface class, which additionally provides (1) toolbars and buttons for manipulating the model, (2) node expansion and selection, and (3) handling for tracking and reversing modifications.

Parameters

originalTemplateList

the (read-only) original templates without modifications

currentTemplateList

the current templates, including modifications

Constructors

Link copied to clipboard
constructor(originalTemplateList: TemplateList, currentTemplateList: TemplateList)

Types

Link copied to clipboard
private inner class AddButton : AnActionButton

Displays a popup to add a scheme, or immediately adds a template if nothing is currently selected.

Link copied to clipboard
private inner class CellRenderer : ColoredTreeCellRenderer

Renders a cell in the tree.

Link copied to clipboard
object Companion

Holds constants.

Link copied to clipboard
private inner class CopyButton : AnActionButton

Copies the selected scheme in the tree.

Link copied to clipboard
private inner class DownButton : AnActionButton

Moves the selected scheme down by one position in the tree.

Link copied to clipboard
private inner class RemoveButton : AnActionButton

Removes the selected scheme from the tree.

Link copied to clipboard
private inner class ResetButton : AnActionButton

Resets the selected scheme to its original state, or removes it if it has no original state.

Link copied to clipboard
private inner class UpButton : AnActionButton

Moves the selected scheme up by one position in the tree.

Properties

Link copied to clipboard
private var collapsedTemplates: Collection<String>

The list of currently-collapsed Templates by UUID.

Link copied to clipboard
Link copied to clipboard

The tree's model.

Link copied to clipboard
Link copied to clipboard

The currently selected node, or null if no node is selected, or null if the root is selected.

Link copied to clipboard

The currently selected scheme (or template), or null if no scheme is currently selected.

Link copied to clipboard

The currently selected template, or the parent of the currently selected non-template scheme, or null if no scheme is currently selected.

Functions

Link copied to clipboard
fun addScheme(newScheme: Scheme)

Adds newScheme at an appropriate location in the tree based on the currently selected node.

Link copied to clipboard
fun asDecoratedPanel(): JPanel

Returns a panel containing this tree decorated with accessible action buttons.

Link copied to clipboard
fun canMoveSchemeByOnePosition(scheme: Scheme, moveDown: Boolean): Boolean

Returns true if and only if moveSchemeByOnePosition can be invoked with these parameters.

Link copied to clipboard
fun expandAll()

Expands all Templates.

Link copied to clipboard
private fun findUniqueNameFor(template: Template): String

Finds a good, unique name for template so that it can be inserted into this list without conflict.

Link copied to clipboard
private fun getMoveDescriptor(scheme: Scheme, moveDown: Boolean): Triple<Int, Int, RowsDnDSupport.RefinedDropSupport.Position>

Returns the arguments to pass to TemplateJTreeModel.moveRow or TemplateJTreeModel.canMoveRow to describe moving scheme up (if moveDown is false) or down (if moveDown is true).

Link copied to clipboard
private fun isModified(scheme: Scheme): Boolean

Returns true if and only if scheme has been modified with respect to originalTemplateList.

Link copied to clipboard
fun moveSchemeByOnePosition(scheme: Scheme, moveDown: Boolean)

Moves scheme by one position; down if moveDown is `true, and up otherwise.

Link copied to clipboard
fun reload(changedScheme: Scheme? = null)

Notifies the tree that external changes have been made to currentTemplateList, and resynchronizes the tree's model with the template list.

Link copied to clipboard
fun removeScheme(scheme: Scheme)

Removes scheme from the tree, and selects an appropriate other scheme.

Link copied to clipboard
fun replaceScheme(oldScheme: Scheme, newScheme: Scheme?)

Replaces oldScheme with newScheme in-place.

Link copied to clipboard
private fun runPreservingState(lambda: () -> Unit)

Runs lambda while ensuring that the selectedScheme and collapsed templates remain unchanged.