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;
32 public class StringRepresentationLabelerFactory implements LabelerFactory {
34 String column = ColumnKeys.SINGLE;
36 //static int counter = 0;
38 public StringRepresentationLabelerFactory() {
41 public StringRepresentationLabelerFactory(String column) {
46 public Labeler create(PrimitiveQueryUpdater updater, final NodeContext context, LabelerKey key) {
47 assert(updater != null);
48 assert(context != null);
50 return new LazyGraphLabeler(updater, context, key) {
52 public Map<String, String> labels(ReadGraph graph) throws DatabaseException {
53 // if((counter++ % 5000) == 0) System.out.println("L" + counter);
54 final Resource r = (Resource) context.getConstant(BuiltinKeys.INPUT);
55 String representation = LabelerUtil.safeStringRepresentation(graph, r);
56 return Collections.singletonMap(column, representation);
59 public Modifier getModifier(ModificationContext modificationContext, String key) {
60 ISessionContext session = Simantics.getSessionContext();
64 if (column.equals(key)) {
65 return new GraphStringModifier(context, session.getSession()) {
67 public void doModify(WriteGraph graph, String label) throws DatabaseException {
68 getModifier().modify(graph, label);
71 public String createModifierInput(String fromLabel) {