Search in sources :

Example 1 with IBeanProxy

use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.

the class BeanTableModelImpl method getNewData.

private Map<Integer, ArrayList<IBeanProxy<BEAN_TYPE>>> getNewData(final Set<IBeanProxy<BEAN_TYPE>> oldSelection, final List<Integer> newSelection, final Iterable<? extends IBeanDto> beans, final List<IBeanProxy<BEAN_TYPE>> removedBeanProxies) {
    // hold the beans that should be deleted but that are currently not deleted
    final Set<IBeanDto> beansToDelete = CollectionUtils.createHashSet(beans);
    final Map<Integer, ArrayList<IBeanProxy<BEAN_TYPE>>> newData = new HashMap<Integer, ArrayList<IBeanProxy<BEAN_TYPE>>>();
    int newPageIndex = 0;
    ArrayList<IBeanProxy<BEAN_TYPE>> newPage = new ArrayList<IBeanProxy<BEAN_TYPE>>(pageSize);
    final int pageCount = getPage(dataModel.getDataRowCount()) + 1;
    int addedNullCount = 0;
    final List<IBeanProxy<BEAN_TYPE>> beansToUnregister = new LinkedList<IBeanProxy<BEAN_TYPE>>();
    for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
        final ArrayList<IBeanProxy<BEAN_TYPE>> page = data.get(pageIndex);
        // add a regular page
        if (page != null) {
            for (final IBeanProxy<BEAN_TYPE> bean : page) {
                final boolean deletedBeanRemoved = beansToDelete.remove(bean);
                if (deletedBeanRemoved) {
                    beansToUnregister.add(bean);
                    removedBeanProxies.add(bean);
                    rowCountOfPages--;
                    if (countedRowCount != null) {
                        countedRowCount = Integer.valueOf(countedRowCount.intValue() - 1);
                    }
                } else if (newPage.size() < pageSize && addedNullCount < pageSize) {
                    newPage.add(bean);
                } else {
                    if (addedNullCount < pageSize) {
                        newData.put(newPageIndex, newPage);
                    }
                    newPageIndex++;
                    newPage = new ArrayList<IBeanProxy<BEAN_TYPE>>(pageSize);
                    newPage.add(bean);
                }
                if (oldSelection.remove(bean)) {
                    if (!deletedBeanRemoved) {
                        newSelection.add(newPageIndex * pageSize + newPage.size() - 1);
                    }
                }
                if (bean == null) {
                    addedNullCount++;
                } else {
                    addedNullCount = 0;
                }
            }
        } else // add a null page (add 'pageSize' times a 'null')
        if (addedNullCount < pageSize) {
            for (int i = 0; i < pageSize; i++) {
                if (newPage.size() < pageSize) {
                    newPage.add(null);
                    addedNullCount++;
                } else {
                    if (addedNullCount < pageSize) {
                        newData.put(newPageIndex, newPage);
                    }
                    newPageIndex++;
                    newPage = new ArrayList<IBeanProxy<BEAN_TYPE>>(pageSize);
                    newPage.add(null);
                    addedNullCount++;
                }
            }
        } else // skip the page
        // (there a more than one page of null's added, so the page can be skipped)
        {
            newPage = new ArrayList<IBeanProxy<BEAN_TYPE>>(pageSize);
            newPageIndex++;
            addedNullCount = addedNullCount + pageSize;
        }
    }
    beansStateTracker.unregister(beansToUnregister);
    // add the last new page if it has data
    if (newPage.size() > 0) {
        newData.put(newPageIndex, newPage);
    }
    return newData;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TableCellBluePrint(org.jowidgets.tools.model.table.TableCellBluePrint) LinkedList(java.util.LinkedList) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto)

Example 2 with IBeanProxy

use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.

the class BeanTableModelImpl method addBeanDtos.

@Override
public List<IBeanProxy<BEAN_TYPE>> addBeanDtos(final Collection<? extends IBeanDto> beanDtos, final boolean sorted) {
    Assert.paramNotNull(beanDtos, "beanDtos");
    final List<IBeanProxy<BEAN_TYPE>> proxies = new ArrayList<IBeanProxy<BEAN_TYPE>>(beanDtos.size());
    for (final IBeanDto beanDto : beanDtos) {
        final IBeanProxy<BEAN_TYPE> beanProxy = createBeanProxy(beanDto);
        proxies.add(beanProxy);
    }
    addBeans(proxies, sorted);
    return proxies;
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ArrayList(java.util.ArrayList) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 3 with IBeanProxy

use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.

the class BeanTableModelImpl method addBeansSorted.

private void addBeansSorted(final Collection<IBeanProxy<BEAN_TYPE>> beansToAdd) {
    final List<IBeanProxy<BEAN_TYPE>> selectedBeans = getSelectedBeans();
    final Comparator<IBeanDto> comparator = BeanDtoComparator.create(sortModel.getSorting());
    final ListIterator<IBeanProxy<BEAN_TYPE>> addedDataIterator = addedData.listIterator();
    boolean beanListenerIndicesStale = false;
    for (final IBeanProxy<BEAN_TYPE> bean : beansToAdd) {
        while (addedDataIterator.hasNext()) {
            final IBeanProxy<BEAN_TYPE> nextBean = addedDataIterator.next();
            final int compare = comparator.compare(bean, nextBean);
            if (compare < 0) {
                addedDataIterator.previous();
                break;
            } else if (beanListenerIndicesStale) {
                updateRowIndexOfBean(bean, rowCountOfPages + addedDataIterator.previousIndex());
            }
        }
        addedDataIterator.add(bean);
        beanListenerIndicesStale = true;
        final int rowIndex = rowCountOfPages + addedDataIterator.previousIndex();
        bean.addPropertyChangeListener(new BeanPropertyChangeListener(rowIndex));
    }
    beansStateTracker.register(beansToAdd);
    cachedReaderService.addBeans(getParentBeanKeys(), new HashSet<IBeanProxy<BEAN_TYPE>>(beansToAdd));
    setSelectedBeans(selectedBeans);
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) TableCellBluePrint(org.jowidgets.tools.model.table.TableCellBluePrint) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 4 with IBeanProxy

use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.

the class BeanTableModelImpl method removeSelection.

private List<IBeanProxy<BEAN_TYPE>> removeSelection() {
    final List<IBeanProxy<BEAN_TYPE>> result = new LinkedList<IBeanProxy<BEAN_TYPE>>();
    final List<Integer> currentSelection = getSelection();
    if (!currentSelection.isEmpty()) {
        for (final Integer index : currentSelection) {
            final int selectedIndex = index.intValue();
            final IBeanProxy<BEAN_TYPE> selectedBean = getBean(selectedIndex);
            if (selectedBean != null && !selectedBean.isDummy()) {
                result.add(selectedBean);
            }
        }
        dataModel.removeDataModelListener(tableDataModelListener);
        final List<Integer> emptySelection = Collections.emptyList();
        setSelection(emptySelection);
        dataModel.addDataModelListener(tableDataModelListener);
        fireSelectionChanged();
    }
    return result;
}
Also used : LinkedList(java.util.LinkedList) TableCellBluePrint(org.jowidgets.tools.model.table.TableCellBluePrint) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 5 with IBeanProxy

use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.

the class BeanLinkCreatorCommand method getBeanLink.

private IBeanLink<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> getBeanLink(final IExecutionContext executionContext) {
    final ICapApiBluePrintFactory cbpf = CapUiToolkit.bluePrintFactory();
    final IBeanLinkPanelBluePrint<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> linkPanelBp = cbpf.beanLinkPanel();
    linkPanelBp.setLinkBeanForm(linkBeanForm);
    linkPanelBp.setLinkableBeanForm(linkableBeanForm);
    linkPanelBp.setLinkableTable(linkableTable);
    final IBeanLinkDialogBluePrint<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> dialogBp = cbpf.beanLinkDialog(linkPanelBp);
    dialogBp.setMinPackSize(new Dimension(800, 600));
    dialogBp.setMaxPackSize(new Dimension(1600, 1000));
    dialogBp.setExecutionContext(executionContext);
    dialogBp.setMissingInputHint(null);
    dialogBp.setContentScrolled(false);
    if (dialogBounds != null) {
        dialogBp.setPosition(dialogBounds.getPosition()).setSize(dialogBounds.getSize());
        dialogBp.autoPackOff().autoCenterOff();
    }
    final IBeanLinkDialog<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> linkDialog;
    linkDialog = Toolkit.getActiveWindow().createChildWindow(dialogBp);
    final IBeanProxy<LINK_BEAN_TYPE> defaultLinkBean;
    if (linkDefaultFactory != null) {
        defaultLinkBean = linkDefaultFactory.create();
    } else {
        defaultLinkBean = createDefaultBean(linkBeanForm, linkBeanTypeId, linkBeanType, linkBeanPropertyValidators);
    }
    final List<IBeanProxy<LINKABLE_BEAN_TYPE>> defaultLinkedBeans;
    if (linkableBeanForm != null) {
        defaultLinkedBeans = Collections.singletonList(createDefaultBean(linkableBeanForm, linkableBeanTypeId, linkableBeanType, linkableBeanPropertyValidators));
    } else {
        defaultLinkedBeans = Collections.emptyList();
    }
    linkDialog.setValue(new IBeanLink<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE>() {

        @Override
        public IBeanProxy<LINK_BEAN_TYPE> getLinkBean() {
            return defaultLinkBean;
        }

        @Override
        public List<IBeanProxy<LINKABLE_BEAN_TYPE>> getLinkableBeans() {
            return defaultLinkedBeans;
        }
    });
    linkDialog.setVisible(true);
    final IBeanLink<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> result;
    if (linkDialog.isOkPressed()) {
        final IBeanLink<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> dialogValue = linkDialog.getValue();
        result = new IBeanLink<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE>() {

            @Override
            public IBeanProxy<LINK_BEAN_TYPE> getLinkBean() {
                final IBeanProxy<LINK_BEAN_TYPE> original = dialogValue.getLinkBean();
                return original != null ? original : defaultLinkBean;
            }

            @Override
            public List<IBeanProxy<LINKABLE_BEAN_TYPE>> getLinkableBeans() {
                return dialogValue.getLinkableBeans();
            }
        };
    } else {
        result = null;
    }
    dialogBounds = linkDialog.getBounds();
    linkDialog.dispose();
    return result;
}
Also used : Dimension(org.jowidgets.common.types.Dimension) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy) ICapApiBluePrintFactory(org.jowidgets.cap.ui.api.widgets.ICapApiBluePrintFactory) List(java.util.List) LinkedList(java.util.LinkedList)

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