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 org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.utils.NameUtils;
17 import org.simantics.db.exception.AdaptionException;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.layer0.utils.representation.StringRepresentation2;
20 import org.simantics.utils.datastructures.slice.ValueRange;
23 * @author Tuukka Lehtonen
25 public final class LabelerUtil {
32 public static String safeStringRepresentation(ReadGraph g, Resource r) throws DatabaseException {
34 String rep = g.adapt(r, String.class);
36 } catch (AdaptionException e) {
37 return "<no string representation: " + e.getMessage() + ">";
38 } catch (DatabaseException e) {
39 return NameUtils.getSafeName(g, r);
49 public static String safeStringRepresentation(ReadGraph g, Resource r, int index) throws DatabaseException {
51 StringRepresentation2 rep = g.adapt(r, StringRepresentation2.class);
52 return rep.get(g, index);
53 } catch (AdaptionException e) {
54 return "<no string representation: " + e.getMessage() + ">";
64 public static String safeStringRepresentation(ReadGraph g, Resource r, ValueRange range) throws DatabaseException {
66 StringRepresentation2 rep = g.adapt(r, StringRepresentation2.class);
67 return rep.get(g, range.start(), range.size());
68 } catch (AdaptionException e) {
69 return "<no string representation: " + e.getMessage() + ">";