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