use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.
the class BeanListExecutionHelper method updateBeans.
private void updateBeans(final List<IBeanProxy<BEAN_TYPE>> executedBeans, final List<IBeanDto> result) {
// put the resulting beans into a map for faster access later
final Map<Object, IBeanDto> resultMap = new LinkedHashMap<Object, IBeanDto>();
for (final IBeanDto beanDto : result) {
resultMap.put(beanDto.getId(), beanDto);
}
// update the executed beans with the beans get as result from the service
final List<IBeanProxy<BEAN_TYPE>> beansToDelete = new LinkedList<IBeanProxy<BEAN_TYPE>>();
for (final IBeanProxy<BEAN_TYPE> bean : executedBeans) {
final IBeanDto updatedBean = resultMap.remove(bean.getId());
if (updatedBean != null) {
bean.update(updatedBean);
} else {
beansToDelete.add(bean);
}
}
// remove the beans from the model that was not returned by the service
if (!beansToDelete.isEmpty()) {
listModel.removeBeans(beansToDelete);
}
// add the beans to the model that was created by the service
for (final IBeanDto beanDto : resultMap.values()) {
listModel.addBeanDto(beanDto);
}
}
use of org.jowidgets.cap.ui.api.bean.IBeanProxy 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.bean.IBeanProxy in project jo-client-platform by jo-source.
the class BeanProxyFactoryImpl method createProxies.
@Override
public List<IBeanProxy<BEAN_TYPE>> createProxies(final Collection<? extends IBeanDto> beanDtos, final IAttributeSet attributes) {
Assert.paramNotNull(beanDtos, "beanDtos");
Assert.paramNotNull(attributes, "attributes");
final List<IBeanProxy<BEAN_TYPE>> result = new LinkedList<IBeanProxy<BEAN_TYPE>>();
for (final IBeanDto beanDto : beanDtos) {
result.add(createProxy(beanDto, attributes));
}
return result;
}
use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.
the class BeanSelectionProviderEnabledChecker method getEnabledState.
@Override
public IEnabledState getEnabledState() {
// TODO MG enabled checks must be done better performance
if (BeanSelectionPolicy.SINGLE_SELECTION == beanSelectionPolicy && lastSelection.size() != 1) {
return SINGLE_SELECTION_STATE.get();
} else if (BeanSelectionPolicy.MULTI_SELECTION == beanSelectionPolicy && lastSelection.size() < 1) {
return MULTI_SELECTION_STATE.get();
} else if (BeanSelectionPolicy.NO_SELECTION == beanSelectionPolicy && lastSelection.size() > 0) {
return NO_SELECTION_STATE.get();
}
for (final IEnabledChecker enabledChecker : enabledCheckers) {
final IEnabledState result = enabledChecker.getEnabledState();
if (!result.isEnabled()) {
return result;
}
}
if (!ignoreSelectedBeansState) {
for (final IBeanProxy bean : lastSelection) {
if (bean == null) {
return UNLOADED_DATA_STATE.get();
}
if (bean.isDummy() || bean.isLastRowDummy()) {
return EnabledState.DISABLED;
}
final IBeanMessage worstMessage = bean.getFirstWorstMessage();
final IBeanMessage worstMandatoryMessage = bean.getFirstWorstMandatoryMessage();
if (bean.getExecutionTask() != null) {
return IS_IN_PROGRESS_STATE.get();
} else if (BeanMessageStatePolicy.NO_MESSAGE == beanMessageStatePolicy && worstMessage != null) {
return UNHANDLED_MESSAGES_STATE.get();
} else if (BeanMessageStatePolicy.NO_MESSAGE_MANDATORY == beanMessageStatePolicy && worstMandatoryMessage != null) {
return UNHANDLED_MESSAGES_STATE.get();
} else if (BeanModificationStatePolicy.NO_MODIFICATION == beanModificationStatePolicy && bean.hasModifications() && !bean.isTransient()) {
return UNSAVED_DATA_STATE.get();
} else if (BeanMessageStatePolicy.NO_WARNING_OR_ERROR == beanMessageStatePolicy && worstMessage != null && worstMessage.getType().equalOrWorse(BeanMessageType.WARNING)) {
return UNHANDLED_MESSAGES_STATE.get();
} else if (BeanMessageStatePolicy.NO_WARNING_OR_ERROR_MANDATORY == beanMessageStatePolicy && worstMandatoryMessage != null && worstMandatoryMessage.getType().equalOrWorse(BeanMessageType.WARNING)) {
return UNHANDLED_MESSAGES_STATE.get();
} else if (BeanMessageStatePolicy.NO_ERROR == beanMessageStatePolicy && worstMessage != null && worstMessage.getType() == BeanMessageType.ERROR) {
return UNHANDLED_MESSAGES_STATE.get();
} else if (BeanMessageStatePolicy.NO_ERROR_MANDATORY == beanMessageStatePolicy && worstMandatoryMessage != null && worstMandatoryMessage.getType() == BeanMessageType.ERROR) {
return UNHANDLED_MESSAGES_STATE.get();
}
for (final IExecutableChecker executableChecker : executableCheckers) {
final IExecutableState result = executableChecker.getExecutableState(bean.getBean());
if (!result.isExecutable()) {
return EnabledState.disabled(result.getReason());
}
}
}
}
return EnabledState.ENABLED;
}
use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.
the class BeanTableModelImpl method getParentBeanKeys.
@Override
public List<IBeanKey> getParentBeanKeys() {
if (parent == null) {
return null;
}
final IBeanSelection<Object> beanSelection = parent.getBeanSelection();
List<IBeanProxy<Object>> selection = beanSelection.getSelection();
if (EmptyCheck.isEmpty(selection)) {
return null;
} else if (linkType == LinkType.SELECTION_FIRST) {
selection = selection.subList(0, 1);
}
final List<IBeanKey> beanKeys = new LinkedList<IBeanKey>();
for (final IBeanProxy<Object> proxy : selection) {
if (proxy != null && !proxy.isDummy() && !proxy.isTransient() && !proxy.isLastRowDummy()) {
beanKeys.add(new BeanKey(proxy.getId(), proxy.getVersion()));
}
}
return beanKeys;
}
Aggregations