M
- the model typepublic class TreeGrid<M> extends Grid<M> implements BeforeCollapseItemEvent.HasBeforeCollapseItemHandlers<M>, CollapseItemEvent.HasCollapseItemHandlers<M>, BeforeExpandItemEvent.HasBeforeExpandItemHandlers<M>, ExpandItemEvent.HasExpandItemHandlers<M>
A TreeGrid
provides support for displaying and editing hierarchical data where each item may contain multiple
properties. The tree grid gets its data from a TreeStore
and its column definitions from a
ColumnModel
. Each model in the store is rendered as an item in the tree. The fields in the model provide the
data for each column associated with the item. Any updates to the store are automatically pushed to the tree grid.
This includes inserting, removing, sorting and filter.
In GXT version 3, ModelKeyProvider
s and ValueProvider
s provide the interface between your data model
and the list store and ColumnConfig
classes. This enables a tree grid to work with data of any object type.
You can provide your own implementation of these interfaces, or you can use a Sencha supplied generator to create
them for you automatically. A generator runs at compile time to create a Java class that is compiled to JavaScript.
The Sencha supplied generator can create classes for interfaces that extend the PropertyAccess
interface. The
generator transparently creates the class at compile time and the GWT#create(Class)
method returns an
instance of that class at run time. The generated class is managed by GWT and GXT and you generally do not need to
worry about what the class is called, where it is located, or other similar details.
Each tree grid has a GridView
. The grid view provides many options for customizing the grid's appearance
(e.g. striping, mouse-over tracking, empty text). To set these options, get the current grid view using
Grid.getView()
and then set the desired option on the grid view.
To customize the appearance of a column in a tree grid, provide a cell implementation using
ColumnConfig#setCell(Cell)
.
Tree grids support several ways to manage column widths:
GridView.setAutoExpandColumn(ColumnConfig)
.GridView.setAutoFill(boolean)
or GridView.setForceFit(boolean)
to enable this feature:
ColumnConfig.setFixed(boolean)
.The following code snippet illustrates the creation of a simple tree grid with local data for test purposes. For more practical examples that show how to load data from remote sources, see the Async TreeGrid example in the online Explorer demo.
// Generate the key provider and value provider for the Data class
DataProperties dp = GWT.create(DataProperties.class);
// Create the configurations for each column in the tree grid
List<ColumnConfig<Data, ?>> ccs = new LinkedList<ColumnConfig<Data, ?>>();
ccs.add(new ColumnConfig<Data, String>(dp.name(), 200, "Name"));
ccs.add(new ColumnConfig<Data, String>(dp.value(), 200, "Value"));
ColumnModel<Data> cm = new ColumnModel<Test.Data>(ccs);
// Create the store that the contains the data to display in the tree grid
TreeStore<Data> s = new TreeStore<Test.Data>(dp.key());
Data r1 = new Data("Parent 1", "value1");
s.add(r1);
s.add(r1, new Data("Child 1.1", "value2"));
s.add(r1, new Data("Child 1.2", "value3"));
Data r2 = new Data("Parent 2", "value4");
s.add(r2);
s.add(r2, new Data("Child 2.1", "value5"));
s.add(r2, new Data("Child 2.2", "value6"));
// Create the tree grid using the store, column model and column config for the tree column
TreeGrid<Data> tg = new TreeGrid<Data>(s, cm, ccs.get(0));
// Add the tree to a container
RootPanel.get().add(tg);
To use the Sencha supplied generator to create model key providers and value providers, extend the
PropertyAccess
interface, parameterized with the type of data you want to access (as shown below) and
invoke the GWT.create
method on its class
member (as shown in the code snippet above). This
creates an instance of the class that can be used to initialize the tree and tree store. In the following code
snippet we define a new interface called DataProperties
that extends the PropertyAccess
interface and is parameterized with Data
, a Plain Old Java Object (POJO).
public interface DataProperties extends PropertyAccess<Data> {
@Path("name")
ModelKeyProvider<Data> key();
ValueProvider<Data, String> name();
ValueProvider<Data, String> value();
}
public class Data {
private String name;
private String value;
public Data(String name, String value) {
super();
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(String value) {
this.value = value;
}
}
To enable drag and drop for a tree grid, add the following:
new TreeGridDragSource<Data>(tg);
TreeGridDropTarget<Data> dt = new TreeGridDropTarget<Data>(tg);
dt.setFeedback(Feedback.BOTH);
To add reordering support to the drag and drop, include:
dt.setAllowSelfAsSource(true);
Modifier and Type | Class and Description |
---|---|
static class |
TreeGrid.TreeGridNode<M> |
Grid.Callback, Grid.GridCell
Modifier and Type | Field and Description |
---|---|
protected boolean |
filtering |
protected TreeLoader<M> |
loader |
protected Map<String,Tree.TreeNode<M>> |
nodes |
protected Map<String,Tree.TreeNode<M>> |
nodesByDomId |
protected StoreHandlers<M> |
storeHandler |
protected HandlerRegistration |
storeHandlerRegistration |
protected TreeGridView<M> |
treeGridView |
protected TreeStore<M> |
treeStore |
cm, sm, store, view, viewReady
adjustSize, allowTextSelection, cacheSizes, disableContextMenu, disabled, disabledStyle, ensureVisibilityOnSizing, height, hidden, lastSize, layer, left, mask, maskMessage, monitorWindowResize, pageX, pageY, resizeHandler, shim, tabIndex, toolTip, toolTipConfig, top, width, windowResizeDelay, windowResizeTask
Constructor and Description |
---|
TreeGrid(TreeStore<M> store,
ColumnModel<M> cm,
ColumnConfig<M,?> treeColumn)
Creates a new tree grid.
|
TreeGrid(TreeStore<M> store,
ColumnModel<M> cm,
ColumnConfig<M,?> treeColumn,
GridView.GridAppearance appearance)
Creates a new tree grid.
|
TreeGrid(TreeStore<M> store,
ColumnModel<M> cm,
ColumnConfig<M,?> treeColumn,
GridView.GridAppearance appearance,
Tree.TreeAppearance treeAppearance)
Creates a new tree grid.
|
Modifier and Type | Method and Description |
---|---|
HandlerRegistration |
addBeforeCollapseHandler(BeforeCollapseItemEvent.BeforeCollapseItemHandler<M> handler)
Adds a
BeforeCollapseItemEvent.BeforeCollapseItemHandler handler for BeforeCollapseItemEvent
events. |
HandlerRegistration |
addBeforeExpandHandler(BeforeExpandItemEvent.BeforeExpandItemHandler<M> handler)
Adds a
BeforeExpandItemEvent.BeforeExpandItemHandler handler for BeforeExpandItemEvent
events. |
HandlerRegistration |
addCollapseHandler(CollapseItemEvent.CollapseItemHandler<M> handler)
Adds a
CollapseItemEvent.CollapseItemHandler handler for CollapseItemEvent
events. |
HandlerRegistration |
addExpandHandler(ExpandItemEvent.ExpandItemHandler<M> handler)
Adds a
ExpandItemEvent.ExpandItemHandler handler for ExpandItemEvent events. |
protected ImageResource |
calculateIconStyle(M model) |
protected Tree.Joint |
calculateJoint(M model) |
void |
collapseAll()
Collapses all nodes.
|
protected ListStore<M> |
createListStore() |
void |
expandAll()
Expands all nodes.
|
protected int |
findLastOpenChildIndex(M model)
Returns the index in the liststore of the last child in the subtree starting at the given model.
|
Tree.TreeNode<M> |
findNode(Element target)
Returns the tree node for the given target.
|
protected String |
generateModelId(M m) |
GridView.GridAppearance |
getAppearance()
Returns the grid appearance.
|
IconProvider<M> |
getIconProvider()
Returns the model icon provider.
|
TreeStyle |
getStyle()
Returns the tree style.
|
Tree.TreeAppearance |
getTreeAppearance()
Returns the tree appearance.
|
ColumnConfig<M,?> |
getTreeColumn()
Returns the column that represents the tree nodes.
|
TreeLoader<M> |
getTreeLoader()
Returns the tree loader.
|
TreeStore<M> |
getTreeStore()
Returns the tree's tree store.
|
TreeGridView<M> |
getTreeView()
Returns the tree's view.
|
protected boolean |
hasChildren(M model) |
boolean |
isAutoExpand()
Returns true if auto expand is enabled.
|
boolean |
isAutoLoad()
Returns true if auto load is enabled.
|
boolean |
isCaching()
Returns true when a loader is queried for it's children each time a node is expanded.
|
protected boolean |
isEventTargetJoint(Event event) |
boolean |
isExpanded(M model)
Returns true if the model is expanded.
|
boolean |
isExpandOnDoubleClick()
Returns the expand on double click state.
|
boolean |
isExpandOnFilter()
Returns the if expand all and collapse all is enabled on filter changes.
|
boolean |
isLeaf(M model)
Returns true if the model is a leaf node.
|
protected void |
onAdd(StoreAddEvent<M> se) |
protected void |
onAfterRenderView()
Invoked after the view has been rendered, may be overridden to perform any
activities that require a rendered view.
|
void |
onBrowserEvent(Event ce) |
protected void |
onClear(StoreClearEvent<M> event) |
protected void |
onClick(Event event)
Handles the browser click event.
|
protected void |
onDataChange(M parent) |
protected void |
onDoubleClick(Event e)
Handles the browser double click event.
|
protected void |
onFilter(StoreFilterEvent<M> se) |
protected void |
onRecordChange(StoreRecordChangeEvent<M> event) |
protected void |
onRemove(TreeStoreRemoveEvent<M> event) |
protected void |
onSort(StoreSortEvent<M> event) |
protected void |
onUpdate(StoreUpdateEvent<M> se) |
void |
reconfigure(ListStore<M> store,
ColumnModel<M> cm)
Reconfigures the grid to use a different Store and Column Model.
|
void |
reconfigure(TreeStore<M> store,
ColumnModel<M> cm,
ColumnConfig<M,?> treeColumn) |
void |
refresh(M model)
Refreshes the data for the given model.
|
protected String |
register(M m) |
protected void |
renderChildren(M parent,
boolean auto) |
void |
setAutoExpand(boolean autoExpand)
If set to true, all non leaf nodes will be expanded automatically (defaults to false).
|
void |
setAutoLoad(boolean autoLoad)
Sets whether all children should automatically be loaded recursively (defaults to false).
|
void |
setCaching(boolean caching)
Sets whether the children should be cached after first being retrieved from the store (defaults to true).
|
void |
setExpanded(M model,
boolean expand)
Sets the item's expand state.
|
void |
setExpanded(M model,
boolean expand,
boolean deep)
Sets the item's expand state.
|
void |
setExpandOnDoubleClick(boolean expandOnDoubleClick)
Determines if the nodes should be expanded and collapsed on double clicks (defaults to
true ). |
void |
setExpandOnFilter(boolean expandOnFilter)
Sets whether the tree should expand all and collapse all when filters are applied (defaults to true).
|
void |
setIconProvider(IconProvider<M> iconProvider)
Sets the tree's model icon provider which provides the icon style for each model.
|
void |
setLeaf(M model,
boolean leaf)
Sets the item's leaf state.
|
protected void |
setTreeColumn(ColumnConfig<M,?> treeColumn) |
void |
setTreeLoader(TreeLoader<M> treeLoader)
Sets the tree loader.
|
void |
setView(GridView<M> view)
Sets the grid's view.
|
void |
toggle(M model)
Toggles the model's expand state.
|
protected void |
unregister(M m) |
addBodyScrollHandler, addCellClickHandler, addCellDoubleClickHandler, addCellMouseDownHandler, addHeaderClickHandler, addHeaderContextMenuHandler, addHeaderDoubleClickHandler, addHeaderMouseDownHandler, addReconfigureHandler, addRefreshHandler, addRowClickHandler, addRowDoubleClickHandler, addRowMouseDownHandler, addSortChangeHandler, addViewReadyHandler, afterRenderView, cellConsumesEventType, doAttachChildren, doDetachChildren, fireEventToCell, focus, getColumnModel, getLazyRowRender, getLoader, getSelectionModel, getStore, getView, handleEventForCell, isColumnReordering, isColumnResize, isHideHeaders, isLoadMask, isViewReady, notifyHide, notifyShow, onAfterFirstAttach, onAttach, onDisable, onEnable, onFocus, onLoaderBeforeLoad, onLoaderLoadException, onLoadLoader, onMouseDown, onMouseUp, onResize, setAllowTextSelection, setColumnReordering, setColumnResize, setHideHeaders, setLazyRowRender, setLoader, setLoadMask, setSelectionModel, sinkCellEvents, walkCells
addBeforeHideHandler, addBeforeShowContextMenuHandler, addBeforeShowHandler, addBlurHandler, addDisableHandler, addEnableHandler, addFocusHandler, addGestureRecognizer, addHideHandler, addMoveHandler, addResizeHandler, addShowContextMenuHandler, addShowHandler, addStyleDependentName, addStyleOnOver, adjustPosition, adjustSize, applyState, assertAfterRender, assertPreRender, blur, clearSizeCache, disable, disableContextMenu, disableEvents, enable, enableEvents, fireCancellableEvent, fireEvent, getData, getElement, getFocusEl, getFocusSupport, getGestureRecognizer, getGestureRecognizerCount, getHideMode, getId, getItemId, getOffsetHeight, getOffsetWidth, getPositionEl, getShadow, getShadowPosition, getStateId, getTabIndex, getToolTip, hide, hideShadow, hideToolTip, isAllowTextSelection, isAutoHeight, isAutoWidth, isDeferHeight, isEnabled, isMonitorWindowResize, isRendered, isStateful, isVisible, isVisible, mask, mask, onBlur, onDetach, onHide, onHideContextMenu, onLoad, onPosition, onRightClick, onShow, onShowContextMenu, onTouch, onUnload, onWindowResize, removeStyleDependentName, removeStyleOnOver, removeToolTip, setBorders, setBounds, setBounds, setContextMenu, setData, setDeferHeight, setEnabled, setHeight, setHeight, setHideMode, setId, setItemId, setMonitorWindowResize, setPagePosition, setPixelSize, setPosition, setShadow, setShadowPosition, setSize, setStateful, setStateId, setStyleDependentName, setTabIndex, setToolTip, setToolTipConfig, setVisible, setWidth, setWidth, show, sync, syncSize, unmask
protected boolean filtering
protected TreeLoader<M> loader
protected Map<String,Tree.TreeNode<M>> nodes
protected Map<String,Tree.TreeNode<M>> nodesByDomId
protected StoreHandlers<M> storeHandler
protected HandlerRegistration storeHandlerRegistration
protected TreeGridView<M> treeGridView
public TreeGrid(TreeStore<M> store, ColumnModel<M> cm, ColumnConfig<M,?> treeColumn)
store
- the tree storecm
- the column modeltreeColumn
- the tree columnpublic TreeGrid(TreeStore<M> store, ColumnModel<M> cm, ColumnConfig<M,?> treeColumn, GridView.GridAppearance appearance)
store
- the tree storecm
- the column modeltreeColumn
- the tree columnappearance
- the grid appearancepublic TreeGrid(TreeStore<M> store, ColumnModel<M> cm, ColumnConfig<M,?> treeColumn, GridView.GridAppearance appearance, Tree.TreeAppearance treeAppearance)
store
- the tree storecm
- the column modeltreeColumn
- the tree columnappearance
- the grid appearancetreeAppearance
- the tree appearancepublic HandlerRegistration addBeforeCollapseHandler(BeforeCollapseItemEvent.BeforeCollapseItemHandler<M> handler)
BeforeCollapseItemEvent.HasBeforeCollapseItemHandlers
BeforeCollapseItemEvent.BeforeCollapseItemHandler
handler for BeforeCollapseItemEvent
events.addBeforeCollapseHandler
in interface BeforeCollapseItemEvent.HasBeforeCollapseItemHandlers<M>
handler
- the handlerpublic HandlerRegistration addBeforeExpandHandler(BeforeExpandItemEvent.BeforeExpandItemHandler<M> handler)
BeforeExpandItemEvent.HasBeforeExpandItemHandlers
BeforeExpandItemEvent.BeforeExpandItemHandler
handler for BeforeExpandItemEvent
events.addBeforeExpandHandler
in interface BeforeExpandItemEvent.HasBeforeExpandItemHandlers<M>
handler
- the handlerpublic HandlerRegistration addCollapseHandler(CollapseItemEvent.CollapseItemHandler<M> handler)
CollapseItemEvent.HasCollapseItemHandlers
CollapseItemEvent.CollapseItemHandler
handler for CollapseItemEvent
events.addCollapseHandler
in interface CollapseItemEvent.HasCollapseItemHandlers<M>
handler
- the handlerpublic HandlerRegistration addExpandHandler(ExpandItemEvent.ExpandItemHandler<M> handler)
ExpandItemEvent.HasExpandItemHandlers
ExpandItemEvent.ExpandItemHandler
handler for ExpandItemEvent
events.addExpandHandler
in interface ExpandItemEvent.HasExpandItemHandlers<M>
handler
- the handlerpublic void collapseAll()
public void expandAll()
public Tree.TreeNode<M> findNode(Element target)
target
- the target elementpublic GridView.GridAppearance getAppearance()
public IconProvider<M> getIconProvider()
public TreeStyle getStyle()
public Tree.TreeAppearance getTreeAppearance()
public ColumnConfig<M,?> getTreeColumn()
public TreeLoader<M> getTreeLoader()
public TreeStore<M> getTreeStore()
public TreeGridView<M> getTreeView()
public boolean isAutoExpand()
public boolean isAutoLoad()
public boolean isCaching()
public boolean isExpanded(M model)
model
- the modelpublic boolean isExpandOnDoubleClick()
public boolean isExpandOnFilter()
public boolean isLeaf(M model)
model
- the modelpublic void reconfigure(ListStore<M> store, ColumnModel<M> cm)
Grid
reconfigure
in class Grid<M>
store
- the new storecm
- the new column modelpublic void reconfigure(TreeStore<M> store, ColumnModel<M> cm, ColumnConfig<M,?> treeColumn)
public void refresh(M model)
model
- the model to be refreshedpublic void setAutoExpand(boolean autoExpand)
autoExpand
- the auto expand state to set.public void setAutoLoad(boolean autoLoad)
autoLoad
- true to auto loadpublic void setCaching(boolean caching)
false
, a load request will be made each time a node is expanded.caching
- the caching statepublic void setExpanded(M model, boolean expand)
model
- the modelexpand
- true to expandpublic void setExpanded(M model, boolean expand, boolean deep)
model
- the modelexpand
- true to expanddeep
- true to expand all children recursivelypublic void setExpandOnDoubleClick(boolean expandOnDoubleClick)
true
). Set to false
when using two clicks to edit inline editing.expandOnDoubleClick
- true to expand and collapse on double clickspublic void setExpandOnFilter(boolean expandOnFilter)
expandOnFilter
- true to expand and collapse on filter changespublic void setIconProvider(IconProvider<M> iconProvider)
iconProvider
- the icon providerpublic void setLeaf(M model, boolean leaf)
model
- the modelleaf
- the leaf statepublic void setTreeLoader(TreeLoader<M> treeLoader)
treeLoader
- the tree loaderpublic void setView(GridView<M> view)
Grid
public void toggle(M model)
model
- the modelprotected ImageResource calculateIconStyle(M model)
protected Tree.Joint calculateJoint(M model)
protected int findLastOpenChildIndex(M model)
model
- the model used to find the last open child index.protected boolean hasChildren(M model)
protected boolean isEventTargetJoint(Event event)
protected void onAdd(StoreAddEvent<M> se)
protected void onAfterRenderView()
Grid
onAfterRenderView
in class Grid<M>
protected void onClear(StoreClearEvent<M> event)
public void onBrowserEvent(Event ce)
onBrowserEvent
in class Grid<M>
protected void onClick(Event event)
Grid
protected void onDataChange(M parent)
protected void onDoubleClick(Event e)
Grid
onDoubleClick
in class Grid<M>
e
- the double click eventprotected void onFilter(StoreFilterEvent<M> se)
protected void onRecordChange(StoreRecordChangeEvent<M> event)
protected void onRemove(TreeStoreRemoveEvent<M> event)
protected void onSort(StoreSortEvent<M> event)
protected void onUpdate(StoreUpdateEvent<M> se)
protected void renderChildren(M parent, boolean auto)
protected void setTreeColumn(ColumnConfig<M,?> treeColumn)
protected void unregister(M m)
Copyright © 2018. All rights reserved.