Search in sources :

Example 1 with MenuModelKeyBinding

use of org.jowidgets.tools.model.item.MenuModelKeyBinding in project jo-client-platform by jo-source.

the class BeanRelationTreeImpl method addBeanToTreeContainer.

private void addBeanToTreeContainer(final IBeanProxy<Object> bean, final int index, final ITreeContainer treeContainer, final IBeanRelationNodeModel<Object, Object> relationNodeModel, final IMenuModel nodeMenu) {
    // the renderer for the child nodes
    final IBeanProxyLabelRenderer<Object> renderer = relationNodeModel.getChildRenderer();
    // create a child node for the bean
    final ITreeNode childNode = treeContainer.addNode(index);
    renderNode(childNode, bean, renderer, relationNodeModel);
    if (nodeMenu.getChildren().size() > 0 && !bean.isDummy() && !bean.isTransient()) {
        childNode.setPopupMenu(nodeMenu);
        if (autoKeyBinding) {
            final MenuModelKeyBinding keyBinding = new MenuModelKeyBinding(nodeMenu, childNode, childNode);
            childNode.addDisposeListener(new IDisposeListener() {

                @Override
                public void onDispose() {
                    keyBinding.dispose();
                }
            });
        }
    }
    // map the child node to the relation model
    final Tuple<IBeanRelationNodeModel<Object, Object>, IBeanProxy<Object>> tuple;
    tuple = new Tuple<IBeanRelationNodeModel<Object, Object>, IBeanProxy<Object>>(relationNodeModel, bean);
    nodesMap.put(childNode, tuple);
    // register listener that re-renders node on property changes
    bean.addPropertyChangeListener(new PropertyChangedRenderingListener(childNode, bean, renderer));
    // registers a listener that re-renders dummy nodes on message state change
    if (bean.isDummy()) {
        bean.addMessageStateListener(new DummyBeanMessageStateRenderingListener(childNode, renderer));
    } else if (relationNodeModel.getChildRelations().size() > 0) {
        // add dummy relation node
        childNode.addNode();
        childNode.addTreeNodeListener(new TreeNodeExpansionListener(childNode, relationNodeModel, bean));
        if (expansionCacheEnabled) {
            childNode.addTreeNodeListener(new TreeNodeExpansionTrackingListener(childNode));
        }
    }
    // register listener that removes node from nodes map on dispose
    childNode.addDisposeListener(new TreeNodeDisposeListener(childNode));
    // auto expand the child node if necessary
    if (!bean.isDummy() && childNode.getLevel() < autoExpandLevel && !childNode.isLeaf()) {
        childNode.setExpanded(true);
    }
    if (expandedNodesCache.contains(new ExpandedNodeKey(childNode))) {
        childNode.setExpanded(true);
    }
}
Also used : IDisposeListener(org.jowidgets.api.controller.IDisposeListener) MenuModelKeyBinding(org.jowidgets.tools.model.item.MenuModelKeyBinding) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy) IBeanRelationNodeModel(org.jowidgets.cap.ui.api.tree.IBeanRelationNodeModel) ITreeNode(org.jowidgets.api.widgets.ITreeNode)

Aggregations

IDisposeListener (org.jowidgets.api.controller.IDisposeListener)1 ITreeNode (org.jowidgets.api.widgets.ITreeNode)1 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)1 IBeanRelationNodeModel (org.jowidgets.cap.ui.api.tree.IBeanRelationNodeModel)1 MenuModelKeyBinding (org.jowidgets.tools.model.item.MenuModelKeyBinding)1