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.jfreechart.chart.properties.pie;
\r
14 import org.eclipse.jface.layout.GridDataFactory;
\r
15 import org.eclipse.jface.layout.GridLayoutFactory;
\r
16 import org.eclipse.jface.layout.LayoutConstants;
\r
17 import org.eclipse.swt.SWT;
\r
18 import org.eclipse.swt.custom.ScrolledComposite;
\r
19 import org.eclipse.swt.graphics.Point;
\r
20 import org.eclipse.swt.widgets.Composite;
\r
21 import org.eclipse.swt.widgets.Group;
\r
22 import org.eclipse.swt.widgets.Label;
\r
23 import org.eclipse.ui.IWorkbenchSite;
\r
24 import org.simantics.browsing.ui.swt.widgets.Button;
\r
25 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;
\r
26 import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;
\r
27 import org.simantics.browsing.ui.swt.widgets.TrackedText;
\r
28 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
29 import org.simantics.db.management.ISessionContext;
\r
30 import org.simantics.jfreechart.chart.properties.BooleanPropertyFactory;
\r
31 import org.simantics.jfreechart.chart.properties.BooleanSelectionListener;
\r
32 import org.simantics.jfreechart.chart.properties.DoublePropertyFactory2;
\r
33 import org.simantics.jfreechart.chart.properties.DoublePropertyModifier2;
\r
34 import org.simantics.jfreechart.chart.properties.DoubleValidator;
\r
35 import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;
\r
36 import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;
\r
37 import org.simantics.jfreechart.chart.properties.TitleFactory;
\r
38 import org.simantics.jfreechart.chart.properties.TitleModifier;
\r
39 import org.simantics.layer0.Layer0;
\r
40 import org.simantics.modeling.ui.chart.property.DoublePropertyFactory;
\r
41 import org.simantics.modeling.ui.chart.property.DoublePropertyModifier;
\r
42 import org.simantics.sysdyn.JFreeChartResource;
\r
45 * General properties of a pie chart
\r
46 * @author Teemu Lempinen
\r
49 public class PieGeneralPropertiesTab extends LabelPropertyTabContributor {
\r
51 private ScrolledComposite sc;
\r
52 private Composite composite;
\r
53 private Button htitle, hlegend, hlabels;
\r
54 private TrackedText name, title, time;
\r
57 public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {
\r
58 // Scrolled composite containing all of the properties in this tab
\r
59 sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL);
\r
60 GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);
\r
61 GridLayoutFactory.fillDefaults().applyTo(sc);
\r
62 sc.setExpandHorizontal(true);
\r
63 sc.setExpandVertical(true);
\r
65 composite = new Composite(sc, SWT.NONE);
\r
66 GridLayoutFactory.fillDefaults().numColumns(3).margins(3, 3).applyTo(composite);
\r
68 // General properties
\r
69 Group general = new Group(composite, SWT.NONE);
\r
70 GridDataFactory.fillDefaults().grab(true, false).applyTo(general);
\r
71 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general);
\r
72 general.setText("General");
\r
74 // first column: labels
\r
75 Composite labelColumn1 = new Composite(general, SWT.NONE);
\r
76 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1);
\r
77 GridLayoutFactory.fillDefaults().applyTo(labelColumn1);
\r
79 // first column: name and title
\r
80 Composite propertyColumn1 = new Composite(general, SWT.NONE);
\r
81 GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1);
\r
82 GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1);
\r
84 // first column: labels
\r
85 Composite labelColumn2 = new Composite(general, SWT.NONE);
\r
86 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2);
\r
87 GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2);
\r
89 // first column: type and time
\r
90 Composite propertyColumn2 = new Composite(general, SWT.NONE);
\r
91 GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2);
\r
92 GridLayoutFactory.fillDefaults().applyTo(propertyColumn2);
\r
95 Label label = new Label(labelColumn1, SWT.NONE);
\r
96 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
97 label.setText("Name:");
\r
99 name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER);
\r
100 GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());
\r
101 name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel));
\r
102 name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));
\r
103 name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));
\r
105 // Dummy data for now. Waiting for different pie chart types
\r
106 label = new Label(labelColumn2, SWT.NONE);
\r
107 GridDataFactory.fillDefaults().grab(false, true).applyTo(label);
\r
110 label = new Label(propertyColumn2, SWT.NONE);
\r
111 GridDataFactory.fillDefaults().grab(false, true).applyTo(label);
\r
114 // Title (Which is different than name)
\r
115 label = new Label(labelColumn1, SWT.NONE);
\r
116 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
117 label.setText("Title:");
\r
119 title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER);
\r
120 GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget());
\r
121 title.setTextFactory(new TitleFactory());
\r
122 title.addModifyListener(new TitleModifier());
\r
123 title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));
\r
126 label = new Label(labelColumn2, SWT.NONE);
\r
127 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
128 label.setText("Time:");
\r
130 time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER);
\r
131 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget());
\r
132 time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time));
\r
133 time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time));
\r
134 time.setInputValidator(new DoubleValidator(true));
\r
135 time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));
\r
137 // Group for hide options
\r
138 Group hideGroup = new Group(composite, SWT.NONE);
\r
139 GridDataFactory.fillDefaults().applyTo(hideGroup);
\r
140 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup);
\r
141 hideGroup.setText("Hide");
\r
143 htitle = new Button(hideGroup, support, SWT.CHECK);
\r
144 htitle.setText("Title");
\r
145 htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true));
\r
146 htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible));
\r
147 hlegend = new Button(hideGroup, support, SWT.CHECK);
\r
148 hlegend.setText("Legend");
\r
149 hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true));
\r
150 hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend));
\r
151 hlabels = new Button(hideGroup, support, SWT.CHECK);
\r
152 hlabels.setText("Section labels");
\r
153 hlabels.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels, true));
\r
154 hlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels));
\r
157 Group filteringGroup = new Group(composite, SWT.NONE);
\r
158 GridDataFactory.fillDefaults().applyTo(filteringGroup);
\r
159 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(filteringGroup);
\r
160 hideGroup.setText("Filter");
\r
161 label = new Label(filteringGroup, SWT.NONE);
\r
162 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
163 label.setText("Use:");
\r
164 Button useFilter = new Button(filteringGroup, support, SWT.CHECK);
\r
165 useFilter.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_used, false));
\r
166 useFilter.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_used));
\r
167 label = new Label(filteringGroup, SWT.NONE);
\r
168 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
169 label.setText("Percent:");
\r
170 TrackedText fraction = new TrackedText(filteringGroup, support, SWT.BORDER);
\r
171 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(fraction.getWidget());
\r
172 fraction.setTextFactory(new DoublePropertyFactory2(JFreeChartResource.URIs.Plot,JFreeChartResource.URIs.Filter_fraction));
\r
173 fraction.addModifyListener(new DoublePropertyModifier2(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_fraction));
\r
174 fraction.setInputValidator(new DoubleValidator(true));
\r
175 fraction.setColorProvider(new JFreeChartPropertyColorProvider(fraction.getResourceManager()));
\r
178 sc.setContent(composite);
\r
179 Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
\r
180 sc.setMinSize(size);
\r