import org.simantics.jfreechart.chart.properties.bar.BarAxisTab;\r
import org.simantics.jfreechart.chart.properties.bar.BarGeneralPropertiesTab;\r
import org.simantics.jfreechart.chart.properties.bar.BarSeriesTab;\r
+import org.simantics.jfreechart.chart.properties.bar.BarSeriesTab2;\r
import org.simantics.jfreechart.chart.properties.pie.PieGeneralPropertiesTab;\r
import org.simantics.jfreechart.chart.properties.pie.PieSeriesTab;\r
+import org.simantics.jfreechart.chart.properties.pie.PieSeriesTab2;\r
import org.simantics.jfreechart.chart.properties.xyline.XYLineAxisAndVariablesTab;\r
import org.simantics.jfreechart.chart.properties.xyline.XYLineGeneralPropertiesTab;\r
import org.simantics.layer0.Layer0;\r
}\r
return false;\r
}\r
+ \r
+ public static boolean contibuteTabs2(ReadGraph backend, Resource r, List<ComparableTabContributor> tabs) throws DatabaseException {\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(backend);\r
+ if(backend.isInstanceOf(r, jfree.ChartElement)) {\r
+ if(backend.hasStatement(r, jfree.ChartElement_component))\r
+ r = backend.getSingleObject(r, jfree.ChartElement_component);\r
+ }\r
+ \r
+ if (backend.isInstanceOf(r, jfree.Chart)) {\r
+\r
+ Collection<Resource> plots = backend.syncRequest(new ObjectsWithType(r, Layer0.getInstance(backend).ConsistsOf, jfree.Plot));\r
+ if(!plots.isEmpty()) {\r
+ Resource plot = plots.iterator().next();\r
+\r
+ if(backend.isInstanceOf(plot, jfree.XYPlot)) {\r
+ tabs.add(new ComparableTabContributor(\r
+ new XYLineGeneralPropertiesTab(),\r
+ 10,\r
+ r,\r
+ "General"));\r
+ tabs.add(new ComparableTabContributor(\r
+ new XYLineAxisAndVariablesTab(),\r
+ 9,\r
+ r,\r
+ "Axis and Variables"));\r
+ } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) {\r
+ tabs.add(new ComparableTabContributor(\r
+ new BarGeneralPropertiesTab(),\r
+ 10,\r
+ r,\r
+ "General"));\r
+ tabs.add(new ComparableTabContributor(\r
+ new BarSeriesTab2(),\r
+ 9,\r
+ r,\r
+ "Variables"));\r
+ tabs.add(new ComparableTabContributor(\r
+ new BarAxisTab(),\r
+ 8,\r
+ r,\r
+ "Axis")); \r
+ } else if(backend.isInstanceOf(plot, jfree.PiePlot)) {\r
+ tabs.add(new ComparableTabContributor(\r
+ new PieGeneralPropertiesTab(),\r
+ 10,\r
+ r,\r
+ "General"));\r
+ tabs.add(new ComparableTabContributor(\r
+ new PieSeriesTab2(),\r
+ 9,\r
+ r,\r
+ "Variables"));\r
+ }\r
+\r
+ tabs.add(new ComparableTabContributor(\r
+ new ChartTab(),\r
+ 1,\r
+ r,\r
+ "Chart"));\r
+ \r
+ return true;\r
+ } \r
+ }\r
+ return false;\r
+ }\r
}\r
--- /dev/null
+package org.simantics.jfreechart.chart.properties;\r
+\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.utils.datastructures.BijectionMap;\r
+\r
+public class VariableFactory extends ReadFactoryImpl<Resource, String> {\r
+ BijectionMap<String , String> map = new BijectionMap<String, String>();\r
+ \r
+ public VariableFactory(BijectionMap<String , String> map) {\r
+ this.map = map;\r
+ }\r
+ \r
+ @Override\r
+ public String perform(ReadGraph graph, Resource input) throws DatabaseException {\r
+ String value = graph.getPossibleRelatedValue(input, JFreeChartResource.getInstance(graph).variableRVI);\r
+ if (value == null)\r
+ return "";\r
+ value = map.getRight(value);\r
+ if (value == null)\r
+ return "";\r
+ return value;\r
+ \r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.jfreechart.chart.properties;\r
+\r
+import org.eclipse.jface.bindings.keys.KeyStroke;\r
+import org.eclipse.jface.bindings.keys.ParseException;\r
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;\r
+import org.eclipse.jface.fieldassist.IContentProposal;\r
+import org.eclipse.jface.fieldassist.IContentProposalListener;\r
+import org.eclipse.jface.fieldassist.IContentProposalListener2;\r
+import org.eclipse.jface.fieldassist.TextContentAdapter;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+\r
+public class VariableModifier extends TextModifyListenerImpl<Resource> {\r
+ \r
+ private boolean active;\r
+ private Control control;\r
+ \r
+ private char[] alphaNumericCharacters = {\r
+ 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','å','ä','ö',\r
+ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Å','Ä','Ö',\r
+ '1','2','3','4','5','6','7','8','9','0','.','_'};\r
+ \r
+ public VariableModifier(Control control, WidgetSupport support) {\r
+ this.control = control;\r
+ this.active = true;\r
+ \r
+ KeyStroke keyStroke = null;\r
+ try {\r
+ keyStroke = KeyStroke.getInstance("Ctrl+Space");\r
+ } catch (ParseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ \r
+ //SimpleContentProposalProvider scpp = new VariableProposalProvider(control, support);\r
+ IdLabelProposalProvider scpp = new VariableProposalProvider(control, support);\r
+ scpp.setFiltering(true);\r
+\r
+ ContentProposalAdapter adapter = new ContentProposalAdapter(\r
+ control, new TextContentAdapter(), scpp, keyStroke, alphaNumericCharacters);\r
+ adapter.setAutoActivationDelay(0);\r
+ adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);\r
+ adapter.addContentProposalListener(new IContentProposalListener2() {\r
+\r
+ @Override\r
+ public void proposalPopupOpened(ContentProposalAdapter adapter) {\r
+ if(VariableModifier.this != null)\r
+ VariableModifier.this.deactivate();\r
+ }\r
+\r
+ @Override\r
+ public void proposalPopupClosed(ContentProposalAdapter adapter) {\r
+ if(VariableModifier.this != null)\r
+ VariableModifier.this.activate();\r
+ }\r
+ });\r
+\r
+ adapter.addContentProposalListener(new IContentProposalListener() {\r
+\r
+ \r
+ @Override\r
+ public void proposalAccepted(IContentProposal proposal) {\r
+ if(VariableModifier.this.control != null && !VariableModifier.this.control.isDisposed())\r
+ VariableModifier.this.modifyText(new TrackedModifyEvent(VariableModifier.this.control, proposal.getContent()));\r
+ }\r
+ });\r
+ \r
+ \r
+ }\r
+ \r
+\r
+ @Override\r
+ public void applyText(WriteGraph graph, Resource resource, String text) throws DatabaseException {\r
+ if(active) {\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ graph.claimLiteral(resource, jfree.variableRVI, text, Bindings.STRING);\r
+ graph.deny(resource, jfree.variableFilter);\r
+ }\r
+ }\r
+\r
+ public void deactivate() {\r
+ active = false;\r
+ }\r
+\r
+ public void activate() {\r
+ active = true;\r
+ } \r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.jfreechart.chart.properties.bar;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.jfreechart.chart.properties.DoubleValidator;\r
+import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;\r
+import org.simantics.jfreechart.chart.properties.RVIFactory;\r
+import org.simantics.jfreechart.chart.properties.RVIModifier;\r
+import org.simantics.jfreechart.chart.properties.RangeComposite;\r
+import org.simantics.jfreechart.chart.properties.VariableExistsValidator;\r
+import org.simantics.jfreechart.chart.properties.VariableFactory;\r
+import org.simantics.jfreechart.chart.properties.VariableModifier;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ui.chart.property.DoublePropertyFactory;\r
+import org.simantics.modeling.ui.chart.property.DoublePropertyModifier;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.utils.datastructures.BijectionMap;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+/**\r
+ * Composite for modifying properties of a series in a bar chart\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class BarSeriesPropertyComposite2 extends Composite {\r
+ \r
+ private TrackedText variable, label, time;\r
+ \r
+ public BarSeriesPropertyComposite2(Composite parent, final ISessionContext context, WidgetSupport support, Pair<String[],String[]> variables, int style) {\r
+ super(parent, style);\r
+ \r
+ GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this);\r
+\r
+ // Variable for the series\r
+ Label label = new Label(this, SWT.NONE);\r
+ label.setText("Variable:");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+\r
+ variable = new TrackedText(this, support, SWT.BORDER);\r
+ if (variables.second == null) {\r
+ variable.setTextFactory(new RVIFactory());\r
+ variable.addModifyListener(new RVIModifier(variable.getWidget(), support));\r
+ variable.setInputValidator(new VariableExistsValidator(support, variable));\r
+ } else {\r
+ // FIXME: using bijectionmap and trackedText looses the variables that have the same label.\r
+ BijectionMap<String , String> map = new BijectionMap<String, String>();\r
+ for (int i = 0; i < variables.first.length; i++) {\r
+ map.map(variables.first[i], variables.second[i]);\r
+ }\r
+ variable.setTextFactory(new VariableFactory(map));\r
+ variable.addModifyListener(new VariableModifier(variable.getWidget(), support));\r
+ variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));\r
+ }\r
+ variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager()));\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget());\r
+\r
+ // Range\r
+ label = new Label(this, SWT.NONE);\r
+ label.setText("Range:");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+ \r
+ RangeComposite rangeComposite = new RangeComposite(this, context, support, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeComposite);\r
+ \r
+ \r
+ // Label to be displayed in chart for this series\r
+ label = new Label(this, SWT.NONE);\r
+ label.setText("Label:");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+\r
+ this.label = new TrackedText(this, support, SWT.BORDER);\r
+ this.label.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, ""));\r
+ this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
+ this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager()));\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget());\r
+ \r
+ // Time\r
+ label = new Label(this, SWT.NONE);\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+ label.setText("Time:");\r
+ \r
+ Composite composite = new Composite(this, SWT.NONE);\r
+ GridDataFactory.fillDefaults().applyTo(composite);\r
+ GridLayoutFactory.fillDefaults().applyTo(composite);\r
+ \r
+ time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER);\r
+ time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time));\r
+ time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time));\r
+ time.setInputValidator(new DoubleValidator(true));\r
+ time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));\r
+ GridDataFactory.fillDefaults().applyTo(time.getWidget());\r
+ }\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.jfreechart.chart.properties.bar;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.ScrolledComposite;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.graphics.Point;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
+import org.simantics.browsing.ui.swt.widgets.Button;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
+import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.PossibleObjectWithType;\r
+import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.jfreechart.chart.ChartUtils;\r
+import org.simantics.jfreechart.chart.properties.AllVariablesOfModel;\r
+import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;\r
+import org.simantics.jfreechart.chart.properties.xyline.AxisAndVariablesExplorerComposite;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
+import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+\r
+/**\r
+ * Tab containing the series of a bar chart\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class BarSeriesTab2 extends LabelPropertyTabContributor implements Widget {\r
+\r
+ private GraphExplorerComposite explorer;\r
+ private ScrolledComposite propertyContainer;\r
+ private WidgetSupportImpl additionalSupport;\r
+ private Button add, remove;\r
+ private Resource chartResource;\r
+ private BarSeriesPropertyComposite2 spc;\r
+\r
+\r
+ public BarSeriesTab2() {\r
+ additionalSupport = new WidgetSupportImpl();\r
+ }\r
+\r
+ @Override\r
+ public void createControls(Composite body, IWorkbenchSite site, final ISessionContext context, WidgetSupport support) {\r
+ support.register(this);\r
+ Composite composite = new Composite(body, SWT.NONE);\r
+ \r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
+ GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite);\r
+\r
+ // (Ontology-based) GraphExplorer displaying variables in a bar chart\r
+ explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys(\r
+ "displaySelectors", "displayFilter").values(false, false), site, composite, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE);\r
+ explorer.setBrowseContexts(JFreeChartResource.URIs.BarSeriesBrowseContext);\r
+ explorer.setInputSource(new SingleSelectionInputSource(\r
+ Resource.class));\r
+ explorer.getExplorer().setAutoExpandLevel(2); // Expand everything in the beginning\r
+ explorer.finish();\r
+\r
+ ((Tree)explorer.getExplorerControl()).addSelectionListener(new SelectionAdapter() {\r
+ public void widgetSelected(SelectionEvent e) {\r
+ updateSelection(context);\r
+ }\r
+ });\r
+ GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer);\r
+\r
+ // Scrolled composite for displaying properties of a selection in explorer\r
+ propertyContainer = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);\r
+ GridDataFactory.fillDefaults().span(1, 2).grab(true, true).applyTo(propertyContainer);\r
+ GridLayoutFactory.fillDefaults().applyTo(propertyContainer);\r
+ propertyContainer.setExpandHorizontal(true);\r
+ propertyContainer.setExpandVertical(true);\r
+\r
+ // Buttons for adding and removing variables from a pie plot\r
+ Composite buttonComposite = new Composite(composite, SWT.NONE);\r
+ GridDataFactory.fillDefaults().applyTo(buttonComposite);\r
+ GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite);\r
+\r
+ add = new Button(buttonComposite, additionalSupport, SWT.NONE);\r
+ add.setText("Add");\r
+ add.addSelectionListener(new NewVariableListener(context));\r
+\r
+ remove = new Button(buttonComposite, additionalSupport, SWT.NONE);\r
+ remove.setText("Remove");\r
+ remove.addSelectionListener(new RemoveListener(context));\r
+ }\r
+\r
+ /**\r
+ * Updates the content of propertyContainer \r
+ * @param context\r
+ */\r
+ private void updateSelection(ISessionContext context) {\r
+ ISelectionProvider selectionProvider = (ISelectionProvider)explorer.getAdapter(ISelectionProvider.class);\r
+ IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection();\r
+ final Resource resource = AdaptionUtils.adaptToSingle(selection, Resource.class);\r
+ if(resource == null)\r
+ return;\r
+ \r
+ for(Control child : propertyContainer.getChildren()) {\r
+ child.dispose();\r
+ }\r
+ \r
+ try {\r
+ Pair<String[],String[]> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
+ \r
+ spc = new BarSeriesPropertyComposite2(propertyContainer, context, additionalSupport, variables, SWT.NONE);\r
+ \r
+ additionalSupport.fireInput(context, selection);\r
+ \r
+ propertyContainer.setContent(spc);\r
+ Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
+ propertyContainer.setMinSize(size);\r
+ } catch (DatabaseException e) {\r
+ ExceptionUtils.logAndShowError(e);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * SelectionListener for adding a new variable to a plot\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+ private class NewVariableListener extends SelectionListenerImpl<Resource> {\r
+\r
+ public NewVariableListener(ISessionContext context) {\r
+ super(context);\r
+ }\r
+\r
+ @Override\r
+ public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
+ Resource dataset = null;\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+ if(input == null) {\r
+ if(chartResource != null) {\r
+ Resource plot = graph.syncRequest(new PossibleObjectWithType(chartResource, l0.ConsistsOf, jfree.Plot));\r
+ if(plot != null)\r
+ dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset));\r
+ }\r
+ } else {\r
+ if(graph.isInstanceOf(input, jfree.Series)) {\r
+ dataset = graph.getPossibleObject(input, l0.PartOf);\r
+ }\r
+ }\r
+\r
+ if(dataset != null) {\r
+ // Create series with no rvi\r
+ ChartUtils.createSeries(graph, dataset, null);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * SelectionListener for remove button\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+ private class RemoveListener extends SelectionListenerImpl<Resource> {\r
+\r
+ public RemoveListener(ISessionContext context) {\r
+ super(context);\r
+ }\r
+\r
+ /**\r
+ * Removes selected resource from explorer\r
+ */\r
+ @Override\r
+ public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
+ if(input == null)\r
+ return; \r
+\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource list = null;\r
+ if(graph.isInstanceOf(input, jfree.Series)) {\r
+ // Remove series from dataset and seriesList\r
+ Resource dataset = graph.getPossibleObject(input, l0.PartOf);\r
+ if(dataset != null)\r
+ list = graph.getPossibleObject(dataset, jfree.Dataset_seriesList);\r
+\r
+ if(list != null)\r
+ ListUtils.removeElement(graph, list, input);\r
+ RemoverUtil.remove(graph, input);\r
+ }\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void setInput(ISessionContext context, Object input) {\r
+ chartResource = AdaptionUtils.adaptToSingle(input, Resource.class);\r
+ }\r
+\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.jfreechart.chart.properties.pie;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.simantics.browsing.ui.swt.widgets.Button;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.jfreechart.chart.properties.BooleanPropertyFactory;\r
+import org.simantics.jfreechart.chart.properties.BooleanSelectionListener;\r
+import org.simantics.jfreechart.chart.properties.ColorPicker;\r
+import org.simantics.jfreechart.chart.properties.DoubleValidator;\r
+import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;\r
+import org.simantics.jfreechart.chart.properties.RVIFactory;\r
+import org.simantics.jfreechart.chart.properties.RVIModifier;\r
+import org.simantics.jfreechart.chart.properties.RangeComposite;\r
+import org.simantics.jfreechart.chart.properties.VariableExistsValidator;\r
+import org.simantics.jfreechart.chart.properties.VariableFactory;\r
+import org.simantics.jfreechart.chart.properties.VariableModifier;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ui.chart.property.DoublePropertyFactory;\r
+import org.simantics.modeling.ui.chart.property.DoublePropertyModifier;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.utils.datastructures.BijectionMap;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+/**\r
+ * Composite containing the properties of a series\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class PieSeriesPropertyComposite2 extends Composite {\r
+ \r
+ private TrackedText variable, label, time;\r
+ \r
+ public PieSeriesPropertyComposite2(Composite parent, ISessionContext context, WidgetSupport support, Pair<String[],String[]> variables,int style) {\r
+ super(parent, style);\r
+ \r
+ GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this);\r
+\r
+ // Variable for the series\r
+ Label label = new Label(this, SWT.NONE);\r
+ label.setText("Variable:");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+\r
+ variable = new TrackedText(this, support, SWT.BORDER);\r
+ if (variables.second == null) {\r
+ variable.setTextFactory(new RVIFactory());\r
+ variable.addModifyListener(new RVIModifier(variable.getWidget(), support));\r
+ variable.setInputValidator(new VariableExistsValidator(support, variable));\r
+ } else {\r
+ // FIXME: using bijectionmap and trackedText looses the variables that have the same label.\r
+ BijectionMap<String , String> map = new BijectionMap<String, String>();\r
+ for (int i = 0; i < variables.first.length; i++) {\r
+ map.map(variables.first[i], variables.second[i]);\r
+ }\r
+ variable.setTextFactory(new VariableFactory(map));\r
+ variable.addModifyListener(new VariableModifier(variable.getWidget(), support));\r
+ variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));\r
+ }\r
+ variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager()));\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget());\r
+\r
+ // Range\r
+ label = new Label(this, SWT.NONE);\r
+ label.setText("Range:");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+ \r
+ RangeComposite rangeComposite = new RangeComposite(this, context, support, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeComposite);\r
+ \r
+ \r
+ // Label to be displayed in chart for this series\r
+ label = new Label(this, SWT.NONE);\r
+ label.setText("Label:");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+\r
+ this.label = new TrackedText(this, support, SWT.BORDER);\r
+ this.label.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, ""));\r
+ this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
+ this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager()));\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget());\r
+\r
+ // Color\r
+ label = new Label(this, SWT.NONE);\r
+ label.setText("Color:");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+\r
+ Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker);\r
+\r
+ // Time\r
+ label = new Label(this, SWT.NONE);\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+ label.setText("Time:");\r
+ \r
+ Composite composite = new Composite(this, SWT.NONE);\r
+ GridDataFactory.fillDefaults().applyTo(composite);\r
+ GridLayoutFactory.fillDefaults().applyTo(composite);\r
+ \r
+ time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER);\r
+ time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time));\r
+ time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time));\r
+ time.setInputValidator(new DoubleValidator(true));\r
+ time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));\r
+ GridDataFactory.fillDefaults().applyTo(time.getWidget());\r
+ \r
+ // Exploded\r
+ label = new Label(this, SWT.NONE);\r
+ label.setText("");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+ \r
+ Button exploded = new Button(this, support, SWT.CHECK);\r
+ exploded.setText("Exploded");\r
+ exploded.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Series_exploded));\r
+ exploded.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Series_exploded));\r
+ GridDataFactory.fillDefaults().applyTo(exploded.getWidget());\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.jfreechart.chart.properties.pie;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.ScrolledComposite;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.graphics.Point;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
+import org.simantics.browsing.ui.swt.widgets.Button;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
+import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.PossibleObjectWithType;\r
+import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.jfreechart.chart.ChartUtils;\r
+import org.simantics.jfreechart.chart.properties.AllVariablesOfModel;\r
+import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;\r
+import org.simantics.jfreechart.chart.properties.xyline.AxisAndVariablesExplorerComposite;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
+import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+\r
+/**\r
+ * Tab for modifying series in a pie chart configuration\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class PieSeriesTab2 extends LabelPropertyTabContributor implements Widget {\r
+\r
+ private GraphExplorerComposite explorer;\r
+ private ScrolledComposite propertyContainer;\r
+ private WidgetSupportImpl additionalSupport;\r
+ private Button add, remove;\r
+ private Resource chartResource;\r
+\r
+ public PieSeriesTab2() {\r
+ additionalSupport = new WidgetSupportImpl();\r
+ }\r
+\r
+ @Override\r
+ public void createControls(Composite body, IWorkbenchSite site, final ISessionContext context, WidgetSupport support) {\r
+ support.register(this);\r
+ Composite composite = new Composite(body, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
+ GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite);\r
+\r
+ // (Ontology-based) GraphExplorer displaying variables of a pie chart\r
+ explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys(\r
+ "displaySelectors", "displayFilter").values(false, false), site, composite, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE);\r
+ explorer.setBrowseContexts(JFreeChartResource.URIs.PieSeriesBrowseContext);\r
+ explorer.setInputSource(new SingleSelectionInputSource(\r
+ Resource.class));\r
+ explorer.getExplorer().setAutoExpandLevel(2); // Expand everything in the beginning\r
+ explorer.finish();\r
+\r
+ ((Tree)explorer.getExplorerControl()).addSelectionListener(new SelectionAdapter() {\r
+ public void widgetSelected(SelectionEvent e) {\r
+ updateSelection(context);\r
+ }\r
+ });\r
+ GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer);\r
+\r
+ // Scrolled composite for displaying properties of a selection in explorer\r
+ propertyContainer = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);\r
+ GridDataFactory.fillDefaults().span(1, 2).grab(true, true).applyTo(propertyContainer);\r
+ GridLayoutFactory.fillDefaults().applyTo(propertyContainer);\r
+ propertyContainer.setExpandHorizontal(true);\r
+ propertyContainer.setExpandVertical(true);\r
+\r
+\r
+ // Buttons for adding and removing variables from a pie plot\r
+ Composite buttonComposite = new Composite(composite, SWT.NONE);\r
+ GridDataFactory.fillDefaults().applyTo(buttonComposite);\r
+ GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite);\r
+\r
+ add = new Button(buttonComposite, additionalSupport, SWT.NONE);\r
+ add.setText("Add");\r
+ add.addSelectionListener(new NewVariableListener(context));\r
+\r
+ remove = new Button(buttonComposite, additionalSupport, SWT.NONE);\r
+ remove.setText("Remove");\r
+ remove.addSelectionListener(new RemoveListener(context));\r
+ }\r
+\r
+ /**\r
+ * Updates the content of propertyContainer \r
+ * @param context\r
+ */\r
+ private void updateSelection(ISessionContext context) {\r
+ ISelectionProvider selectionProvider = (ISelectionProvider)explorer.getAdapter(ISelectionProvider.class);\r
+ IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection();\r
+ final Resource resource = AdaptionUtils.adaptToSingle(selection, Resource.class);\r
+ if(resource == null)\r
+ return;\r
+\r
+ for(Control child : propertyContainer.getChildren()) {\r
+ child.dispose();\r
+ }\r
+\r
+ try {\r
+ Pair<String[],String[]> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
+ PieSeriesPropertyComposite2 spc = new PieSeriesPropertyComposite2(propertyContainer, context, additionalSupport, variables, SWT.NONE);\r
+ propertyContainer.setContent(spc);\r
+ Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
+ propertyContainer.setMinSize(size);\r
+ \r
+ additionalSupport.fireInput(context, selection);\r
+ } catch (DatabaseException e) {\r
+ ExceptionUtils.logAndShowError(e);\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
+ * SelectionListener for adding a new variable to a plot\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+ private class NewVariableListener extends SelectionListenerImpl<Resource> {\r
+\r
+ public NewVariableListener(ISessionContext context) {\r
+ super(context);\r
+ }\r
+\r
+ @Override\r
+ public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource dataset = null;\r
+ if(input == null) {\r
+ if(chartResource != null) {\r
+ Resource plot = graph.syncRequest(new PossibleObjectWithType(chartResource, l0.ConsistsOf, jfree.Plot));\r
+ if(plot != null)\r
+ dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset));\r
+ }\r
+ } else {\r
+ if(graph.isInstanceOf(input, jfree.Series)) {\r
+ dataset = graph.getPossibleObject(input, l0.PartOf);\r
+ }\r
+ }\r
+ if(dataset != null) {\r
+ // Create series with no rvi\r
+ Resource series = ChartUtils.createSeries(graph, dataset, null);\r
+ graph.claimLiteral(series, jfree.Series_exploded, false);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * SelectionListener for remove button\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+ private class RemoveListener extends SelectionListenerImpl<Resource> {\r
+\r
+ public RemoveListener(ISessionContext context) {\r
+ super(context);\r
+ }\r
+\r
+ /**\r
+ * Removes selected resource from explorer\r
+ */\r
+ @Override\r
+ public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
+ if(input == null)\r
+ return; \r
+\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource list = null;\r
+ if(graph.isInstanceOf(input, jfree.Series)) {\r
+ // Remove series from dataset and seriesList\r
+ Resource dataset = graph.getPossibleObject(input, l0.PartOf);\r
+ if(dataset != null)\r
+ list = graph.getPossibleObject(dataset, jfree.Dataset_seriesList);\r
+\r
+ if(list != null)\r
+ ListUtils.removeElement(graph, list, input);\r
+ RemoverUtil.remove(graph, input);\r
+ }\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public void setInput(ISessionContext context, Object input) {\r
+ chartResource = AdaptionUtils.adaptToSingle(input, Resource.class);\r
+ }\r
+\r
+}\r