]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
c02b3a58d7e298062fdeb46050992b914b50343d
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * 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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.jfreechart.chart.properties;\r
13 \r
14 import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
15 import org.simantics.databoard.Bindings;\r
16 import org.simantics.db.ReadGraph;\r
17 import org.simantics.db.Resource;\r
18 import org.simantics.db.common.request.PossibleObjectWithType;\r
19 import org.simantics.db.exception.DatabaseException;\r
20 import org.simantics.layer0.Layer0;\r
21 import org.simantics.sysdyn.JFreeChartResource;\r
22 \r
23 /**\r
24  * TextFactory for chart title\r
25  * @author Teemu Lempinen\r
26  *\r
27  */\r
28 public class TitleFactory extends ReadFactoryImpl<Resource, String>   {\r
29     @Override\r
30     public String perform(ReadGraph graph, Resource chart) throws DatabaseException {\r
31         Layer0 l0 = Layer0.getInstance(graph);\r
32         JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
33         Resource title = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.TextTitle));\r
34         if(title == null)\r
35             return "";\r
36         else {\r
37             String label = graph.getPossibleRelatedValue(title, l0.HasLabel, Bindings.STRING);\r
38             return label == null ? "" : label;\r
39         }\r
40     }\r
41 }