Search in sources :

Example 11 with ILookupRow

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;
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) BatchLookupResultCache(org.eclipse.scout.rt.shared.services.lookup.BatchLookupResultCache) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall)

Example 12 with ILookupRow

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;
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) ArrayList(java.util.ArrayList) ThreadInterruptedError(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) ClientRunContext(org.eclipse.scout.rt.client.context.ClientRunContext) FutureCancelledError(org.eclipse.scout.rt.platform.util.concurrent.FutureCancelledError) ILookupRowFetchedCallback(org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback) List(java.util.List) ArrayList(java.util.ArrayList)

Example 13 with ILookupRow

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();
        }
    };
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) ClientRunContext(org.eclipse.scout.rt.client.context.ClientRunContext) 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 14 with ILookupRow

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;
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) HashMap(java.util.HashMap) ITreeVisitor(org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)

Example 15 with ILookupRow

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));
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Aggregations

ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)36 ArrayList (java.util.ArrayList)29 List (java.util.List)24 ILookupCall (org.eclipse.scout.rt.shared.services.lookup.ILookupCall)19 BatchLookupResultCache (org.eclipse.scout.rt.shared.services.lookup.BatchLookupResultCache)10 ILookupRowFetchedCallback (org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback)10 ClientRunContext (org.eclipse.scout.rt.client.context.ClientRunContext)9 ToStringBuilder (org.eclipse.scout.rt.platform.util.ToStringBuilder)8 Test (org.junit.Test)7 BatchLookupCall (org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall)6 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)5 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)4 ILookupRowProvider (org.eclipse.scout.rt.client.ui.form.fields.smartfield.ILookupRowProvider)4 EventListenerList (org.eclipse.scout.rt.platform.util.EventListenerList)4 LookupRow (org.eclipse.scout.rt.shared.services.lookup.LookupRow)4 HashMap (java.util.HashMap)3 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)3 ITreeVisitor (org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)3 Pattern (java.util.regex.Pattern)2 IBatchLookupService (org.eclipse.scout.rt.shared.services.lookup.IBatchLookupService)2