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.actions.newActions;
\r
14 import java.util.Collections;
\r
15 import java.util.UUID;
\r
17 import org.simantics.db.Resource;
\r
18 import org.simantics.db.WriteGraph;
\r
19 import org.simantics.db.common.request.WriteRequest;
\r
20 import org.simantics.db.common.utils.ListUtils;
\r
21 import org.simantics.db.common.utils.NameUtils;
\r
22 import org.simantics.db.exception.DatabaseException;
\r
23 import org.simantics.db.layer0.adapter.ActionFactory;
\r
24 import org.simantics.diagram.stubs.G2DResource;
\r
25 import org.simantics.layer0.Layer0;
\r
26 import org.simantics.layer0.utils.direct.GraphUtils;
\r
27 import org.simantics.sysdyn.JFreeChartResource;
\r
28 import org.simantics.ui.SimanticsUI;
\r
31 * Creates a new pie chart
\r
32 * @author Teemu Lempinen
\r
35 public class NewPieChartAction implements ActionFactory{
\r
38 public Runnable create(Object target) {
\r
39 if(!(target instanceof Resource))
\r
41 final Resource model = (Resource)target;
\r
43 return new Runnable() {
\r
47 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
\r
50 public void perform(WriteGraph graph) throws DatabaseException {
\r
51 Layer0 l0 = Layer0.getInstance(graph);
\r
52 JFreeChartResource jfree = JFreeChartResource.getInstance(graph);
\r
53 G2DResource g2d = G2DResource.getInstance(graph);
\r
56 Resource jfreechart = GraphUtils.create2(graph, jfree.Chart,
\r
57 l0.HasName, "PieChart" + UUID.randomUUID().toString(),
\r
58 l0.HasLabel, NameUtils.findFreshLabel(graph, "Pie Chart", model),
\r
60 jfree.Chart_visibleBorder, true,
\r
61 jfree.Chart_borderWidth, 3);
\r
62 graph.claimLiteral(jfreechart, jfree.Chart_borderColor, g2d.Color, new float[] {0,0,0,1});
\r
65 GraphUtils.create2(graph, jfree.TextTitle,
\r
66 l0.HasName, "TextTitle" + UUID.randomUUID().toString(),
\r
67 l0.HasLabel, "Pie Chart Title",
\r
68 jfree.Title_position, jfree.Top,
\r
69 l0.PartOf, jfreechart);
\r
72 Resource dataset = GraphUtils.create2(graph, jfree.PieDataset,
\r
73 l0.HasName, "CategoryDataset" + UUID.randomUUID().toString(),
\r
74 jfree.Dataset_seriesList, ListUtils.create(graph, Collections.<Resource>emptyList())
\r
78 GraphUtils.create2(graph, jfree.PiePlot,
\r
79 l0.HasName, "PiePlot" + UUID.randomUUID().toString(),
\r
80 l0.PartOf, jfreechart,
\r
81 l0.ConsistsOf, dataset
\r