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.Collections;
17 import org.simantics.Simantics;
18 import org.simantics.browsing.ui.BuiltinKeys;
19 import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;
20 import org.simantics.browsing.ui.GraphExplorer.ModificationContext;
21 import org.simantics.browsing.ui.NodeContext;
22 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
23 import org.simantics.browsing.ui.common.ColumnKeys;
24 import org.simantics.browsing.ui.content.Labeler;
25 import org.simantics.browsing.ui.content.LabelerFactory;
26 import org.simantics.db.ReadGraph;
27 import org.simantics.db.Resource;
28 import org.simantics.db.WriteGraph;
29 import org.simantics.db.exception.DatabaseException;
30 import org.simantics.db.management.ISessionContext;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class StringRepresentationLabelerFactory implements LabelerFactory {
36 String column = ColumnKeys.SINGLE;
38 //static int counter = 0;
40 public StringRepresentationLabelerFactory() {
43 public StringRepresentationLabelerFactory(String column) {
48 public Labeler create(PrimitiveQueryUpdater updater, final NodeContext context, LabelerKey key) {
49 assert(updater != null);
50 assert(context != null);
52 return new LazyGraphLabeler(updater, context, key) {
54 public Map<String, String> labels(ReadGraph graph) throws DatabaseException {
55 // if((counter++ % 5000) == 0) System.out.println("L" + counter);
56 final Resource r = (Resource) context.getConstant(BuiltinKeys.INPUT);
57 String representation = LabelerUtil.safeStringRepresentation(graph, r);
58 return Collections.singletonMap(column, representation);
61 public Modifier getModifier(ModificationContext modificationContext, String key) {
62 ISessionContext session = Simantics.getSessionContext();
66 if (column.equals(key)) {
67 return new GraphStringModifier(context, session.getSession()) {
69 public void doModify(WriteGraph graph, String label) throws DatabaseException {
70 getModifier().modify(graph, label);
73 public String createModifierInput(String fromLabel) {
82 public Logger getLogger() {
83 return LoggerFactory.getLogger(StringRepresentationLabelerFactory.class);