|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.sencha.gxt.widget.core.client.Component
com.sencha.gxt.widget.core.client.grid.Grid<M>
com.sencha.gxt.widget.core.client.treegrid.TreeGrid<M>
M - the model typepublic class TreeGrid<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.
ModelKeyProviders and ValueProviders
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).// 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 {
@Path("name")
ModelKeyProvider 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(tg);
TreeGridDropTarget dt = new TreeGridDropTarget(tg);
dt.setFeedback(Feedback.BOTH);
To add reordering support to the drag and drop, include:
dt.setAllowSelfAsSource(true);
| Nested Class Summary | |
|---|---|
static class |
TreeGrid.TreeGridNode<M>
|
| Nested classes/interfaces inherited from class com.sencha.gxt.widget.core.client.grid.Grid |
|---|
Grid.Callback, Grid.GridCell |
| Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject |
|---|
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled |
| Field Summary |
|---|
| Fields inherited from class com.google.gwt.user.client.ui.UIObject |
|---|
DEBUG_ID_PREFIX |
| Constructor Summary | |
|---|---|
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. |
|
| Method Summary | |
|---|---|
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. |
void |
collapseAll()
Collapses all nodes. |
void |
expandAll()
Expands all nodes. |
Tree.TreeNode<M> |
findNode(Element target)
Returns the tree node for the given target. |
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. |
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. |
boolean |
isExpanded(M model)
Returns true if the model is expanded. |
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. |
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. |
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 |
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. |
void |
setTreeLoader(TreeLoader<M> treeLoader)
Sets the tree loader. |
void |
setView(GridView<M> view)
Sets the view's grid (pre-render). |
void |
toggle(M model)
Toggles the model's expand state. |
| Methods inherited from class com.google.gwt.user.client.ui.Widget |
|---|
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, getLayoutData, getParent, isAttached, removeFromParent, setLayoutData, sinkEvents |
| Methods inherited from class com.google.gwt.user.client.ui.UIObject |
|---|
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getOffsetHeight, getOffsetWidth, getStyleName, getStylePrimaryName, getTitle, isVisible, removeStyleDependentName, removeStyleName, setStyleDependentName, setStyleName, setStyleName, setStylePrimaryName, setTitle, setVisible, sinkBitlessEvent, toString, unsinkEvents |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.google.gwt.event.shared.HasHandlers |
|---|
fireEvent |
| Constructor Detail |
|---|
public TreeGrid(TreeStore<M> store,
ColumnModel<M> cm,
ColumnConfig<M,?> treeColumn)
store - the tree storecm - the column modeltreeColumn - the tree column
public 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 appearance
public 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 appearance| Method Detail |
|---|
public HandlerRegistration addBeforeCollapseHandler(BeforeCollapseItemEvent.BeforeCollapseItemHandler<M> handler)
BeforeCollapseItemEvent.HasBeforeCollapseItemHandlersBeforeCollapseItemEvent.BeforeCollapseItemHandler handler for BeforeCollapseItemEvent
events.
addBeforeCollapseHandler in interface BeforeCollapseItemEvent.HasBeforeCollapseItemHandlers<M>handler - the handler
public HandlerRegistration addBeforeExpandHandler(BeforeExpandItemEvent.BeforeExpandItemHandler<M> handler)
BeforeExpandItemEvent.HasBeforeExpandItemHandlersBeforeExpandItemEvent.BeforeExpandItemHandler handler for BeforeExpandItemEvent
events.
addBeforeExpandHandler in interface BeforeExpandItemEvent.HasBeforeExpandItemHandlers<M>handler - the handler
public HandlerRegistration addCollapseHandler(CollapseItemEvent.CollapseItemHandler<M> handler)
CollapseItemEvent.HasCollapseItemHandlersCollapseItemEvent.CollapseItemHandler handler for CollapseItemEvent
events.
addCollapseHandler in interface CollapseItemEvent.HasCollapseItemHandlers<M>handler - the handler
public HandlerRegistration addExpandHandler(ExpandItemEvent.ExpandItemHandler<M> handler)
ExpandItemEvent.HasExpandItemHandlersExpandItemEvent.ExpandItemHandler handler for ExpandItemEvent events.
addExpandHandler in interface ExpandItemEvent.HasExpandItemHandlers<M>handler - the handler
public void collapseAll()
public void expandAll()
public Tree.TreeNode<M> findNode(Element target)
target - the target element
public 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 model
public boolean isExpandOnFilter()
public boolean isLeaf(M model)
model - the model
public void reconfigure(ListStore<M> store,
ColumnModel<M> cm)
Grid
reconfigure in class Grid<M>store - the new storecm - the new column model
public 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 state
public void setExpanded(M model,
boolean expand)
model - the modelexpand - true to expand
public void setExpanded(M model,
boolean expand,
boolean deep)
model - the modelexpand - true to expanddeep - true to expand all children recursivelypublic void setExpandOnFilter(boolean expandOnFilter)
expandOnFilter - true to expand and collapse on filter changespublic void setIconProvider(IconProvider<M> iconProvider)
iconProvider - the icon provider
public 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
setView in class Grid<M>view - the viewpublic void toggle(M model)
model - the model
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||