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;
16 import org.simantics.browsing.ui.BuiltinKeys;
17 import org.simantics.browsing.ui.DataSource;
18 import org.simantics.browsing.ui.NodeContext;
19 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
20 import org.simantics.browsing.ui.common.labelers.LabelerContent;
21 import org.simantics.browsing.ui.common.labelers.LabelerStub;
22 import org.simantics.browsing.ui.graph.impl.request.ParametrizedResourceQuery;
23 import org.simantics.db.ReadGraph;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.db.procedure.Listener;
28 * A version of LazyLabeler that uses a set of arbitrary parameters to describe
29 * the label resource query within the class.
31 * @author Tuukka Lehtonen
33 * @see LazyGraphLabeler a non-parametrized version (more light-weight)
35 public abstract class LazyParametrizedGraphLabeler extends LabelerStub {
37 private final ParametrizedResourceQuery<LabelerContent> labelQuery;
38 private final Listener<LabelerContent> labelProcedure;
39 private final PrimitiveQueryUpdater updater;
42 static int debugCounter = 0;
44 public LazyParametrizedGraphLabeler(final PrimitiveQueryUpdater updater, final NodeContext context, final BuiltinKeys.LabelerKey key, Object... parameters) {
45 this.updater = updater;
46 this.labelQuery = new ParametrizedResourceQuery<LabelerContent>(getClass(), context, parameters) {
48 public LabelerContent perform(ReadGraph graph) throws DatabaseException {
49 return new LabelerContent(category(graph), labels(graph));
53 this.labelProcedure = new Listener<LabelerContent>() {
56 public void execute(LabelerContent result) {
58 updater.scheduleReplace(context, key, LazyParametrizedGraphLabeler.this);
62 public void exception(Throwable t) {
67 public boolean isDisposed() {
68 return updater.isDisposed();
75 public Map<String, String> getLabels() {
76 // new Exception().printStackTrace();
77 if (content == LabelerContent.NO_CONTENT) {
78 final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
80 source.schedule(graph -> {
82 graph.syncRequest(labelQuery, labelProcedure);
83 } catch (DatabaseException e) {
89 return content.labels;
94 public abstract Map<String, String> labels(ReadGraph graph) throws DatabaseException;
96 public int category(ReadGraph graph) {
97 return content.category;