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.sysdyn.ui.trend.chart.graphexplorer;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\r
17 import org.simantics.browsing.ui.model.children.ChildRule;
\r
18 import org.simantics.db.ReadGraph;
\r
19 import org.simantics.db.Resource;
\r
20 import org.simantics.db.common.request.ObjectsWithType;
\r
21 import org.simantics.db.common.utils.ListUtils;
\r
22 import org.simantics.db.exception.DatabaseException;
\r
23 import org.simantics.layer0.Layer0;
\r
24 import org.simantics.sysdyn.JFreeChartResource;
\r
27 * ChildRule for finding the series of an axis
\r
29 * @author Teemu Lempinen
\r
32 public class VariableChildRule implements ChildRule {
\r
35 public boolean isCompatible(Class<?> contentType) {
\r
36 return contentType.equals(Resource.class);
\r
40 public Collection<?> getChildren(ReadGraph graph, Object parent) throws DatabaseException {
\r
41 ArrayList<Resource> result = new ArrayList<Resource>();
\r
42 if(!(parent instanceof Resource))
\r
44 JFreeChartResource jfree = JFreeChartResource.getInstance(graph);
\r
45 Layer0 l0 = Layer0.getInstance(graph);
\r
46 Resource axis = (Resource)parent;
\r
48 * 1. Axis belongs to a plot
\r
49 * 2. Plot may have multiple datasets
\r
50 * 3. Dataset is mapped to a single range axis
\r
51 * 3. Dataset may have multiple seires
\r
53 Resource plot = graph.getPossibleObject(axis, jfree.Plot_rangeAxis_Inverse);
\r
57 for(Resource dataset : graph.syncRequest(new ObjectsWithType(plot, l0.ConsistsOf, jfree.Dataset))) {
\r
58 if(graph.hasStatement(dataset, jfree.Dataset_mapToRangeAxis, axis)) {
\r
59 Resource seriesList = graph.getPossibleObject(dataset, jfree.Dataset_seriesList);
\r
60 if(seriesList != null)
\r
61 for(Resource series : ListUtils.toList(graph, seriesList)) {
\r
70 public Collection<?> getParents(ReadGraph graph, Object child) throws DatabaseException {
\r
71 return new ArrayList<Resource>();
\r