1 /*******************************************************************************
\r
2 * Copyright (c) 2013, 2014 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 * Semantum Oy - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.trend;
\r
14 import org.eclipse.jface.layout.GridDataFactory;
\r
15 import org.eclipse.jface.layout.GridLayoutFactory;
\r
16 import org.eclipse.jface.viewers.ISelectionProvider;
\r
17 import org.eclipse.jface.viewers.IStructuredSelection;
\r
18 import org.eclipse.swt.SWT;
\r
19 import org.eclipse.swt.custom.ScrolledComposite;
\r
20 import org.eclipse.swt.events.SelectionAdapter;
\r
21 import org.eclipse.swt.events.SelectionEvent;
\r
22 import org.eclipse.swt.graphics.Point;
\r
23 import org.eclipse.swt.widgets.Composite;
\r
24 import org.eclipse.swt.widgets.Control;
\r
25 import org.eclipse.swt.widgets.Tree;
\r
26 import org.eclipse.ui.IWorkbenchSite;
\r
27 import org.simantics.browsing.ui.swt.SingleSelectionInputSource;
\r
28 import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;
\r
29 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
30 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;
\r
31 import org.simantics.db.ReadGraph;
\r
32 import org.simantics.db.Resource;
\r
33 import org.simantics.db.exception.DatabaseException;
\r
34 import org.simantics.db.management.ISessionContext;
\r
35 import org.simantics.db.request.Read;
\r
36 import org.simantics.jfreechart.chart.properties.AdjustableTab;
\r
37 import org.simantics.jfreechart.chart.properties.xyline.AxisAndVariablesExplorerComposite;
\r
38 import org.simantics.jfreechart.chart.properties.xyline.AxisPropertyComposite;
\r
39 import org.simantics.jfreechart.chart.properties.xyline.SeriesPropertyComposite;
\r
40 import org.simantics.sysdyn.JFreeChartResource;
\r
41 import org.simantics.ui.SimanticsUI;
\r
42 import org.simantics.utils.datastructures.ArrayMap;
\r
43 import org.simantics.utils.ui.AdaptionUtils;
\r
45 public class SensitivityChartAxisAndVariablesTab extends AdjustableTab {
\r
47 private GraphExplorerComposite explorer;
\r
48 private ScrolledComposite propertyContainer;
\r
49 private WidgetSupportImpl additionalSupport;
\r
51 public SensitivityChartAxisAndVariablesTab(Object id) {
\r
53 additionalSupport = new WidgetSupportImpl();
\r
57 * Updates the content of propertyContainer
\r
60 private void updateSelection(ISessionContext context) {
\r
61 ISelectionProvider selectionProvider = (ISelectionProvider)explorer.getAdapter(ISelectionProvider.class);
\r
62 IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection();
\r
63 final Resource resource = AdaptionUtils.adaptToSingle(selection, Resource.class);
\r
64 if(resource == null)
\r
67 // Get the type of the selected node (axis or series)
\r
68 String typeUri = null;
\r
70 typeUri = SimanticsUI.getSession().syncRequest(new Read<String>() {
\r
73 public String perform(ReadGraph graph) throws DatabaseException {
\r
74 JFreeChartResource jfree = JFreeChartResource.getInstance(graph);
\r
75 if(graph.isInstanceOf(resource, jfree.Axis))
\r
76 return graph.getURI(jfree.Axis);
\r
77 else if (graph.isInstanceOf(resource, jfree.Series))
\r
78 return graph.getURI(jfree.Series);
\r
83 } catch (DatabaseException e) {
\r
84 e.printStackTrace();
\r
87 // Create a PropertyComposite for the selected node
\r
88 if(typeUri != null) {
\r
90 for(Control child : propertyContainer.getChildren()) {
\r
94 if(typeUri.equals(JFreeChartResource.URIs.Axis)) {
\r
95 AxisPropertyComposite apc = new AxisPropertyComposite(propertyContainer, context, additionalSupport, SWT.NONE, isVertical());
\r
96 propertyContainer.setContent(apc);
\r
97 Point size = apc.computeSize(SWT.DEFAULT, SWT.DEFAULT);
\r
98 propertyContainer.setMinSize(size);
\r
99 } else if(typeUri.equals(JFreeChartResource.URIs.Series)) {
\r
100 SeriesPropertyComposite spc = new SensitivitySeriesPropertyComposite(propertyContainer, context, additionalSupport, SWT.NONE);
\r
101 propertyContainer.setContent(spc);
\r
102 Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT);
\r
103 propertyContainer.setMinSize(size);
\r
107 additionalSupport.fireInput(context, selection);
\r
111 protected void createAndAddControls(Composite body, IWorkbenchSite site,
\r
112 final ISessionContext context, WidgetSupport support) {
\r
113 composite = new Composite(body, SWT.NONE);
\r
115 // (Ontology-based) GraphExplorer displaying range axis and variables mapped to those axis
\r
116 explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys(
\r
117 "displaySelectors", "displayFilter").values(false, false), site, composite, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE);
\r
118 explorer.setBrowseContexts(JFreeChartResource.URIs.ChartAxisAndVariablesBrowseContext);
\r
119 explorer.setInputSource(new SingleSelectionInputSource(
\r
121 explorer.getExplorer().setAutoExpandLevel(2); // Expand everything in the beginning
\r
124 ((Tree)explorer.getExplorerControl()).addSelectionListener(new SelectionAdapter() {
\r
125 public void widgetSelected(SelectionEvent e) {
\r
126 updateSelection(context);
\r
130 // Scrolled composite for displaying properties of a selection in explorer
\r
131 propertyContainer = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
\r
132 propertyContainer.setExpandHorizontal(true);
\r
133 propertyContainer.setExpandVertical(true);
\r
138 protected void createControlLayoutVertical() {
\r
139 GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
\r
140 GridLayoutFactory.fillDefaults().numColumns(1).margins(3, 3).applyTo(composite);
\r
142 GridDataFactory.fillDefaults().hint(220, SWT.DEFAULT).grab(false, true).applyTo(explorer);
\r
144 // Scrolled composite for displaying properties of a selection in explorer
\r
145 GridDataFactory.fillDefaults().span(1, 1).hint(SWT.DEFAULT, 210).grab(true, false).applyTo(propertyContainer);
\r
146 GridLayoutFactory.fillDefaults().applyTo(propertyContainer);
\r
150 protected void createControlLayoutHorizontal(boolean wideScreen) {
\r
151 GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
\r
152 GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite);
\r
154 GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer);
\r
156 // Scrolled composite for displaying properties of a selection in explorer
\r
157 GridDataFactory.fillDefaults().span(1, 2).hint(SWT.DEFAULT, SWT.DEFAULT).grab(true, true).applyTo(propertyContainer);
\r
158 GridLayoutFactory.fillDefaults().applyTo(propertyContainer);
\r