Search in sources :

Example 16 with ILookupCall

use of org.eclipse.scout.rt.shared.services.lookup.ILookupCall in project scout.rt by eclipse.

the class BatchLookupTest method testInternal.

private void testInternal(Class<? extends IFlowerLookupCall> callClazz, int expectedLocalInvocations, int expectedServerInvocations) throws Exception {
    m_localInvocations = 0;
    BatchLookupCall batchCall = new BatchLookupCall();
    for (int i = 0; i < 1000; i++) {
        IFlowerLookupCall call = callClazz.newInstance();
        call.setKey((i / 100) + 1L);
        call.setLatinId((i / 10) + 1L);
        batchCall.addLookupCall((LookupCall) call);
    }
    // 
    List<ILookupCall<?>> callArray = batchCall.getCallBatch();
    List<List<ILookupRow<?>>> resultArray = new BatchLookupService().getBatchDataByKey(batchCall);
    assertEquals(resultArray.size(), callArray.size());
    assertEquals(expectedLocalInvocations, m_localInvocations);
    Mockito.verify(m_lookupService, Mockito.times(expectedServerInvocations)).getDataByKey(Mockito.<ILookupCall<Object>>any());
    for (int i = 0; i < resultArray.size(); i++) {
        assertEquals(1, resultArray.get(i).size());
        assertEquals(callArray.get(i).getKey(), resultArray.get(i).get(0).getKey());
        assertEquals(dumpCall(callArray.get(i)), resultArray.get(i).get(0).getText());
    }
}
Also used : IBatchLookupService(org.eclipse.scout.rt.shared.services.lookup.IBatchLookupService) ArrayList(java.util.ArrayList) List(java.util.List) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall) BatchLookupCall(org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall)

Example 17 with ILookupCall

use of org.eclipse.scout.rt.shared.services.lookup.ILookupCall in project scout.rt by eclipse.

the class BatchNormalizerTest method setUp.

@Before
public void setUp() throws Exception {
    Answer answer = new Answer<List<ILookupRow<Object>>>() {

        @Override
        public List<ILookupRow<Object>> answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            ILookupCall<?> call = (ILookupCall<?>) args[0];
            return createCallResult(call);
        }
    };
    Mockito.doAnswer(answer).when(m_lookupService).getDataByKey(Mockito.<ILookupCall<Object>>any());
    Mockito.doAnswer(answer).when(m_lookupService).getDataByAll(Mockito.<ILookupCall<Object>>any());
    Mockito.doAnswer(answer).when(m_lookupService).getDataByText(Mockito.<ILookupCall<Object>>any());
    Mockito.doAnswer(answer).when(m_lookupService).getDataByRec(Mockito.<ILookupCall<Object>>any());
}
Also used : Answer(org.mockito.stubbing.Answer) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall) Before(org.junit.Before)

Example 18 with ILookupCall

use of org.eclipse.scout.rt.shared.services.lookup.ILookupCall in project scout.rt by eclipse.

the class SmartFieldLookupTest method testSubtreeLookup_FilterResult.

@Test
public void testSubtreeLookup_FilterResult() {
    ISmartField<Long> field = new AbstractSmartField<Long>() {

        @Override
        protected void execFilterRecLookupResult(ILookupCall<Long> call, List<ILookupRow<Long>> result) {
            result.clear();
        }
    };
    field.setLookupCall(new TestLookupCall());
    List<? extends ILookupRow<Long>> rows2 = field.callSubTreeLookup(1L);
    assertEquals(0, rows2.size());
}
Also used : TestLookupCall(org.eclipse.scout.rt.client.ui.form.fields.smartfield.fixture.TestLookupCall) ArrayList(java.util.ArrayList) List(java.util.List) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall) Test(org.junit.Test)

Example 19 with ILookupCall

use of org.eclipse.scout.rt.shared.services.lookup.ILookupCall in project scout.rt by eclipse.

the class AbstractContentAssistField method newByKeyLookupRowProvider.

// ==== Lookup row fetching strategies ==== //
/**
 * Creates a {@link ILookupRowProvider} to fetch a row by key.
 *
 * @see LookupCall#getDataByKey()
 * @see LookupCall#getDataByAllInBackground(ILookupRowFetchedCallback)
 */
protected ILookupRowProvider<LOOKUP_KEY> newByKeyLookupRowProvider(final LOOKUP_KEY key) {
    return new ILookupRowProvider<LOOKUP_KEY>() {

        @Override
        public void beforeProvide(ILookupCall<LOOKUP_KEY> lookupCall) {
            prepareKeyLookup(lookupCall, key);
        }

        @Override
        public void afterProvide(ILookupCall<LOOKUP_KEY> lookupCall, List<ILookupRow<LOOKUP_KEY>> result) {
            interceptFilterLookupResult(lookupCall, result);
            interceptFilterKeyLookupResult(lookupCall, 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.getDataByKeyInBackground(clientRunContext, callback);
        }

        @SuppressWarnings("unchecked")
        @Override
        public List<ILookupRow<LOOKUP_KEY>> provide(ILookupCall<LOOKUP_KEY> lookupCall) {
            return (List<ILookupRow<LOOKUP_KEY>>) lookupCall.getDataByKey();
        }

        @Override
        public String toString() {
            ToStringBuilder sb = new ToStringBuilder(this).attr("Key Lookup").attr("key", key);
            return sb.toString();
        }
    };
}
Also used : ClientRunContext(org.eclipse.scout.rt.client.context.ClientRunContext) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) ILookupRowFetchedCallback(org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback) ToStringBuilder(org.eclipse.scout.rt.platform.util.ToStringBuilder) EventListenerList(org.eclipse.scout.rt.platform.util.EventListenerList) List(java.util.List) ArrayList(java.util.ArrayList) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall)

Example 20 with ILookupCall

use of org.eclipse.scout.rt.shared.services.lookup.ILookupCall in project scout.rt by eclipse.

the class AbstractContentAssistField method newByAllLookupRowProvider.

/**
 * Creates a {@link ILookupRowProvider} to fetch all rows.
 *
 * @see LookupCall#getDataByAll()
 * @see LookupCall#getDataByAllInBackground(ILookupRowFetchedCallback)
 */
protected ILookupRowProvider<LOOKUP_KEY> newByAllLookupRowProvider(final String browseHint, final TriState activeState) {
    return new ILookupRowProvider<LOOKUP_KEY>() {

        @Override
        public void beforeProvide(ILookupCall<LOOKUP_KEY> lookupCall) {
            prepareBrowseLookup(lookupCall, browseHint, activeState);
        }

        @Override
        public void afterProvide(ILookupCall<LOOKUP_KEY> lookupCall, List<ILookupRow<LOOKUP_KEY>> result) {
            interceptFilterLookupResult(lookupCall, result);
            interceptFilterBrowseLookupResult(lookupCall, 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.getDataByAllInBackground(clientRunContext, callback);
        }

        @SuppressWarnings("unchecked")
        @Override
        public List<ILookupRow<LOOKUP_KEY>> provide(ILookupCall<LOOKUP_KEY> lookupCall) {
            return (List<ILookupRow<LOOKUP_KEY>>) lookupCall.getDataByAll();
        }

        @Override
        public String toString() {
            ToStringBuilder sb = new ToStringBuilder(this).attr("All Lookup").attr("browseHint", browseHint).attr("activeState", activeState);
            return sb.toString();
        }
    };
}
Also used : ClientRunContext(org.eclipse.scout.rt.client.context.ClientRunContext) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) ILookupRowFetchedCallback(org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback) ToStringBuilder(org.eclipse.scout.rt.platform.util.ToStringBuilder) EventListenerList(org.eclipse.scout.rt.platform.util.EventListenerList) List(java.util.List) ArrayList(java.util.ArrayList) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall)

Aggregations

ILookupCall (org.eclipse.scout.rt.shared.services.lookup.ILookupCall)25 ArrayList (java.util.ArrayList)19 List (java.util.List)19 ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)18 ClientRunContext (org.eclipse.scout.rt.client.context.ClientRunContext)8 ToStringBuilder (org.eclipse.scout.rt.platform.util.ToStringBuilder)8 BatchLookupResultCache (org.eclipse.scout.rt.shared.services.lookup.BatchLookupResultCache)8 ILookupRowFetchedCallback (org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback)8 BatchLookupCall (org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall)6 Test (org.junit.Test)5 ILookupRowProvider (org.eclipse.scout.rt.client.ui.form.fields.smartfield.ILookupRowProvider)4 EventListenerList (org.eclipse.scout.rt.platform.util.EventListenerList)4 TestLookupCall (org.eclipse.scout.rt.client.ui.form.fields.smartfield.fixture.TestLookupCall)3 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)2 BatchLookupNormalizer (org.eclipse.scout.rt.shared.services.lookup.BatchLookupNormalizer)2 IBatchLookupService (org.eclipse.scout.rt.shared.services.lookup.IBatchLookupService)2 Before (org.junit.Before)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 IMixedSmartField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.IMixedSmartField)1