use of com.haulmont.cuba.desktop.gui.data.TreeModelAdapter in project cuba by cuba-platform.
the class DesktopTree method setDatasource.
@Override
public void setDatasource(HierarchicalDatasource datasource) {
this.datasource = datasource;
hierarchyProperty = datasource.getHierarchyPropertyName();
model = new TreeModelAdapter(datasource, captionMode, captionProperty, true);
impl.setModel(model);
impl.addTreeSelectionListener(new SelectionListener());
UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);
if (uss.getUserSession().isSpecificPermitted(ShowInfoAction.ACTION_PERMISSION)) {
ShowInfoAction action = (ShowInfoAction) getAction(ShowInfoAction.ACTION_ID);
if (action == null) {
action = new ShowInfoAction();
addAction(action);
}
action.setDatasource(datasource);
}
collectionChangeListener = e -> {
// #PL-2035, reload selection from ds
Set<E> selectedItems = getSelected();
if (selectedItems == null) {
selectedItems = Collections.emptySet();
}
Set<E> newSelection = new HashSet<>();
for (E entity : selectedItems) {
if (e.getDs().containsItem(entity.getId())) {
newSelection.add(entity);
}
}
if (e.getDs().getState() == Datasource.State.VALID && e.getDs().getItem() != null) {
// noinspection unchecked
newSelection.add((E) e.getDs().getItem());
}
if (newSelection.isEmpty()) {
setSelected((Entity) null);
} else {
setSelected(newSelection);
}
};
// noinspection unchecked
datasource.addCollectionChangeListener(new WeakCollectionChangeListener(datasource, collectionChangeListener));
collectionDsActionsNotifier = new CollectionDsActionsNotifier(this);
collectionDsActionsNotifier.bind(datasource);
for (Action action : getActions()) {
action.refreshState();
}
assignAutoDebugId();
}
Aggregations