use of org.jowidgets.cap.ui.api.execution.IExecutionTask in project jo-client-platform by jo-source.
the class BeanListSaveDelegate method update.
private void update(final Runnable finishedCallback) {
final Set<IBeanProxy<BEAN_TYPE>> modifiedBeans = beansStateTracker.getMasterBeansToUpdate();
if (!EmptyCheck.isEmpty(modifiedBeans)) {
if (updaterService == null) {
throw new IllegalStateException("No updater service set. Can not update modified beans");
}
final BeanListExecutionHelper<BEAN_TYPE> executionHelper = new BeanListExecutionHelper<BEAN_TYPE>(SAVE_FAILED.get(), listModel, modifiedBeans, beanExecutionPolicy, exceptionConverter, false, fireBeansChanged);
final List<List<IBeanProxy<BEAN_TYPE>>> preparedExecutions = executionHelper.prepareExecutions(false, 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(SAVE.get());
final List<IBeanModification> modifications = new LinkedList<IBeanModification>();
for (final IBeanProxy<?> bean : preparedBeans) {
modifications.addAll(bean.getModifications());
}
final IResultCallback<List<IBeanDto>> helperCallback = executionHelper.createResultCallback(preparedBeans, countDownRunnable);
updaterService.update(helperCallback, modifications, executionTask);
}
}
}
} else {
finishedCallback.run();
}
}
use of org.jowidgets.cap.ui.api.execution.IExecutionTask in project jo-client-platform by jo-source.
the class BeanProxyImpl method getProgress.
private String getProgress() {
String result = null;
final IExecutionTask currentExecutionTask = executionTask;
if (currentExecutionTask != null) {
final int worked = currentExecutionTask.getWorked();
final Integer total = currentExecutionTask.getTotalStepCount();
if (total != null) {
final double percent = (((double) worked) * 100) / total;
result = "" + Math.round(percent) + "%";
} else {
result = "?";
}
}
lastProgress = result;
return result;
}
use of org.jowidgets.cap.ui.api.execution.IExecutionTask in project jo-client-platform by jo-source.
the class ExecutionTask method cancel.
@Override
public void cancel() {
this.canceled = true;
fireCanceled();
for (final IExecutionTask subExecution : new LinkedList<IExecutionTask>(subExecutions)) {
subExecution.cancel();
}
}
use of org.jowidgets.cap.ui.api.execution.IExecutionTask in project jo-client-platform by jo-source.
the class ExecutionTaskFactory method create.
@Override
public IExecutionTask create(final IExecutionContext executionContext) {
final ExecutionTask result = new ExecutionTask();
result.addExecutionTaskListener(new ExecutionTaskMonitor(result, executionContext, Toolkit.getUiThreadAccess()));
return result;
}
use of org.jowidgets.cap.ui.api.execution.IExecutionTask 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