use of org.jowidgets.api.threads.IUiThreadAccess 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.api.threads.IUiThreadAccess 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.api.threads.IUiThreadAccess in project jo-client-platform by jo-source.
the class AbstractRemoteLoginService method createLoginInterceptor.
@Override
public ILoginInterceptor createLoginInterceptor() {
final ILoginInterceptor original = new RemotingBasicAuthenticationLoginInterceptor(getAuthorizationProviderServiceId());
return new ILoginInterceptor() {
@Override
public void login(final ILoginResultCallback resultCallback, final String username, final String password, final IUiThreadAccess uiThreadAccess) {
final ILoginResultCallback decoratedCallback = new ILoginResultCallback() {
@Override
public void addCancelListener(final ILoginCancelListener cancelListener) {
resultCallback.addCancelListener(cancelListener);
}
@Override
public void granted() {
afterLoginSuccess();
resultCallback.granted();
}
@Override
public void denied(final String reason) {
afterLoginFailed(reason);
resultCallback.denied(reason);
}
};
original.login(decoratedCallback, username, password, uiThreadAccess);
}
};
}
use of org.jowidgets.api.threads.IUiThreadAccess in project jo-client-platform by jo-source.
the class ParentSelectionListener method loadScheduled.
private void loadScheduled() {
if (listenerDelay > 0) {
childModel.clear();
}
if (schedule != null) {
schedule.cancel(false);
}
final IUiThreadAccess uiThreadAccess = Toolkit.getUiThreadAccess();
final Runnable runnable = new Runnable() {
@Override
public void run() {
uiThreadAccess.invokeLater(new Runnable() {
@Override
public void run() {
schedule = null;
load();
}
});
}
};
schedule = getExecutorService().schedule(runnable, listenerDelay, TimeUnit.MILLISECONDS);
}
use of org.jowidgets.api.threads.IUiThreadAccess 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