1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.graph.impl;
\r
14 import org.simantics.db.ReadGraph;
\r
15 import org.simantics.db.Resource;
\r
16 import org.simantics.db.common.utils.NameUtils;
\r
17 import org.simantics.db.exception.AdaptionException;
\r
18 import org.simantics.db.exception.DatabaseException;
\r
19 import org.simantics.layer0.utils.representation.StringRepresentation2;
\r
20 import org.simantics.utils.datastructures.slice.ValueRange;
\r
23 * @author Tuukka Lehtonen
\r
25 public final class LabelerUtil {
\r
32 public static String safeStringRepresentation(ReadGraph g, Resource r) throws DatabaseException {
\r
34 String rep = g.adapt(r, String.class);
\r
36 } catch (AdaptionException e) {
\r
37 return "<no string representation: " + e.getMessage() + ">";
\r
38 } catch (DatabaseException e) {
\r
39 return NameUtils.getSafeName(g, r);
\r
49 public static String safeStringRepresentation(ReadGraph g, Resource r, int index) throws DatabaseException {
\r
51 StringRepresentation2 rep = g.adapt(r, StringRepresentation2.class);
\r
52 return rep.get(g, index);
\r
53 } catch (AdaptionException e) {
\r
54 return "<no string representation: " + e.getMessage() + ">";
\r
64 public static String safeStringRepresentation(ReadGraph g, Resource r, ValueRange range) throws DatabaseException {
\r
66 StringRepresentation2 rep = g.adapt(r, StringRepresentation2.class);
\r
67 return rep.get(g, range.start(), range.size());
\r
68 } catch (AdaptionException e) {
\r
69 return "<no string representation: " + e.getMessage() + ">";
\r