use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.
the class BatchLookupService method getBatchDataByAll.
@Override
public List<List<ILookupRow<?>>> getBatchDataByAll(BatchLookupCall batch) {
List<ILookupCall<?>> calls = batch.getCallBatch();
List<List<ILookupRow<?>>> result = new ArrayList<List<ILookupRow<?>>>();
BatchLookupResultCache cache = new BatchLookupResultCache();
for (ILookupCall<?> call : calls) {
result.add(new ArrayList<ILookupRow<?>>(cache.getDataByAll(call)));
}
return result;
}
use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.
the class AbstractSmartField2 method fetchLookupRows.
/**
* Loads lookup rows according to the specified {@link ILookupRowProvider}, and notifies the specified callback upon
* fetching completed.
*
* @return {@link IFuture} if data is fetched asynchronously, or <code>null</code> for synchronous fetching, or if
* using {@link LocalLookupCall}.
*/
private IFuture<Void> fetchLookupRows(final ILookupRowProvider<VALUE> dataProvider, final ILookupRowFetchedCallback<VALUE> callback, final boolean asynchronousFetching, final int maxRowCount) {
cancelPotentialLookup();
if (getLookupCall() == null) {
callback.onSuccess(Collections.<ILookupRow<VALUE>>emptyList());
return null;
}
// Prepare the lookup call.
final ILookupCall<VALUE> lookupCall = cloneLookupCall();
lookupCall.setMaxRowCount(maxRowCount > 0 ? maxRowCount : getBrowseMaxRowCount());
// Prepare processing of the fetched rows.
final ILookupRowFetchedCallback<VALUE> internalCallback = new ILookupRowFetchedCallback<VALUE>() {
@Override
public void onSuccess(final List<? extends ILookupRow<VALUE>> rows) {
joinModelThreadAndUpdateField(rows, null);
}
@Override
public void onFailure(final RuntimeException e) {
joinModelThreadAndUpdateField(null, e);
}
private void joinModelThreadAndUpdateField(final List<? extends ILookupRow<VALUE>> rows, final RuntimeException exception) {
if (ModelJobs.isModelThread()) {
updateField(rows, exception);
} else {
// Note: The model job will not commence execution if the current ClientRunContext is or gets cancelled.
try {
ClientRunContext callerRunContext = ClientRunContexts.copyCurrent();
if (callerRunContext.getRunMonitor().isCancelled()) {
return;
}
ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
updateField(rows, exception);
}
}, ModelJobs.newInput(callerRunContext).withName("Updating {}", AbstractSmartField2.this.getClass().getName())).awaitDone();
} catch (ThreadInterruptedError e) {
/*
This state can be reached by a race condition when the job's RunMonitor is in canceled state and later the ModelJob is run.
This yields to a Thread.interrupt in the RunContext.ThreadInterrupter...
at RunContext$ThreadInterrupter.cancel(boolean) line: 563
at RunMonitor.cancel(ICancellable, boolean) line: 160
at RunMonitor.registerCancellable(ICancellable) line: 104 <---------------------
at RunContext$ThreadInterrupter.<init>(Thread, RunMonitor) line: 545
at ClientRunContext(RunContext).call(Callable<RESULT>, Class<IExceptionTranslator<EXCEPTION>>) line: 154
at RunContextRunner<RESULT>.intercept(Chain<RESULT>) line: 38
which itself causes the running job to be interrupted with a InterruptedException
at org.eclipse.scout.rt.platform.job.internal.JobExceptionTranslator.translateInterruptedException(JobExceptionTranslator.java:49)
at org.eclipse.scout.rt.platform.job.internal.JobFutureTask.awaitDone(JobFutureTask.java:339)
at org.eclipse.scout.rt.client.ui.form.fields.smartfield2.AbstractSmartField2$7.joinModelThreadAndUpdateField(AbstractSmartField2.java:1598)
at org.eclipse.scout.rt.client.ui.form.fields.smartfield2.AbstractSmartField2$7.onSuccess(AbstractSmartField2.java:1575)
at org.eclipse.scout.rt.shared.services.lookup.LookupCall.loadData(LookupCall.java:437)
at org.eclipse.scout.rt.shared.services.lookup.LookupCall$5.run(LookupCall.java:417)
*/
return;
}
}
}
private void updateField(final List<? extends ILookupRow<VALUE>> rows, final RuntimeException exception) {
try {
if (exception != null) {
// throw to handle exception at the end.
throw exception;
}
final List<ILookupRow<VALUE>> result = new ArrayList<>(rows);
dataProvider.afterProvide(lookupCall, result);
callback.onSuccess(result);
} catch (FutureCancelledError | ThreadInterruptedError e) {
// NOSONAR
callback.onSuccess(Collections.<ILookupRow<VALUE>>emptyList());
} catch (final RuntimeException e) {
callback.onFailure(e);
}
}
};
// Start fetching lookup rows.
IFuture<Void> asyncLookupFuture = null;
try {
dataProvider.beforeProvide(lookupCall);
if (asynchronousFetching) {
asyncLookupFuture = dataProvider.provideAsync(lookupCall, internalCallback, ClientRunContexts.copyCurrent());
} else {
dataProvider.provideSync(lookupCall, internalCallback);
asyncLookupFuture = null;
}
} catch (final RuntimeException e) {
internalCallback.onFailure(e);
asyncLookupFuture = null;
}
m_lookupFuture = asyncLookupFuture;
return asyncLookupFuture;
}
use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.
the class AbstractSmartField2 method newByRecLookupRowProvider.
/**
* @see LookupCall#getDataByRec()
*/
protected ILookupRowProvider<VALUE> newByRecLookupRowProvider(final VALUE parentKey, final TriState activeState) {
return new ILookupRowProvider<VALUE>() {
@SuppressWarnings("unchecked")
@Override
public List<ILookupRow<VALUE>> provide(ILookupCall<VALUE> lookupCall) {
return (List<ILookupRow<VALUE>>) lookupCall.getDataByRec();
}
@Override
public void beforeProvide(ILookupCall<VALUE> lookupCall) {
prepareRecLookup(lookupCall, parentKey, activeState);
}
@Override
public void afterProvide(ILookupCall<VALUE> lookupCall, List<ILookupRow<VALUE>> result) {
interceptFilterLookupResult(lookupCall, result);
interceptFilterRecLookupResult(lookupCall, result);
cleanupResultList(result);
}
@Override
public void provideSync(ILookupCall<VALUE> lookupCall, ILookupRowFetchedCallback<VALUE> callback) {
throw new UnsupportedOperationException("Legacy calls not supported");
}
@Override
public IFuture<Void> provideAsync(ILookupCall<VALUE> lookupCall, ILookupRowFetchedCallback<VALUE> callback, ClientRunContext clientRunContext) {
throw new UnsupportedOperationException("Legacy calls not supported");
}
@Override
public String toString() {
ToStringBuilder sb = new ToStringBuilder(this).attr("Rec Lookup").attr("parentKey", parentKey).attr("activeState", activeState);
return sb.toString();
}
};
}
use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.
the class IncrementalTreeBuilder method createParentMap.
/**
* Creates a map containing every key in the tree and its parent tree node
*/
public Map<LOOKUP_KEY, ILookupRow<LOOKUP_KEY>> createParentMap(ITree tree) {
final Map<LOOKUP_KEY, ILookupRow<LOOKUP_KEY>> map = new HashMap<>();
tree.visitTree(new ITreeVisitor() {
@Override
public boolean visit(ITreeNode node) {
ITreeNode parent = node.getParentNode();
ILookupRow<LOOKUP_KEY> row = getLookupRow(node);
if (row != null) {
LOOKUP_KEY key = row.getKey();
m_keyCache.put(key, row);
map.put(key, getLookupRow(parent));
}
return true;
}
});
return map;
}
use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.
the class IncrementalTreeBuilderTest method testCreateParentMap_NonEmpty.
@Test
public void testCreateParentMap_NonEmpty() {
ITree tree = createTestTree();
tree.addChildNode(tree.getRootNode(), createNode(1L));
Map<Long, ILookupRow<Long>> parentMap = new IncrementalTreeBuilder<Long>(null).createParentMap(tree);
assertTrue(parentMap.size() == 1);
assertTrue(parentMap.containsKey(1L));
}
Aggregations