Search in sources :

Example 16 with IBeanProxy

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

the class BeanTableModelImpl method addSelectedBeansImpl.

@SuppressWarnings("unchecked")
private List<IBeanProxy<BEAN_TYPE>> addSelectedBeansImpl(final List<Integer> currentSelection, final Collection<? extends IBeanProxy<BEAN_TYPE>> selectedBeans) {
    final Set<Integer> newSelection = new LinkedHashSet<Integer>(currentSelection);
    final List<IBeanProxy<BEAN_TYPE>> result = new LinkedList<IBeanProxy<BEAN_TYPE>>();
    boolean setSelection = EmptyCheck.isEmpty(currentSelection);
    if (!EmptyCheck.isEmpty(selectedBeans)) {
        // use hash set instead of collection for faster access
        final Set<IBeanProxy<BEAN_TYPE>> selectedBeansSet;
        if (selectedBeans instanceof HashSet) {
            selectedBeansSet = (Set<IBeanProxy<BEAN_TYPE>>) selectedBeans;
        } else {
            selectedBeansSet = new HashSet<IBeanProxy<BEAN_TYPE>>(selectedBeans);
        }
        for (final Entry<Integer, ArrayList<IBeanProxy<BEAN_TYPE>>> pageEntry : data.entrySet()) {
            final int pageIndex = pageEntry.getKey().intValue();
            final int pageStartIndex = pageIndex * pageSize;
            int relativeIndex = 0;
            for (final IBeanProxy<BEAN_TYPE> bean : pageEntry.getValue()) {
                if (bean != null && selectedBeansSet.contains(bean)) {
                    setSelection = newSelection.add(Integer.valueOf(pageStartIndex + relativeIndex)) || setSelection;
                    result.add(bean);
                }
                relativeIndex++;
            }
        }
        final int dataRowCount = dataModel.getDataRowCount();
        int relativeIndex = 0;
        for (final IBeanProxy<BEAN_TYPE> bean : addedData) {
            if (bean != null && selectedBeansSet.contains(bean)) {
                setSelection = newSelection.add(Integer.valueOf(dataRowCount + relativeIndex)) || setSelection;
                result.add(bean);
            }
            relativeIndex++;
        }
    }
    if (setSelection) {
        setSelection(newSelection);
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TableCellBluePrint(org.jowidgets.tools.model.table.TableCellBluePrint) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 17 with IBeanProxy

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

the class BeanTableModelImpl method updateBeansInAddedData.

private void updateBeansInAddedData(final Map<Object, IBeanDto> beansToUpateById, final boolean sorted, final Comparator<IBeanDto> comparator) {
    boolean sortingChanged = false;
    IBeanProxy<BEAN_TYPE> previousBean = null;
    IBeanProxy<BEAN_TYPE> lastUpdatedBean = null;
    for (final IBeanProxy<BEAN_TYPE> beanProxy : addedData) {
        if (beansToUpateById.isEmpty()) {
            break;
        }
        final IBeanDto beanToUpdate = beansToUpateById.get(beanProxy.getId());
        if (beanToUpdate != null) {
            beanProxy.update(beanToUpdate);
            beansToUpateById.remove(beanProxy.getId());
            if (sorted && !sortingChanged && previousBean != null && comparator.compare(previousBean, beanProxy) > 0) {
                sortingChanged = true;
            }
        }
        if (sorted && !sortingChanged && lastUpdatedBean != null && comparator.compare(lastUpdatedBean, beanProxy) > 0) {
            sortingChanged = true;
        }
        if (beanToUpdate != null) {
            lastUpdatedBean = beanProxy;
        } else {
            lastUpdatedBean = null;
        }
        previousBean = beanProxy;
    }
    if (!beansToUpateById.isEmpty()) {
        LOGGER.warn("Cannot find beans for the following updates:" + beansToUpateById.values().toString());
    }
    if (sorted && sortingChanged) {
        final List<IBeanProxy<BEAN_TYPE>> selectedBeans = getSelectedBeans();
        Collections.sort(addedData, comparator);
        int rowIndex = rowCountOfPages;
        for (final IBeanProxy<BEAN_TYPE> bean : addedData) {
            updateRowIndexOfBean(bean, rowIndex);
            rowIndex += 1;
        }
        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 18 with IBeanProxy

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

the class BeanTableModelImpl method addBeansUnsorted.

private void addBeansUnsorted(final Collection<IBeanProxy<BEAN_TYPE>> beansToAdd) {
    for (final IBeanProxy<BEAN_TYPE> bean : beansToAdd) {
        addedData.add(bean);
        final int index = dataModel.getRowCount() - dataModel.getLastBeanCount() - 1;
        bean.addPropertyChangeListener(new BeanPropertyChangeListener(index));
    }
    beansStateTracker.register(beansToAdd);
    cachedReaderService.addBeans(getParentBeanKeys(), new HashSet<IBeanProxy<BEAN_TYPE>>(beansToAdd));
}
Also used : TableCellBluePrint(org.jowidgets.tools.model.table.TableCellBluePrint) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 19 with IBeanProxy

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

the class BeanTableSetToAllCommand method execute.

@Override
public void execute(final IExecutionContext executionContext) throws Exception {
    final ITableCellPopupEvent event = executionContext.getValue(IBeanTable.CELL_POPUP_EVENT_CONTEXT_KEY);
    final int rowIndex = event.getRowIndex();
    final Object value = model.getValue(rowIndex, columnIndex);
    final List<IBeanProxy<BEAN_TYPE>> selectedBeans = model.getSelectedBeans();
    if (model.getSelectedBeans().size() > 1) {
        for (final IBeanProxy<BEAN_TYPE> bean : selectedBeans) {
            if (bean != null && !bean.isDisposed() && !bean.isDummy() && !bean.isLastRowDummy()) {
                bean.setValue(propertyName, value);
            }
        }
    } else {
        for (int i = 0; i < model.getSize(); i++) {
            final IBeanProxy<?> bean = model.getBean(i);
            if (bean != null && !bean.isDisposed() && !bean.isDummy() && !bean.isLastRowDummy()) {
                bean.setValue(propertyName, value);
            }
        }
    }
}
Also used : ITableCellPopupEvent(org.jowidgets.common.widgets.controller.ITableCellPopupEvent) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 20 with IBeanProxy

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

the class BeanDeleterCommand method execute.

@Override
public void execute(final IExecutionContext executionContext) throws Exception {
    if (!executionObservable.fireBeforeExecution(executionContext)) {
        return;
    }
    final IBeanSelection<BEAN_TYPE> beanSelection = model.getBeanSelection();
    if (beanSelection == null || beanSelection.getSelection().size() == 0) {
        Toolkit.getMessagePane().showWarning(executionContext, NOTHING_SELECTED.get());
        return;
    }
    if (deletionConfirmDialog) {
        if (!showDeletionConfirmDialog(executionContext, beanSelection)) {
            executionObservable.fireAfterExecutionCanceled(executionContext);
            return;
        }
    }
    final IBeanKeyFactory beanKeyFactory = CapUiToolkit.beanKeyFactory();
    final IExecutionTask executionTask = CapUiToolkit.executionTaskFactory().create(executionContext);
    final List<IBeanKey> beanKeys = new LinkedList<IBeanKey>();
    final List<IBeanProxy<BEAN_TYPE>> beans = new LinkedList<IBeanProxy<BEAN_TYPE>>();
    final List<IBeanProxy<BEAN_TYPE>> transientBeans = new LinkedList<IBeanProxy<BEAN_TYPE>>();
    for (final IBeanProxy<BEAN_TYPE> bean : beanSelection.getSelection()) {
        if (bean != null && bean.isTransient()) {
            transientBeans.add(bean);
        } else if (bean != null && !bean.isDummy() && !bean.isLastRowDummy()) {
            bean.setExecutionTask(executionTask);
            beanKeys.add(beanKeyFactory.createKey(bean));
            beans.add(bean);
        }
    }
    final IUiThreadAccess uiThreadAccess = Toolkit.getUiThreadAccess();
    executionTask.addExecutionCallbackListener(new IExecutionCallbackListener() {

        @Override
        public void canceled() {
            uiThreadAccess.invokeLater(new Runnable() {

                @Override
                public void run() {
                    for (final IBeanProxy<BEAN_TYPE> bean : beans) {
                        bean.setExecutionTask(null);
                    }
                    model.fireBeansChanged();
                    executionObservable.fireAfterExecutionCanceled(executionContext);
                }
            });
        }
    });
    if (autoSelection) {
        final ArrayList<Integer> selection = model.getSelection();
        if (!EmptyCheck.isEmpty(selection)) {
            final int newSelectionIndex = selection.get(selection.size() - 1) + 1;
            if (newSelectionIndex >= 0 && newSelectionIndex < model.getSize()) {
                model.setSelection(Collections.singletonList(newSelectionIndex));
            }
        }
    }
    if (!transientBeans.isEmpty()) {
        model.removeBeans(transientBeans);
    }
    model.fireBeansChanged();
    executionObservable.fireAfterExecutionPrepared(executionContext);
    if (!beanKeys.isEmpty()) {
        deleterService.delete(new ResultCallback(executionContext, beans), beanKeys, executionTask);
    }
}
Also used : IExecutionCallbackListener(org.jowidgets.cap.common.api.execution.IExecutionCallbackListener) AbstractUiResultCallback(org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback) IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask) IUiThreadAccess(org.jowidgets.api.threads.IUiThreadAccess) LinkedList(java.util.LinkedList) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IBeanKeyFactory(org.jowidgets.cap.ui.api.bean.IBeanKeyFactory)

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