The following section provides a short
description of the most important functions of the model viewer. The basic
model viewer functions are defined using the class com.tssap.util.ui.viewer.tree.GenericDataModelFilteredTreeViewer.
The model viewer offers several create methods for creating viewer instances. You can use parameters to
specify which filter is used and which objects are to be predefined as root
nodes.
In the simplest case, you merely pass the parent Control as a parameter of the create method and use a standard filter and a predefined assignment for the
root nodes.
![]()
|
public void createPartControl(Composite parent) { GenericDataModelFilteredTreeViewer modelViewer =
GenericDataModelFilteredTreeViewer.createFilteredTreeViewer(parent); // ... } |
|
Like every tree viewer, the
model viewer consists of one or more root nodes. The root nodes set the
uppermost tree hierarchy and enable you to access all subnodes in the tree. All objects that can be root nodes in the
model viewer must be of the type PropertyMap. The model viewer provides
the methods setRoots() and addRoot(),
which can be used to set the desired objects as root nodes dynamically. |
|
To assign one or more nodes as a root of the
model viewer dynamically, you simply call the setRoots() method.
![]()
|
modelViewer.setRoots(PropertyMap[] roots); |
Example 1
In the following example, all models are assigned to the viewer as root
nodes. All available models are ascertained using the method com.tssap.selena.model.extension.ModelUtilPlugin.computeModels().
|
PropertyMap[] roots
= ModelUtilPlugin.computeModels(); modelViewer.setRoots(roots); |
Example 2
This example demonstrates how one or more selected nodes are assigned to
the model viewer as root nodes. For this purpose, we first ascertain all
selected nodes selectedItems. For every selected node the getData() method returns the corresponding data object treeItemData. If an object maps the type PropertyMap, it is added to newRootVector. All elements of this vector are
assigned to the viewer as root nodes using setRoots().
|
TreeItem[] selectedItems = modelViewer.getTree().getSelection(); Vector newRootVector
= new
Vector(); for (int i = 0; i < selectedItems.length; i++)
{ TreeItem treeItem
= selectedItems[i]; Object treeItemData
= treeItem.getData(); if (treeItemData
instanceof PropertyMap)
{ newRootVector.add(treeItemData); } } if (newRootVector.size()
> 0) { modelViewer.setRoots((PropertyMap[]) newRootVector.toArray( new PropertyMap[newRootVector.size()])); |
The context menus are especially useful for
making the action function available to the model viewer.
The model viewer provides an appropriate set method that can be used when linking context menus.
To link a context menu with the model viewer,
call the relevant set method setContextMenu(IContextMenu
contextMenu).
![]()
|
modelViewer.setContextMenu(myContextMenu); |
For more details about creating and
linking context menus, refer to Using the SAP Action Framework.
Filters are required, for example, for
extracting a set of elements that are made available to the model viewer with
Selena content providers. The model viewer provides an appropriate set method for assigning a filter.
To use a filter with the model viewer, you need
the setFilter(IFilter filter) method.
![]()
|
modelViewer.setFilter(myFilter); |
For further information on the use of filters
or how you can write your own filters, see Defining Filters.
|
In addition to applying
filters, the model viewer can also dissolve all references in the tree. After
dissolving the references, all reference collections, references, and
referenced objects (elements, entities, and so on) are displayed in the tree
structure. Otherwise,
they are not shown in the tree display at all. |
|
To dissolve all references in a model viewer,
call the setDissolveReferences() method.
![]()
|
boolean currentValue = modelViewer.isDissolveReferences(); modelViewer.setDissolveReferences(!currentValue); |
|
The model viewer is able to
hide specific object types in the viewer display. You can either skip all reference
collections or all references in the tree. Simply hiding a
reference collection node results in the subordinate reference node being
displayed in its place. The referenced elements are displayed in the tree,
instead of the skipped references. |
|
![]()
To hide or display all reference collection
nodes in a model viewer, call the setSkipReferenceCollections() method.
|
boolean currentValue
= modelViewer.isSkipReferences(); modelViewer.setSkipReferences(!currentValue); |
![]()
To hide or display all reference nodes
in a model viewer, call the setSkipReferences() method.
|
boolean currentValue
= modelViewer.isSkipReferenceCollections(); modelViewer.setSkipReferenceCollections(!currentValue); |