1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.graph.impl;
\r
14 import java.util.function.Consumer;
\r
16 import org.simantics.browsing.ui.DataSource;
\r
17 import org.simantics.db.AsyncReadGraph;
\r
18 import org.simantics.db.AsyncRequestProcessor;
\r
19 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
\r
20 import org.simantics.db.common.request.AsyncReadRequest;
\r
21 import org.simantics.db.service.LifecycleSupport;
\r
22 import org.simantics.utils.ui.ErrorLogger;
\r
24 public class AsyncReadGraphDataSource implements DataSource<AsyncReadGraph> {
\r
26 final private AsyncRequestProcessor processor;
\r
27 final private LifecycleSupport ls;
\r
29 public AsyncReadGraphDataSource(AsyncRequestProcessor processor) {
\r
30 this.processor = processor;
\r
31 this.ls = processor.getService(LifecycleSupport.class);
\r
35 public void schedule(final Consumer<AsyncReadGraph> callback) {
\r
36 if(ls.isClosing() || ls.isClosed()) return;
\r
37 processor.asyncRequest(new AsyncReadRequest() {
\r
39 public void run(AsyncReadGraph graph) {
\r
40 if(ls.isClosing() || ls.isClosed()) return;
\r
41 callback.accept(graph);
\r
43 }, new ProcedureAdapter<Object>() {
\r
45 public void exception(Throwable t) {
\r
46 ErrorLogger.defaultLogError(t);
\r
52 public Class<AsyncReadGraph> getProvidedClass() {
\r
53 return AsyncReadGraph.class;
\r