]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/TimePropertyFactory.java
Externalize strings
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / chart / property / TimePropertyFactory.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.ui.chart.property;
13
14 import java.text.Format;
15
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;
22
23 /**
24  * @author Toni Kalajainen
25  */
26 public class TimePropertyFactory extends ReadFactoryImpl<Resource, String> {
27
28     final private String propertyURI;
29
30     public TimePropertyFactory(String propertyURI) {
31         this.propertyURI = propertyURI;
32     }
33
34     @Override
35     public Object getIdentity(Object inputContents) {
36         return new Triple<Resource, String, Object>((Resource) inputContents, propertyURI, getClass());
37     }
38
39     @Override
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 ""; //$NON-NLS-1$
43         Format timeFormat = new TimeFormat(100, 3);
44         return timeFormat.format(value);
45     }
46
47 }