Search in sources :

Example 21 with ILookupCall

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

the class AbstractSmartField2 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<VALUE> newByKeyLookupRowProvider(final VALUE key) {
    return new ILookupRowProvider<VALUE>() {

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

        @Override
        public void afterProvide(ILookupCall<VALUE> lookupCall, List<ILookupRow<VALUE>> result) {
            interceptFilterLookupResult(lookupCall, result);
            interceptFilterKeyLookupResult(lookupCall, result);
            cleanupResultList(result);
        }

        @Override
        public void provideSync(ILookupCall<VALUE> lookupCall, ILookupRowFetchedCallback<VALUE> callback) {
            callback.onSuccess(provide(lookupCall));
        }

        @Override
        public IFuture<Void> provideAsync(ILookupCall<VALUE> lookupCall, ILookupRowFetchedCallback<VALUE> callback, ClientRunContext clientRunContext) {
            return lookupCall.getDataByKeyInBackground(clientRunContext, callback);
        }

        @SuppressWarnings("unchecked")
        @Override
        public List<ILookupRow<VALUE>> provide(ILookupCall<VALUE> lookupCall) {
            return (List<ILookupRow<VALUE>>) 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) ILookupRowProvider(org.eclipse.scout.rt.client.ui.form.fields.smartfield.ILookupRowProvider) ILookupRowFetchedCallback(org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback) ToStringBuilder(org.eclipse.scout.rt.platform.util.ToStringBuilder) List(java.util.List) ArrayList(java.util.ArrayList) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall)

Example 22 with ILookupCall

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

the class AbstractSmartField2 method newByTextLookupRowProvider.

/**
 * Creates a {@link ILookupRowProvider} to fetch rows matching the given text.
 *
 * @see LookupCall#getDataByText()
 * @see LookupCall#getDataByTextInBackground(ILookupRowFetchedCallback)
 */
protected ILookupRowProvider<VALUE> newByTextLookupRowProvider(final String text) {
    return new ILookupRowProvider<VALUE>() {

        @Override
        public void beforeProvide(ILookupCall<VALUE> lookupCall) {
            prepareTextLookup(lookupCall, text);
        }

        @Override
        public void afterProvide(ILookupCall<VALUE> call, List<ILookupRow<VALUE>> result) {
            interceptFilterLookupResult(call, result);
            interceptFilterTextLookupResult(call, result);
            cleanupResultList(result);
        }

        @Override
        public void provideSync(ILookupCall<VALUE> lookupCall, ILookupRowFetchedCallback<VALUE> callback) {
            callback.onSuccess(provide(lookupCall));
        }

        @Override
        public IFuture<Void> provideAsync(ILookupCall<VALUE> lookupCall, ILookupRowFetchedCallback<VALUE> callback, ClientRunContext clientRunContext) {
            return lookupCall.getDataByTextInBackground(clientRunContext, callback);
        }

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

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

Example 23 with ILookupCall

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

the class AbstractSmartField2 method newByAllLookupRowProvider.

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

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

        @Override
        public void afterProvide(ILookupCall<VALUE> lookupCall, List<ILookupRow<VALUE>> result) {
            interceptFilterLookupResult(lookupCall, result);
            interceptFilterBrowseLookupResult(lookupCall, result);
            cleanupResultList(result);
        }

        @Override
        public void provideSync(ILookupCall<VALUE> lookupCall, ILookupRowFetchedCallback<VALUE> callback) {
            callback.onSuccess(provide(lookupCall));
        }

        @Override
        public IFuture<Void> provideAsync(ILookupCall<VALUE> lookupCall, ILookupRowFetchedCallback<VALUE> callback, ClientRunContext clientRunContext) {
            return lookupCall.getDataByAllInBackground(clientRunContext, callback);
        }

        @SuppressWarnings("unchecked")
        @Override
        public List<ILookupRow<VALUE>> provide(ILookupCall<VALUE> lookupCall) {
            return (List<ILookupRow<VALUE>>) 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) ILookupRowProvider(org.eclipse.scout.rt.client.ui.form.fields.smartfield.ILookupRowProvider) ILookupRowFetchedCallback(org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback) ToStringBuilder(org.eclipse.scout.rt.platform.util.ToStringBuilder) List(java.util.List) ArrayList(java.util.ArrayList) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall)

Example 24 with ILookupCall

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

the class AbstractMixedSmartColumnTest method testPrepareLookupCallback.

/**
 * Tests that {@link AbstractMixedSmartColumn#execPrepareLookup(ILookupCall, ITableRow)} is called when
 * {@link IMixedSmartField#prepareKeyLookup(ILookupCall, Object)} is called on the editor field.
 */
@SuppressWarnings("unchecked")
@Test
public void testPrepareLookupCallback() {
    TestMixedSmartColumn column = new TestMixedSmartColumn();
    ITableRow row = Mockito.mock(ITableRow.class);
    IMixedSmartField<String, Long> field = (IMixedSmartField<String, Long>) column.prepareEditInternal(row);
    ILookupCall call = mock(ILookupCall.class);
    field.prepareKeyLookup(call, 10L);
    assertEquals(row, column.lastRow);
    assertEquals(call, column.lastCall);
}
Also used : ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) IMixedSmartField(org.eclipse.scout.rt.client.ui.form.fields.smartfield.IMixedSmartField) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall) Test(org.junit.Test)

Example 25 with ILookupCall

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

the class AbstractProposalColumnTest method testPrepareLookupCallback.

/**
 * Tests that {@link AbstractProposalColumn#execPrepareLookup(ILookupCall, ITableRow)} is called when
 * {@link IProposalField#prepareKeyLookup(ILookupCall, Object)} is called on the editor field.
 */
@SuppressWarnings("unchecked")
@Test
public void testPrepareLookupCallback() {
    TestProposalColumn column = new TestProposalColumn();
    ITableRow row = Mockito.mock(ITableRow.class);
    IProposalField<Long> field = (IProposalField<Long>) column.prepareEditInternal(row);
    ILookupCall call = mock(ILookupCall.class);
    field.prepareKeyLookup(call, 10L);
    assertEquals(row, column.lastRow);
    assertEquals(call, column.lastCall);
}
Also used : IProposalField(org.eclipse.scout.rt.client.ui.form.fields.smartfield.IProposalField) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall) Test(org.junit.Test)

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