use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.
the class BeanListRefreshDelegate method refresh.
void refresh(final Collection<IBeanProxy<BEAN_TYPE>> beans) {
if (refreshService != null) {
final BeanListExecutionHelper<BEAN_TYPE> executionHelper = new BeanListExecutionHelper<BEAN_TYPE>(REFRESH_FAILED.get(), listModel, beans, beanExecutionPolicy, exceptionConverter, false, true);
for (final List<IBeanProxy<BEAN_TYPE>> preparedBeans : executionHelper.prepareExecutions(false)) {
if (preparedBeans.size() > 0) {
final IExecutionTask executionTask = preparedBeans.get(0).getExecutionTask();
if (executionTask != null) {
executionTask.setDescription(REFRESH.get());
final IBeanKeyFactory beanKeyFactory = CapUiToolkit.beanKeyFactory();
final List<IBeanKey> beanKeys = beanKeyFactory.createKeys(preparedBeans);
final IResultCallback<List<IBeanDto>> helperCallback = executionHelper.createResultCallback(preparedBeans);
refreshService.refresh(helperCallback, beanKeys, executionTask);
}
}
}
}
}
use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.
the class BeanListSaveDelegate method create.
private void create(final Runnable finishedCallback) {
final Set<IBeanProxy<BEAN_TYPE>> beansToCreate = beansStateTracker.getBeansToCreate();
if (!EmptyCheck.isEmpty(beansToCreate)) {
if (creatorService == null) {
throw new IllegalStateException("No creator service set. Could not create transient beans");
}
final BeanListExecutionHelper<BEAN_TYPE> executionHelper = new BeanListExecutionHelper<BEAN_TYPE>(CREATION_FAILED.get(), listModel, beansToCreate, beanExecutionPolicy, exceptionConverter, true, fireBeansChanged);
final List<List<IBeanProxy<BEAN_TYPE>>> preparedExecutions = executionHelper.prepareExecutions(true, executionContext);
final CountDownRunnable countDownRunnable = new CountDownRunnable(finishedCallback, preparedExecutions.size());
for (final List<IBeanProxy<BEAN_TYPE>> preparedBeans : preparedExecutions) {
if (preparedBeans.size() > 0) {
final IExecutionTask executionTask = preparedBeans.get(0).getExecutionTask();
if (executionTask != null) {
executionTask.setDescription(CREATE.get());
final List<IBeanData> beansData = new LinkedList<IBeanData>();
for (final IBeanProxy<BEAN_TYPE> bean : preparedBeans) {
beansData.add(createBeanData(bean));
}
final IResultCallback<List<IBeanDto>> helperCallback = executionHelper.createResultCallback(preparedBeans, countDownRunnable);
creatorService.create(helperCallback, parentBeansProvider.get(), beansData, executionTask);
}
}
}
} else {
finishedCallback.run();
}
}
use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.
the class SingleBeanModelImpl method getParentBeanKeys.
private List<IBeanKey> getParentBeanKeys() {
if (parent == null) {
return null;
}
final IBeanSelection<Object> beanSelection = parent.getBeanSelection();
List<IBeanProxy<Object>> selection = beanSelection.getSelection();
if (EmptyCheck.isEmpty(selection)) {
return null;
} else if (linkType == LinkType.SELECTION_FIRST) {
selection = selection.subList(0, 1);
}
final List<IBeanKey> beanKeys = new LinkedList<IBeanKey>();
for (final IBeanProxy<Object> proxy : selection) {
if (proxy != null && !proxy.isDummy() && !proxy.isTransient()) {
beanKeys.add(new BeanKey(proxy.getId(), proxy.getVersion()));
}
}
return beanKeys;
}
use of org.jowidgets.cap.ui.api.bean.IBeanProxy 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.cap.ui.api.bean.IBeanProxy 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