Search in sources :

Example 21 with IBeanProxy

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);
                }
            }
        }
    }
}
Also used : IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask) List(java.util.List) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy) IBeanKeyFactory(org.jowidgets.cap.ui.api.bean.IBeanKeyFactory)

Example 22 with IBeanProxy

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();
    }
}
Also used : IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask) LinkedList(java.util.LinkedList) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy) IBeanData(org.jowidgets.cap.common.api.bean.IBeanData) LinkedList(java.util.LinkedList) List(java.util.List)

Example 23 with IBeanProxy

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;
}
Also used : BeanKey(org.jowidgets.cap.common.tools.bean.BeanKey) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) LinkedList(java.util.LinkedList) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 24 with IBeanProxy

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);
    }
}
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)

Example 25 with IBeanProxy

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);
    }
}
Also used : IBeanRelationNodeModel(org.jowidgets.cap.ui.api.tree.IBeanRelationNodeModel) ITreeNode(org.jowidgets.api.widgets.ITreeNode) ITreeContainer(org.jowidgets.api.widgets.ITreeContainer) IBeanRelationTreeBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanRelationTreeBluePrint) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Aggregations

IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)25 LinkedList (java.util.LinkedList)13 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)7 TableCellBluePrint (org.jowidgets.tools.model.table.TableCellBluePrint)6 List (java.util.List)5 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)5 IExecutionTask (org.jowidgets.cap.ui.api.execution.IExecutionTask)5 ArrayList (java.util.ArrayList)3 BeanKey (org.jowidgets.cap.common.tools.bean.BeanKey)3 IBeanRelationNodeModel (org.jowidgets.cap.ui.api.tree.IBeanRelationNodeModel)3 ITreeNode (org.jowidgets.api.widgets.ITreeNode)2 IBeanKeyFactory (org.jowidgets.cap.ui.api.bean.IBeanKeyFactory)2 ITableCellPopupEvent (org.jowidgets.common.widgets.controller.ITableCellPopupEvent)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 IEnabledChecker (org.jowidgets.api.command.IEnabledChecker)1 IEnabledState (org.jowidgets.api.command.IEnabledState)1 IDisposeListener (org.jowidgets.api.controller.IDisposeListener)1