]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
be94644aa8b4d6aed9ea486b87d1126d4ac5b458
[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.ge;\r
13 \r
14 import org.eclipse.jface.resource.FontDescriptor;\r
15 import org.simantics.browsing.ui.content.LabelDecorator;\r
16 import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;\r
17 import org.simantics.databoard.Bindings;\r
18 import org.simantics.db.ReadGraph;\r
19 import org.simantics.db.Resource;\r
20 import org.simantics.db.exception.DatabaseException;\r
21 import org.simantics.sysdyn.JFreeChartResource;\r
22 import org.simantics.ui.utils.AdaptionUtils;\r
23 \r
24 public class SeriesLabelDecorationRule implements LabelDecorationRule {\r
25 \r
26     @Override\r
27     public boolean isCompatible(Class<?> contentType) {\r
28         return contentType.equals(Resource.class);\r
29     }\r
30 \r
31     @Override\r
32     public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {\r
33         Resource resource = AdaptionUtils.adaptToSingle(content, Resource.class);\r
34         JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
35 \r
36         if (resource != null && graph.isInstanceOf(resource, jfree.Series)) {\r
37             final String[] filter = graph.getPossibleRelatedValue(resource, jfree.variableFilter, Bindings.STRING_ARRAY);\r
38             if(filter != null) {\r
39                 return new LabelDecorator.Stub() {\r
40                     @Override\r
41                     public String decorateLabel(String label, String column, int itemIndex) {\r
42                         label += " [";\r
43                         for(int i = 0; i < filter.length; i++) {\r
44                             label += filter[i];\r
45                             if(i < filter.length - 1)\r
46                                 label += ", ";\r
47                         }\r
48                         label += "]";\r
49                         return label;\r
50                     }\r
51 \r
52                     @SuppressWarnings("unchecked")\r
53                     @Override\r
54                     public <F> F decorateFont(F font, String column, int itemIndex) {\r
55                         return (F) ((FontDescriptor) font);\r
56                     }\r
57                 };\r
58             }\r
59         }\r
60         return null;\r
61     }\r
62 \r
63 }\r