use of org.jowidgets.cap.ui.api.execution.IExecutionTask in project jo-client-platform by jo-source.
the class BeansStateTrackerImpl method cancelExecutions.
@Override
public void cancelExecutions() {
final Set<IExecutionTask> tasks = new HashSet<IExecutionTask>();
for (final IBeanProxy<BEAN_TYPE> bean : new HashSet<IBeanProxy<BEAN_TYPE>>(processingBeans)) {
tasks.add(bean.getExecutionTask());
bean.setExecutionTask(null);
}
processingBeans.clear();
for (final IExecutionTask task : tasks) {
if (task != null && !task.isCanceled() && !task.isFinshed()) {
final Runnable runnable = new Runnable() {
@Override
public void run() {
task.cancel();
}
};
final Thread thread = new Thread(runnable);
thread.setDaemon(true);
thread.start();
}
}
}
use of org.jowidgets.cap.ui.api.execution.IExecutionTask in project jo-client-platform by jo-source.
the class BeanCreatorCommand method createBean.
private void createBean(final IExecutionContext executionContext, final IBeanProxy<BEAN_TYPE> bean) {
final IExecutionTask executionTask = CapUiToolkit.executionTaskFactory().create(executionContext);
bean.setExecutionTask(executionTask);
final IUiThreadAccess uiThreadAccess = Toolkit.getUiThreadAccess();
executionTask.addExecutionCallbackListener(new IExecutionCallbackListener() {
@Override
public void canceled() {
uiThreadAccess.invokeLater(new Runnable() {
@Override
public void run() {
bean.setExecutionTask(null);
model.removeBeans(Collections.singletonList(bean));
model.fireBeansChanged();
executionObservable.fireAfterExecutionCanceled(executionContext);
}
});
}
});
model.addBean(bean);
final IBeanData beanData = createBeanData(bean);
final List<IBeanData> data = Collections.singletonList(beanData);
executionObservable.fireAfterExecutionPrepared(executionContext);
creatorService.create(new ResultCallback(executionContext, bean), parentBeanKeysProvider.get(), data, executionTask);
}
use of org.jowidgets.cap.ui.api.execution.IExecutionTask in project jo-client-platform by jo-source.
the class BeanLinkCreatorCommand method linkBeans.
private void linkBeans(final IExecutionContext executionContext, final List<IBeanProxy<SOURCE_BEAN_TYPE>> selection, final IBeanLink<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> beanLink) {
final IExecutionTask executionTask = CapUiToolkit.executionTaskFactory().create(executionContext);
final IUiThreadAccess uiThreadAccess = Toolkit.getUiThreadAccess();
executionTask.addExecutionCallbackListener(new IExecutionCallbackListener() {
@Override
public void canceled() {
uiThreadAccess.invokeLater(new Runnable() {
@Override
public void run() {
for (final IBeanProxy<SOURCE_BEAN_TYPE> bean : selection) {
bean.setExecutionTask(null);
}
executionObservable.fireAfterExecutionCanceled(executionContext);
}
});
}
});
final ILinkCreationBuilder linkCreationBuilder = LinkCreation.builder();
// add the source beans
for (final IBeanProxy<SOURCE_BEAN_TYPE> sourceBean : selection) {
if (sourceBean.isTransient()) {
linkCreationBuilder.addTransientSourceBean(sourceBean.getBeanData());
} else {
linkCreationBuilder.addSourceBean(sourceBean.getBeanKey());
}
}
// add the linkable beans
for (final IBeanProxy<LINKABLE_BEAN_TYPE> linkableBean : beanLink.getLinkableBeans()) {
if (linkableBean.isTransient()) {
linkCreationBuilder.addTransientLinkableBean(linkableBean.getBeanData());
} else {
linkCreationBuilder.addLinkableBean(linkableBean.getBeanKey());
}
}
// set the additional properties
final IBeanProxy<LINK_BEAN_TYPE> linkBean = beanLink.getLinkBean();
if (linkBean != null) {
linkCreationBuilder.setAdditionalLinkProperties(linkBean.getBeanData());
}
final Set<ILinkCreation> linkCreations = Collections.singleton(linkCreationBuilder.build());
executionObservable.fireAfterExecutionPrepared(executionContext);
linkCreatorService.create(createResultCallback(selection, executionContext), linkCreations, executionTask);
}
use of org.jowidgets.cap.ui.api.execution.IExecutionTask in project jo-client-platform by jo-source.
the class BeanListExecutionHelper method prepareExecutions.
List<List<IBeanProxy<BEAN_TYPE>>> prepareExecutions(final boolean allowTransient, final IExecutionContext executionContext) {
final List<List<IBeanProxy<BEAN_TYPE>>> result = new LinkedList<List<IBeanProxy<BEAN_TYPE>>>();
if (BeanExecutionPolicy.BATCH == beanExecutionPolicy) {
final IExecutionTask executionTask = createExecutionTask(executionContext);
final List<IBeanProxy<BEAN_TYPE>> subList = new LinkedList<IBeanProxy<BEAN_TYPE>>();
result.add(subList);
for (final IBeanProxy<BEAN_TYPE> bean : beans) {
if (bean.getExecutionTask() == null && !bean.isDummy() && !bean.isLastRowDummy() && (allowTransient || !bean.isTransient())) {
bean.setExecutionTask(executionTask);
subList.add(bean);
}
}
} else {
for (final IBeanProxy<BEAN_TYPE> bean : beans) {
final List<IBeanProxy<BEAN_TYPE>> subList = new LinkedList<IBeanProxy<BEAN_TYPE>>();
result.add(subList);
if (bean.getExecutionTask() == null && !bean.isDummy() && (allowTransient || !bean.isTransient())) {
final IExecutionTask executionTask = createExecutionTask(executionContext);
bean.setExecutionTask(executionTask);
subList.add(bean);
}
}
}
if (fireBeansChanged) {
listModel.fireBeansChanged();
}
return result;
}
use of org.jowidgets.cap.ui.api.execution.IExecutionTask in project jo-client-platform by jo-source.
the class BeanListExecutionHelper method onExecption.
void onExecption(final List<IBeanProxy<BEAN_TYPE>> executedBeans, final Throwable exception) {
int beanIndex = 0;
for (final IBeanProxy<BEAN_TYPE> bean : executedBeans) {
final IExecutionTask executionTask = bean.getExecutionTask();
final boolean canceled = (exception instanceof ServiceCanceledException) || (executionTask != null && executionTask.isCanceled());
if (!canceled) {
bean.addMessage(exceptionConverter.convert(shortErrorMessage, executedBeans, beanIndex++, bean, exception));
}
bean.setExecutionTask(null);
}
if (fireBeansChanged) {
listModel.fireBeansChanged();
}
}
Aggregations