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