1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
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.modeling.ui.chart.property;
14 import java.text.Format;
16 import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.utils.datastructures.Triple;
21 import org.simantics.utils.format.TimeFormat;
24 * @author Toni Kalajainen
26 public class TimePropertyFactory extends ReadFactoryImpl<Resource, String> {
28 final private String propertyURI;
30 public TimePropertyFactory(String propertyURI) {
31 this.propertyURI = propertyURI;
35 public Object getIdentity(Object inputContents) {
36 return new Triple<Resource, String, Object>((Resource) inputContents, propertyURI, getClass());
40 public String perform(ReadGraph graph, Resource r) throws DatabaseException {
41 Double value = graph.getPossibleRelatedAdapter(r, graph.getResource(propertyURI), Double.class);
42 if (value == null) return "";
43 Format timeFormat = new TimeFormat(100, 3);
44 return timeFormat.format(value);