use of org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback in project scout.rt by eclipse.
the class AbstractContentAssistField method newByRecLookupRowProvider.
/**
* @see LookupCall#getDataByRec()
*/
protected ILookupRowProvider<LOOKUP_KEY> newByRecLookupRowProvider(final LOOKUP_KEY parentKey, final TriState activeState) {
return new ILookupRowProvider<LOOKUP_KEY>() {
@SuppressWarnings("unchecked")
@Override
public List<ILookupRow<LOOKUP_KEY>> provide(ILookupCall<LOOKUP_KEY> lookupCall) {
return (List<ILookupRow<LOOKUP_KEY>>) lookupCall.getDataByRec();
}
@Override
public void beforeProvide(ILookupCall<LOOKUP_KEY> lookupCall) {
prepareRecLookup(lookupCall, parentKey, activeState);
}
@Override
public void afterProvide(ILookupCall<LOOKUP_KEY> lookupCall, List<ILookupRow<LOOKUP_KEY>> result) {
interceptFilterLookupResult(lookupCall, result);
interceptFilterRecLookupResult(lookupCall, result);
cleanupResultList(result);
}
@Override
public void provideSync(ILookupCall<LOOKUP_KEY> lookupCall, ILookupRowFetchedCallback<LOOKUP_KEY> callback) {
throw new UnsupportedOperationException("Legacy calls not supported");
}
@Override
public IFuture<Void> provideAsync(ILookupCall<LOOKUP_KEY> lookupCall, ILookupRowFetchedCallback<LOOKUP_KEY> 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.ILookupRowFetchedCallback in project scout.rt by eclipse.
the class AbstractContentAssistField method newByTextLookupRowProvider.
/**
* Creates a {@link ILookupRowProvider} to fetch rows matching the given text.
*
* @see LookupCall#getDataByText()
* @see LookupCall#getDataByTextInBackground(ILookupRowFetchedCallback)
*/
protected ILookupRowProvider<LOOKUP_KEY> newByTextLookupRowProvider(final String text) {
return new ILookupRowProvider<LOOKUP_KEY>() {
@Override
public void beforeProvide(ILookupCall<LOOKUP_KEY> lookupCall) {
prepareTextLookup(lookupCall, text);
}
@Override
public void afterProvide(ILookupCall<LOOKUP_KEY> call, List<ILookupRow<LOOKUP_KEY>> result) {
interceptFilterLookupResult(call, result);
interceptFilterTextLookupResult(call, result);
cleanupResultList(result);
}
@Override
public void provideSync(ILookupCall<LOOKUP_KEY> lookupCall, ILookupRowFetchedCallback<LOOKUP_KEY> callback) {
callback.onSuccess(provide(lookupCall));
}
@Override
public IFuture<Void> provideAsync(ILookupCall<LOOKUP_KEY> lookupCall, ILookupRowFetchedCallback<LOOKUP_KEY> callback, ClientRunContext clientRunContext) {
return lookupCall.getDataByTextInBackground(clientRunContext, callback);
}
@SuppressWarnings("unchecked")
@Override
public List<ILookupRow<LOOKUP_KEY>> provide(ILookupCall<LOOKUP_KEY> lookupCall) {
return (List<ILookupRow<LOOKUP_KEY>>) lookupCall.getDataByText();
}
@Override
public String toString() {
ToStringBuilder sb = new ToStringBuilder(this).attr("Text Lookup").attr("text", text);
return sb.toString();
}
};
}
use of org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback 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.ILookupRowFetchedCallback 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.ILookupRowFetchedCallback in project scout.rt by eclipse.
the class SmartFieldLookupTest method testTextLookupExceptions_InBackground.
@SuppressWarnings("unchecked")
@Test
public void testTextLookupExceptions_InBackground() throws InterruptedException {
m_field.setLookupCall(new TestLookupCall());
final String errorText = "lookup error";
when(m_mock_service.getDataByText(any(ILookupCall.class))).thenThrow(new PlatformException(errorText));
final IBlockingCondition bc = Jobs.newBlockingCondition(true);
ILookupRowFetchedCallback callback = new ILookupRowFetchedCallback<Long>() {
@Override
public void onSuccess(List<? extends ILookupRow<Long>> rows) {
Assert.fail("no exception thrown");
bc.setBlocking(false);
}
@Override
public void onFailure(RuntimeException exception) {
assertTrue(exception instanceof PlatformException);
assertEquals(errorText, exception.getMessage());
bc.setBlocking(false);
}
};
m_field.callTextLookupInBackground("", 10, callback);
bc.waitFor();
}
Aggregations