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.DoubleValidator;
\r
33 import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;
\r
34 import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;
\r
35 import org.simantics.jfreechart.chart.properties.TitleFactory;
\r
36 import org.simantics.jfreechart.chart.properties.TitleModifier;
\r
37 import org.simantics.layer0.Layer0;
\r
38 import org.simantics.modeling.ui.chart.property.DoublePropertyFactory;
\r
39 import org.simantics.modeling.ui.chart.property.DoublePropertyModifier;
\r
40 import org.simantics.sysdyn.JFreeChartResource;
\r
43 * General properties of a pie chart
\r
44 * @author Teemu Lempinen
\r
47 public class PieGeneralPropertiesTab extends LabelPropertyTabContributor {
\r
49 private ScrolledComposite sc;
\r
50 private Composite composite;
\r
51 private Button htitle, hlegend, hlabels;
\r
52 private TrackedText name, title, time;
\r
55 public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {
\r
56 // Scrolled composite containing all of the properties in this tab
\r
57 sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL);
\r
58 GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);
\r
59 GridLayoutFactory.fillDefaults().applyTo(sc);
\r
60 sc.setExpandHorizontal(true);
\r
61 sc.setExpandVertical(true);
\r
63 composite = new Composite(sc, SWT.NONE);
\r
64 GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite);
\r
66 // General properties
\r
67 Group general = new Group(composite, SWT.NONE);
\r
68 GridDataFactory.fillDefaults().grab(true, false).applyTo(general);
\r
69 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general);
\r
70 general.setText("General");
\r
72 // first column: labels
\r
73 Composite labelColumn1 = new Composite(general, SWT.NONE);
\r
74 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1);
\r
75 GridLayoutFactory.fillDefaults().applyTo(labelColumn1);
\r
77 // first column: name and title
\r
78 Composite propertyColumn1 = new Composite(general, SWT.NONE);
\r
79 GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1);
\r
80 GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1);
\r
82 // first column: labels
\r
83 Composite labelColumn2 = new Composite(general, SWT.NONE);
\r
84 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2);
\r
85 GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2);
\r
87 // first column: type and time
\r
88 Composite propertyColumn2 = new Composite(general, SWT.NONE);
\r
89 GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2);
\r
90 GridLayoutFactory.fillDefaults().applyTo(propertyColumn2);
\r
93 Label label = new Label(labelColumn1, SWT.NONE);
\r
94 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
95 label.setText("Name:");
\r
97 name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER);
\r
98 GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());
\r
99 name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel));
\r
100 name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));
\r
101 name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));
\r
103 // Dummy data for now. Waiting for different pie chart types
\r
104 label = new Label(labelColumn2, SWT.NONE);
\r
105 GridDataFactory.fillDefaults().grab(false, true).applyTo(label);
\r
108 label = new Label(propertyColumn2, SWT.NONE);
\r
109 GridDataFactory.fillDefaults().grab(false, true).applyTo(label);
\r
112 // Title (Which is different than name)
\r
113 label = new Label(labelColumn1, SWT.NONE);
\r
114 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
115 label.setText("Title:");
\r
117 title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER);
\r
118 GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget());
\r
119 title.setTextFactory(new TitleFactory());
\r
120 title.addModifyListener(new TitleModifier());
\r
121 title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));
\r
124 label = new Label(labelColumn2, SWT.NONE);
\r
125 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
126 label.setText("Time:");
\r
128 time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER);
\r
129 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget());
\r
130 time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time));
\r
131 time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time));
\r
132 time.setInputValidator(new DoubleValidator(true));
\r
133 time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));
\r
135 // Group for hide options
\r
136 Group hideGroup = new Group(composite, SWT.NONE);
\r
137 GridDataFactory.fillDefaults().applyTo(hideGroup);
\r
138 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup);
\r
139 hideGroup.setText("Hide");
\r
141 htitle = new Button(hideGroup, support, SWT.CHECK);
\r
142 htitle.setText("Title");
\r
143 htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true));
\r
144 htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible));
\r
145 hlegend = new Button(hideGroup, support, SWT.CHECK);
\r
146 hlegend.setText("Legend");
\r
147 hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true));
\r
148 hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend));
\r
149 hlabels = new Button(hideGroup, support, SWT.CHECK);
\r
150 hlabels.setText("Section labels");
\r
151 hlabels.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels, true));
\r
152 hlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels));
\r
154 sc.setContent(composite);
\r
155 Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
\r
156 sc.setMinSize(size);
\r