use of org.jowidgets.cap.common.api.execution.IExecutionCallbackListener 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.common.api.execution.IExecutionCallbackListener 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.common.api.execution.IExecutionCallbackListener in project jo-client-platform by jo-source.
the class CsvExporter method startExportBeans.
private void startExportBeans(final IBeanProvider beanProvider, final Integer totalCount, final IExecutionCallback executionCallback) throws Exception {
final File file = new File(parameter.getFilename());
final FileOutputStream fos = new FileOutputStream(file);
final PrintStream ps = new PrintStream(fos, true, parameter.getEncoding());
executionCallback.addExecutionCallbackListener(new IExecutionCallbackListener() {
@Override
public void canceled() {
try {
closeStream(ps);
} catch (final Exception e) {
}
}
});
writeHeader(ps);
exportBeans(beanProvider, ps, 0, totalCount, executionCallback);
}
use of org.jowidgets.cap.common.api.execution.IExecutionCallbackListener 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.common.api.execution.IExecutionCallbackListener in project jo-client-platform by jo-source.
the class PasteLinkCommand method linkBeans.
private void linkBeans(final IExecutionContext executionContext, final List<IBeanProxy<SOURCE_BEAN_TYPE>> selection) {
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 Collection<ILinkCreation> linkCreations = linkProvider.get();
executionObservable.fireAfterExecutionPrepared(executionContext);
linkCreatorService.create(createResultCallback(selection, executionContext), linkCreations, executionTask);
}
Aggregations