use of org.jowidgets.cap.common.api.bean.IBeanKey in project jo-client-platform by jo-source.
the class AbstractSyncCreatorServiceImpl method create.
@SuppressWarnings("unchecked")
@Override
public final List<IBeanDto> create(final List<? extends IBeanKey> parentBeanKeys, final Collection<? extends IBeanData> beansData, final IExecutionCallback executionCallback) {
final List<IBeanDto> result = new LinkedList<IBeanDto>();
final List<BEAN_TYPE> beans = new ArrayList<BEAN_TYPE>(beansData.size());
final Map<IdentityHashKey, IBeanData> beanDataMap = new HashMap<IdentityHashKey, IBeanData>();
for (final IBeanData beanData : beansData) {
CapServiceToolkit.checkCanceled(executionCallback);
final BEAN_TYPE bean = createBean((Collection<IBeanKey>) parentBeanKeys, executionCallback);
beanDataMap.put(new IdentityHashKey(bean), beanData);
beans.add(bean);
}
final IBeanDataMapper<BEAN_TYPE> beanDataMapper = new BeanDataMapper(beanDataMap);
beforeInitialize((List<IBeanKey>) parentBeanKeys, beans, beanDataMapper, executionCallback);
for (final BEAN_TYPE bean : beans) {
CapServiceToolkit.checkCanceled(executionCallback);
beanInitializer.initialize(bean, beanDataMapper.getBeanData(bean));
}
afterInitialize((List<IBeanKey>) parentBeanKeys, beans, beanDataMapper, executionCallback);
checkExecutableStates(beans, executionCallback);
validate(beans, executionCallback);
for (final BEAN_TYPE bean : beans) {
CapServiceToolkit.checkCanceled(executionCallback);
persistBean((Collection<IBeanKey>) parentBeanKeys, bean, executionCallback);
}
afterCreate((List<IBeanKey>) parentBeanKeys, beans, beanDataMapper, executionCallback);
for (final BEAN_TYPE bean : beans) {
CapServiceToolkit.checkCanceled(executionCallback);
result.add(dtoFactory.createDto(bean));
}
CapServiceToolkit.checkCanceled(executionCallback);
return result;
}
use of org.jowidgets.cap.common.api.bean.IBeanKey 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;
}
use of org.jowidgets.cap.common.api.bean.IBeanKey in project jo-client-platform by jo-source.
the class BeanRelationNodeModelImpl method getParentBeanKeys.
private List<IBeanKey> getParentBeanKeys() {
if (parentBean != null && !parentBean.isTransient() && !parentBean.isDummy()) {
final List<IBeanKey> result = new LinkedList<IBeanKey>();
result.add(new BeanKey(parentBean.getId(), parentBean.getVersion()));
return result;
} else {
return Collections.emptyList();
}
}
use of org.jowidgets.cap.common.api.bean.IBeanKey in project jo-client-platform by jo-source.
the class BeanListRefreshDelegate method refresh.
void refresh(final Collection<IBeanProxy<BEAN_TYPE>> beans) {
if (refreshService != null) {
final BeanListExecutionHelper<BEAN_TYPE> executionHelper = new BeanListExecutionHelper<BEAN_TYPE>(REFRESH_FAILED.get(), listModel, beans, beanExecutionPolicy, exceptionConverter, false, true);
for (final List<IBeanProxy<BEAN_TYPE>> preparedBeans : executionHelper.prepareExecutions(false)) {
if (preparedBeans.size() > 0) {
final IExecutionTask executionTask = preparedBeans.get(0).getExecutionTask();
if (executionTask != null) {
executionTask.setDescription(REFRESH.get());
final IBeanKeyFactory beanKeyFactory = CapUiToolkit.beanKeyFactory();
final List<IBeanKey> beanKeys = beanKeyFactory.createKeys(preparedBeans);
final IResultCallback<List<IBeanDto>> helperCallback = executionHelper.createResultCallback(preparedBeans);
refreshService.refresh(helperCallback, beanKeys, executionTask);
}
}
}
}
}
use of org.jowidgets.cap.common.api.bean.IBeanKey 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