1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\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.jfreechart.chart.ge;
\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
24 public class SeriesLabelDecorationRule implements LabelDecorationRule {
\r
27 public boolean isCompatible(Class<?> contentType) {
\r
28 return contentType.equals(Resource.class);
\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
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
41 public String decorateLabel(String label, String column, int itemIndex) {
\r
43 for(int i = 0; i < filter.length; i++) {
\r
45 if(i < filter.length - 1)
\r
52 @SuppressWarnings("unchecked")
\r
54 public <F> F decorateFont(F font, String column, int itemIndex) {
\r
55 return (F) ((FontDescriptor) font);
\r