]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
bbaa7b4b6e5b25cbbca0f8cc0d4cd13ef8d38147
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.trend.chart.properties.pie;\r
13 \r
14 import org.eclipse.jface.layout.GridDataFactory;\r
15 import org.eclipse.jface.layout.GridLayoutFactory;\r
16 import org.eclipse.swt.SWT;\r
17 import org.eclipse.swt.custom.ScrolledComposite;\r
18 import org.eclipse.swt.graphics.Point;\r
19 import org.eclipse.swt.widgets.Composite;\r
20 import org.eclipse.swt.widgets.Group;\r
21 import org.eclipse.swt.widgets.Label;\r
22 import org.eclipse.ui.IWorkbenchSite;\r
23 import org.simantics.browsing.ui.swt.widgets.Button;\r
24 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
25 import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
26 import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
27 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
28 import org.simantics.db.management.ISessionContext;\r
29 import org.simantics.layer0.Layer0;\r
30 import org.simantics.sysdyn.JFreeChartResource;\r
31 import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor;\r
32 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory;\r
33 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener;\r
34 import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;\r
35 import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory;\r
36 import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier;\r
37 \r
38 /**\r
39  * General properties of a pie chart\r
40  * @author Teemu Lempinen\r
41  *\r
42  */\r
43 public class PieGeneralPropertiesTab extends LabelPropertyTabContributor {\r
44 \r
45     private ScrolledComposite sc;\r
46     private Composite composite;\r
47     private Button htitle, hlegend, hlabels;\r
48     private TrackedText name, title;\r
49 \r
50     @Override\r
51     public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {    \r
52         // Scrolled composite containing all of the properties in this tab\r
53         sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL);\r
54         GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);\r
55         GridLayoutFactory.fillDefaults().applyTo(sc);\r
56         sc.setExpandHorizontal(true);\r
57         sc.setExpandVertical(true);\r
58 \r
59         composite = new Composite(sc, SWT.NONE);\r
60         GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite);\r
61 \r
62         // General properties\r
63         Group general = new Group(composite, SWT.NONE);\r
64         GridDataFactory.fillDefaults().grab(true, false).applyTo(general);\r
65         GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(general);\r
66         general.setText("General");\r
67 \r
68         // Name\r
69         Label label = new Label(general, SWT.NONE);\r
70         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
71         label.setText("Name:");\r
72 \r
73         name = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER);\r
74         GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());\r
75         name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel));\r
76         name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
77         name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));\r
78 \r
79         // Title (Which is different than name)\r
80         label = new Label(general, SWT.NONE);\r
81         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
82         label.setText("Title:");\r
83 \r
84         title = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER);\r
85         GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget());\r
86         title.setTextFactory(new TitleFactory());\r
87         title.addModifyListener(new TitleModifier());\r
88         title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));\r
89 \r
90         // Group for hide options\r
91         Group hideGroup = new Group(composite, SWT.NONE);\r
92         GridDataFactory.fillDefaults().applyTo(hideGroup);\r
93         GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup);\r
94         hideGroup.setText("Hide");\r
95 \r
96         htitle = new Button(hideGroup, support, SWT.CHECK);\r
97         htitle.setText("Title");\r
98         htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true));\r
99         htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible));\r
100         hlegend = new Button(hideGroup, support, SWT.CHECK);\r
101         hlegend.setText("Legend");\r
102         hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true));\r
103         hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend));\r
104         hlabels = new Button(hideGroup, support, SWT.CHECK);\r
105         hlabels.setText("Section labels");\r
106         hlabels.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels, true));\r
107         hlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels));\r
108         \r
109         sc.setContent(composite);\r
110         Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
111         sc.setMinSize(size);\r
112     }\r
113 }\r