1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 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.sysdyn.ui.browser.imagerules;
\r
14 import java.util.Collections;
\r
15 import java.util.Map;
\r
17 import org.eclipse.jface.resource.ImageDescriptor;
\r
18 import org.simantics.browsing.ui.common.ColumnKeys;
\r
19 import org.simantics.browsing.ui.model.images.ImageRule;
\r
20 import org.simantics.db.ReadGraph;
\r
21 import org.simantics.db.Resource;
\r
22 import org.simantics.db.common.request.PossibleObjectWithType;
\r
23 import org.simantics.db.exception.DatabaseException;
\r
24 import org.simantics.layer0.Layer0;
\r
25 import org.simantics.sysdyn.JFreeChartResource;
\r
26 import org.simantics.sysdyn.ui.Activator;
\r
28 public class ChartImageRule implements ImageRule {
\r
31 public boolean isCompatible(Class<?> contentType) {
\r
32 return Resource.class.equals(contentType);
\r
36 public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
\r
37 Layer0 l0 = Layer0.getInstance(graph);
\r
38 JFreeChartResource jfree = JFreeChartResource.getInstance(graph);
\r
40 String image = "icons/chart_line.png";
\r
42 Resource chart = (Resource) content;
\r
44 Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.Plot));
\r
46 if(graph.isInstanceOf(plot, jfree.CategoryPlot)) {
\r
47 image = "icons/chart_bar.png";
\r
48 } else if(graph.isInstanceOf(plot, jfree.PiePlot)) {
\r
49 image = "icons/chart_pie.png";
\r
53 return Collections.singletonMap(ColumnKeys.SINGLE,
\r
54 ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource(image))
\r