use of org.jowidgets.cap.ui.api.bean.IBeanKeyFactory 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);
}
}
use of org.jowidgets.cap.ui.api.bean.IBeanKeyFactory 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);
}
}
}
}
}
Aggregations