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.BuiltinKeys.LabelerKey;
18 import org.simantics.browsing.ui.NodeContext;
19 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
20 import org.simantics.browsing.ui.common.ColumnKeys;
21 import org.simantics.browsing.ui.content.Labeler;
22 import org.simantics.browsing.ui.content.LabelerFactory;
23 import org.simantics.db.ReadGraph;
24 import org.simantics.db.RelationContext;
25 import org.simantics.db.exception.DatabaseException;
26 import org.simantics.utils.datastructures.ArrayMap;
29 * @author Tuukka Lehtonen
31 public class RelationContextLabelerFactory implements LabelerFactory {
34 public Labeler create(PrimitiveQueryUpdater updater, final NodeContext context, LabelerKey key) {
35 assert(updater != null);
36 assert(context != null);
38 return new LazyGraphLabeler(updater, context, key) {
40 public Map<String, String> labels(ReadGraph graph) throws DatabaseException {
41 final RelationContext ctx = (RelationContext) context.getConstant(BuiltinKeys.INPUT);
42 String property = LabelerUtil.safeStringRepresentation(graph, ctx.getStatement().getPredicate());
43 //System.out.println(getClass().getName() + ": relation context: " + NameUtils.getSafeName(graph, ctx.getSubject()) + " - " + NameUtils.toString(graph, ctx.getStatement()));
44 String object = graph.getPossibleRelatedAdapter(ctx.getSubject(), ctx.getStatement().getPredicate(), String.class);
46 object = LabelerUtil.safeStringRepresentation(graph, ctx.getStatement().getObject());
47 return ArrayMap.make(ColumnKeys.KEYS_PROPERTY_VALUE, new String[] { property, object });