eu.webtoolkit.jwt
Class WTreeView

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WWidget
          extended by eu.webtoolkit.jwt.WCompositeWidget
              extended by eu.webtoolkit.jwt.WAbstractItemView
                  extended by eu.webtoolkit.jwt.WTreeView

public class WTreeView
extends WAbstractItemView

A view class that displays a model as a tree or tree table.

The view displays data from a WAbstractItemModel in a tree or tree table. It provides incremental rendering, allowing the display of data models of any size efficiently, without excessive use of client- or serverside resources.

The rendering (and editing) of items is handled by a WAbstractItemDelegate, by default it uses WItemDelegate which renders data of all predefined roles (see also ItemDataRole), including text, icons, checkboxes, and tooltips.

The view may support editing of items, if the model indicates support (see the ItemFlag.ItemIsEditable flag). You can define triggers that initiate editing of an item using WAbstractItemView#setEditTriggers(). The actual editing is provided by the item delegate (you can set an appropriate delegate for one column using WAbstractItemView#setItemDelegateForColumn()). Using WAbstractItemView#setEditOptions() you can customize if and how the view deals with multiple editors.

By default, all but the first columns are given a width of 150px, and the first column takes the remaining size. Note that this may have as consequence that the first column's size is reduced to 0. Column widths of all columns, including the first column, can be set through the API method setColumnWidth(), and also by the user using handles provided in the header.

Optionally, the treeview may be configured so that the first column is always visible while scrolling through the other columns, which may be convenient if you wish to display a model with many columns. Use WAbstractItemView#setColumn1Fixed() to enable this behaviour.

If the model supports sorting ( WAbstractItemModel#sort()), such as the WStandardItemModel, then you can enable sorting buttons in the header, using WAbstractItemView#setSortingEnabled().

You can allow selection on row or item level (using WAbstractItemView#setSelectionBehavior()), and selection of single or multiple items (using WAbstractItemView#setSelectionMode()), and listen for changes in the selection using the WAbstractItemView#selectionChanged() signal.

You may enable drag & drop support for this view, whith awareness of the items in the model. When enabling dragging (see WAbstractItemView#setDragEnabled()), the current selection may be dragged, but only when all items in the selection indicate support for dragging (controlled by the ItemIsDragEnabled flag), and if the model indicates a mime-type (controlled by WAbstractItemModel#getMimeType()). Likewise, by enabling support for dropping (see WAbstractItemView#setDropsEnabled()), the treeview may receive a drop event on a particular item, at least if the item indicates support for drops (controlled by the ItemIsDropEnabled flag).

You may also react to mouse click events on any item, by connecting to one of the WAbstractItemView#clicked() or WAbstractItemView#doubleClicked() signals.

Graceful degradation

The view provides a virtual scrolling behavior which relies on Ajax availability. When Ajax is not available, a page navigation bar is used instead, see WAbstractItemView#getCreatePageNavigationBar(). In that case, the widget needs to be given an explicit height using resize() which determines the number of rows that are displayed at a time.

CSS

The treeview is styled by the current CSS theme. The look can be overridden using the Wt-treeview CSS class and the following selectors.

Selectors that apply to the body

 .Wt-treeview .Wt-pagingbar        : paging bar
 
Selectors that apply to the header:
 .Wt-treeview .Wt-headerdiv         : header (background)
 .Wt-treeview .Wt-header .Wt-label  : header label
 .Wt-treeview .Wt-tv-rh             : column resize handle
 .Wt-treeview .Wt-tv-sh-none        : column sort handle, no sorting
 .Wt-treeview .Wt-tv-sh-up          : column sort handle, sort up
 .Wt-treeview .Wt-tv-sh-down        : column sort handle, sort down
 .Wt-treeview .Wt-tv-br             : header border
 
Selectors that apply to the tree decoration:
 .Wt-treeview .Wt-trunk          : vertical line, trunk
 .Wt-treeview .Wt-end            : vertical line, last item
 .Wt-treeview .Wt-collapse       : collapse icon
 .Wt-treeview .Wt-expand         : expand icon
 .Wt-treeview .Wt-noexpand       : leaf icon
 
Selectors that apply to the table contents:
 .Wt-treeview .Wt-spacer         : spacer for non-loaded content
 .Wt-treeview .Wt-selected       : selected item
 .Wt-treeview .Wt-drop-site      : possible drop site
 
Selectors that apply to the table borders (which must be 1 pixel wide)
 .Wt-treeview .Wt-tv-row .Wt-tv-c      : border-right property of cells
 .Wt-treeview .Wt-header .Wt-tv-row,
   .Wt-treeview .Wt-tv-node .Wt-tv-row : border-left property of cells
 

A snapshot of the WTreeView:

WTreeView example (default)

WTreeView example (default)

WTreeView example (polished)

WTreeView example (polished)


Nested Class Summary
 
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WAbstractItemView
WAbstractItemView.EditOption, WAbstractItemView.EditTrigger, WAbstractItemView.ScrollHint
 
Constructor Summary
WTreeView()
          Creates a new tree view.
WTreeView(WContainerWidget parent)
          Creates a new tree view.
 
Method Summary
 void collapse(WModelIndex index)
          Collapses a node.
 Signal1<WModelIndex> collapsed()
          Signal emitted when a node is collapsed.
protected  void enableAjax()
          Progresses to an Ajax-enabled widget.
 void expand(WModelIndex index)
          Expands a node.
 Signal1<WModelIndex> expanded()
          Signal emitted when a node is expanded.
 void expandToDepth(int depth)
          Expands all nodes to a depth.
 int getCurrentPage()
          Returns the current page.
 int getPageCount()
          Returns the number of pages.
 int getPageSize()
          Returns the page size.
 boolean isExpanded(WModelIndex index)
          Returns whether a node is expanded.
 boolean isRootDecorated()
          Returns whether toplevel items are decorated.
 void remove()
          Destructor.
 void resize(WLength width, WLength height)
          Resizes the widget.
 void scrollTo(WModelIndex index, WAbstractItemView.ScrollHint hint)
          Scrolls the view to an item.
 void setAlternatingRowColors(boolean enable)
          Sets if alternating row colors are to be used.
 void setColumnBorder(WColor color)
          Sets the column border color.
 void setColumnHidden(int column, boolean hidden)
          Changes the visibility of a column.
 void setColumnWidth(int column, WLength width)
          Sets the column width.
 void setCurrentPage(int page)
          Sets the current page.
 void setExpanded(WModelIndex index, boolean expanded)
          Expands or collapses a node.
 void setHeaderHeight(WLength height)
          Sets the header height.
 void setModel(WAbstractItemModel model)
          Sets the model.
 void setRootIsDecorated(boolean show)
          Sets whether toplevel items are decorated.
 void setRowHeaderCount(int count)
          Configures the number of columns that are used as row headers.
 void setRowHeight(WLength rowHeight)
          Sets the row height.
 
Methods inherited from class eu.webtoolkit.jwt.WAbstractItemView
clicked, closeEditor, closeEditor, closeEditors, closeEditors, columnResized, createExtraHeaderWidget, doubleClicked, dropEvent, edit, extraHeaderWidget, getColumnAlignment, getColumnWidth, getCreatePageNavigationBar, getEditOptions, getEditTriggers, getHeaderAlignment, getHeaderHeight, getItemDelegate, getItemDelegate, getItemDelegate, getItemDelegateForColumn, getModel, getRootIndex, getRowHeaderCount, getRowHeight, getSelectedIndexes, getSelectionBehavior, getSelectionMode, getSelectionModel, getSortColumn, getSortOrder, hasAlternatingRowColors, hideColumn, horizontalHeaderAlignment, isColumn1Fixed, isColumnHidden, isColumnResizeEnabled, isEditing, isSelected, isSortingEnabled, isSortingEnabled, isValid, modelHeaderDataChanged, mouseWentDown, mouseWentUp, pageChanged, saveExtraHeaderWidgets, scrollTo, select, select, selectionChanged, setColumn1Fixed, setColumnAlignment, setColumnResizeEnabled, setDragEnabled, setDropsEnabled, setEditOptions, setEditOptions, setEditTriggers, setEditTriggers, setHeaderAlignment, setHeaderAlignment, setHeaderHeight, setHeaderItemDelegate, setHeaderWordWrap, setItemDelegate, setItemDelegateForColumn, setRootIndex, setSelectedIndexes, setSelectionBehavior, setSelectionMode, setSortingEnabled, setSortingEnabled, shiftEditors, showColumn, sortByColumn, validateEditor, validateEditors, verticalHeaderAlignment
 
Methods inherited from class eu.webtoolkit.jwt.WCompositeWidget
addStyleClass, boxBorder, boxPadding, callJavaScriptMember, doJavaScript, find, getAttributeValue, getClearSides, getDecorationStyle, getFloatSide, getHeight, getId, getImplementation, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, isDisabled, isEnabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isVisible, load, propagateSetEnabled, refresh, removeStyleClass, setAttributeValue, setClearSides, setDecorationStyle, setDisabled, setFloatSide, setHidden, setHiddenKeepsGeometry, setId, setImplementation, setInline, setJavaScriptMember, setLineHeight, setMargin, setMaximumSize, setMinimumSize, setOffsets, setPopup, setPositionScheme, setSelectable, setStyleClass, setTabIndex, setToolTip, setVerticalAlignment
 
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addStyleClass, animateHide, animateShow, containsExposed, disable, dropEvent, enable, getDrop, getJsRef, getParent, hide, htmlText, isLayoutSizeAware, isRendered, layoutSizeChanged, positionAt, positionAt, removeStyleClass, resize, setClearSides, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
 
Methods inherited from class eu.webtoolkit.jwt.WObject
getObjectName, setObjectName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WTreeView

public WTreeView(WContainerWidget parent)
Creates a new tree view.


WTreeView

public WTreeView()
Creates a new tree view.

Calls this((WContainerWidget)null)

Method Detail

remove

public void remove()
Description copied from class: WWidget
Destructor.

Deletes a widget and all children (recursively). If the widget is contained in another widget, it is removed first.

Overrides:
remove in class WAbstractItemView
See Also:
WContainerWidget.removeWidget(WWidget widget)

setExpanded

public void setExpanded(WModelIndex index,
                        boolean expanded)
Expands or collapses a node.

See Also:
expand(WModelIndex index), collapse(WModelIndex index)

isExpanded

public boolean isExpanded(WModelIndex index)
Returns whether a node is expanded.

See Also:
setExpanded(WModelIndex index, boolean expanded)

collapse

public void collapse(WModelIndex index)
Collapses a node.

See Also:
setExpanded(WModelIndex index, boolean expanded), expand(WModelIndex index)

expand

public void expand(WModelIndex index)
Expands a node.

See Also:
setExpanded(WModelIndex index, boolean expanded), collapse(WModelIndex index)

expandToDepth

public void expandToDepth(int depth)
Expands all nodes to a depth.

Expands all nodes to the given depth. A depth of 1 corresponds to the top level nodes.

See Also:
expand(WModelIndex index)

setRootIsDecorated

public void setRootIsDecorated(boolean show)
Sets whether toplevel items are decorated.

By default, top level nodes have expand/collapse and other lines to display their linkage and offspring, like any node.

By setting show to false, you can hide these decorations for root nodes, and in this way mimic a plain list. You could also consider using a WTableView instead.


isRootDecorated

public boolean isRootDecorated()
Returns whether toplevel items are decorated.

See Also:
setRootIsDecorated(boolean show)

resize

public void resize(WLength width,
                   WLength height)
Description copied from class: WWidget
Resizes the widget.

Specify a new size for this widget, by specifying width and height. By default a widget has automatic width and height, see WLength#isAuto().

This applies to CSS-based layout, and only block widgets can be given a size reliably.

When inserted in a layout manager, the widget may be informed about its current size using setLayoutSizeAware(). If you have defined a "wtResize()" JavaScript method for the widget, then this method will also be called. operation.

Overrides:
resize in class WCompositeWidget
See Also:
WWidget.getWidth(), WWidget.getHeight()

collapsed

public Signal1<WModelIndex> collapsed()
Signal emitted when a node is collapsed.

See Also:
setExpanded(WModelIndex index, boolean expanded), expanded()

expanded

public Signal1<WModelIndex> expanded()
Signal emitted when a node is expanded.

See Also:
setExpanded(WModelIndex index, boolean expanded), collapsed()

setModel

public void setModel(WAbstractItemModel model)
Description copied from class: WAbstractItemView
Sets the model.

The View will display data of the given model and changes in the model are reflected by the View.

The initial model is null.

Overrides:
setModel in class WAbstractItemView
See Also:
WAbstractItemView.setRootIndex(WModelIndex rootIndex)

setColumnWidth

public void setColumnWidth(int column,
                           WLength width)
Sets the column width.

For a model with columnCount() == N, the initial width of columns 1.. N is set to 150 pixels, and column 0 will take all remaining space.

Note: The actual space occupied by each column is the column width augmented by 7 pixels for internal padding and a border.

Specified by:
setColumnWidth in class WAbstractItemView
See Also:
setRowHeight(WLength rowHeight)

setAlternatingRowColors

public void setAlternatingRowColors(boolean enable)
Description copied from class: WAbstractItemView
Sets if alternating row colors are to be used.

Configure whether rows get alternating background colors, defined by the current CSS theme.

The default value is false.

Overrides:
setAlternatingRowColors in class WAbstractItemView

setRowHeight

public void setRowHeight(WLength rowHeight)
Description copied from class: WAbstractItemView
Sets the row height.

The view renders all rows with a same height. This method configures this row height.

The default value is 20 pixels.

Note: The height must be specified in WLength.Unit.Pixel units.

Overrides:
setRowHeight in class WAbstractItemView
See Also:
WAbstractItemView.setColumnWidth(int column, WLength width)

setHeaderHeight

public void setHeaderHeight(WLength height)
Description copied from class: WAbstractItemView
Sets the header height.

The default value is 20 pixels.

Overrides:
setHeaderHeight in class WAbstractItemView

setColumnBorder

public void setColumnBorder(WColor color)
Description copied from class: WAbstractItemView
Sets the column border color.

The default border color is defined by the CSS theme.

Specified by:
setColumnBorder in class WAbstractItemView

setColumnHidden

public void setColumnHidden(int column,
                            boolean hidden)
Description copied from class: WAbstractItemView
Changes the visibility of a column.

Overrides:
setColumnHidden in class WAbstractItemView
See Also:
WAbstractItemView.isColumnHidden(int column)

setRowHeaderCount

public void setRowHeaderCount(int count)
Description copied from class: WAbstractItemView
Configures the number of columns that are used as row headers.

An item view does not use the vertical header data from the model in any way, but instead you can configure data in the first column(s) to be used as a row headers.

These columns will not scroll horizontally together with the rest of the model.

The default value is 0.

Note: Currently, this property must be set before any other settings of the view and only a value of 0 or 1 is supported.

Overrides:
setRowHeaderCount in class WAbstractItemView

getPageCount

public int getPageCount()
Description copied from class: WAbstractItemView
Returns the number of pages.

When Ajax/JavaScript is not available, the view will use a paging navigation bar to allow scrolling through the data. This returns the number of pages currently shown.

Specified by:
getPageCount in class WAbstractItemView
See Also:
WAbstractItemView.getCreatePageNavigationBar(), WAbstractItemView.pageChanged()

getPageSize

public int getPageSize()
Description copied from class: WAbstractItemView
Returns the page size.

When Ajax/JavaScript is not available, the view will use a paging navigation bar to allow scrolling through the data. This returns the number of items per page.

Specified by:
getPageSize in class WAbstractItemView
See Also:
WAbstractItemView.getCreatePageNavigationBar(), WAbstractItemView.pageChanged()

getCurrentPage

public int getCurrentPage()
Description copied from class: WAbstractItemView
Returns the current page.

When Ajax/JavaScript is not available, the view will use a paging navigation bar to allow scrolling through the data. This returns the current page (between 0 and getPageCount() - 1).

Specified by:
getCurrentPage in class WAbstractItemView
See Also:
WAbstractItemView.getCreatePageNavigationBar(), WAbstractItemView.pageChanged()

setCurrentPage

public void setCurrentPage(int page)
Description copied from class: WAbstractItemView
Sets the current page.

When Ajax/JavaScript is not available, the view will use a paging navigation bar to allow scrolling through the data. This method can be used to change the current page.

Specified by:
setCurrentPage in class WAbstractItemView
See Also:
WAbstractItemView.getCreatePageNavigationBar(), WAbstractItemView.pageChanged()

scrollTo

public void scrollTo(WModelIndex index,
                     WAbstractItemView.ScrollHint hint)
Description copied from class: WAbstractItemView
Scrolls the view to an item.

Scrolls the view to ensure that the item which represents the provided index is visible. A hint may indicate how the item should appear in the viewport (if possible).

Note: Currently only implemented to scroll to the correct row, not taking into account the column.

Specified by:
scrollTo in class WAbstractItemView

enableAjax

protected void enableAjax()
Description copied from class: WWidget
Progresses to an Ajax-enabled widget.

This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.

You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.

Overrides:
enableAjax in class WCompositeWidget
See Also:
WApplication.enableAjax()