use of org.jowidgets.api.widgets.ITreeNode in project jo-client-platform by jo-source.
the class BeanRelationTreeImpl method getHeadMatchingLength.
private int getHeadMatchingLength(final ITreeContainer treeContainer, final IBeanRelationNodeModel<Object, Object> relationNodeModel) {
final int maxMatching = getMaxMatchingLength(treeContainer, relationNodeModel);
if (maxMatching == 0) {
return 0;
}
final Iterator<ITreeNode> treeNodeIterator = treeContainer.getChildren().iterator();
for (int index = 0; index < relationNodeModel.getSize(); index++) {
if (treeNodeIterator.hasNext()) {
if (!isNodeAssociatedWithBean(treeNodeIterator.next(), relationNodeModel.getBean(index))) {
return index;
}
} else {
return index;
}
}
return maxMatching;
}
use of org.jowidgets.api.widgets.ITreeNode in project jo-client-platform by jo-source.
the class BeanRelationTreeImpl method getTailMatchingLength.
private int getTailMatchingLength(final ITreeContainer treeContainer, final IBeanRelationNodeModel<Object, Object> relationNodeModel) {
final int maxMatching = getMaxMatchingLength(treeContainer, relationNodeModel);
if (maxMatching == 0) {
return 0;
}
final List<ITreeNode> children = treeContainer.getChildren();
final ListIterator<ITreeNode> treeNodeIterator = children.listIterator(children.size());
final int relationNodeModelSize = relationNodeModel.getSize();
for (int index = 0; index < relationNodeModelSize; index++) {
if (treeNodeIterator.hasPrevious()) {
final int beanIndex = relationNodeModelSize - index - 1;
if (!isNodeAssociatedWithBean(treeNodeIterator.previous(), relationNodeModel.getBean(beanIndex))) {
return index;
}
} else {
return index;
}
}
return maxMatching;
}
use of org.jowidgets.api.widgets.ITreeNode 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);
}
}
use of org.jowidgets.api.widgets.ITreeNode in project jo-client-platform by jo-source.
the class BeanRelationTreeImpl method onBeansChanged.
private void onBeansChanged(final ITreeContainer treeContainer, final IBeanRelationNodeModel<Object, Object> relationNodeModel, final IMenuModel nodeMenu) {
if (RelationRenderingPolicy.GREY_EMPTY_RELATIONS == relationRenderingPolicy || RelationRenderingPolicy.HIDE_EMPTY_READONLY_RELATIONS == relationRenderingPolicy) {
final ITreeContainer parentContainer = treeContainer.getParentContainer();
if (parentContainer != null && treeContainer instanceof ITreeNode) {
final Tuple<IBeanRelationNodeModel<Object, Object>, IBeanProxy<Object>> tuple = nodesMap.get(treeContainer);
if (tuple != null && tuple.getSecond() == null) {
if (relationNodeModel.getSize() == 0) {
if (!hasVisibleItems(nodeMenu) && relationNodeModel.getFilter(IBeanTableModel.UI_FILTER_ID) == null && relationNodeModel.getFilter(IBeanTableModel.UI_SEARCH_FILTER_ID) == null && RelationRenderingPolicy.HIDE_EMPTY_READONLY_RELATIONS == relationRenderingPolicy) {
parentContainer.removeNode((ITreeNode) treeContainer);
return;
} else {
((ITreeNode) treeContainer).setForegroundColor(Colors.DISABLED);
}
} else {
((ITreeNode) treeContainer).setForegroundColor(null);
}
}
}
}
final int oldSize = treeContainer.getChildren().size();
final int headMatching = getHeadMatchingLength(treeContainer, relationNodeModel);
final int tailMatching = getTailMatchingLength(treeContainer, relationNodeModel);
final int beansToDelete = oldSize - headMatching - tailMatching;
// add the new beans
for (int i = headMatching; i < (relationNodeModel.getSize() - tailMatching); i++) {
// get the bean at index i
final IBeanProxy<Object> bean = relationNodeModel.getBean(i);
// add the bean to tree container
addBeanToTreeContainer(bean, beansToDelete + i, treeContainer, relationNodeModel, nodeMenu);
}
// remove the old beans
for (int i = 0; i < beansToDelete; i++) {
treeContainer.removeNode(headMatching);
}
// auto expand the node if necessary
if (treeContainer.getLevel() < autoExpandLevel && treeContainer instanceof ITreeNode && treeContainer.getChildren().size() > 0) {
final ITreeNode treeNode = (ITreeNode) treeContainer;
treeNode.setExpanded(true);
}
if (treeContainer instanceof ITreeNode && expandedNodesCache.contains(new ExpandedNodeKey((ITreeNode) treeContainer))) {
final ITreeNode treeNode = (ITreeNode) treeContainer;
treeNode.setExpanded(true);
}
}
Aggregations