]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
3900631f6f6a80eb7b67d4abe08a422fa09819bc
[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.Combo;\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.layer0.Layer0;\r
31 import org.simantics.sysdyn.JFreeChartResource;\r
32 import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor;\r
33 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory;\r
34 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener;\r
35 import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;\r
36 import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory;\r
37 import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier;\r
38 \r
39 /**\r
40  * General properties of a pie chart\r
41  * @author Teemu Lempinen\r
42  *\r
43  */\r
44 public class PieGeneralPropertiesTab extends LabelPropertyTabContributor {\r
45 \r
46     private ScrolledComposite sc;\r
47     private Composite composite;\r
48     private Button htitle, hlegend;\r
49     private TrackedText name, title;\r
50     private Combo type;\r
51 \r
52     @Override\r
53     public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {    \r
54         // Scrolled composite containing all of the properties in this tab\r
55         sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL);\r
56         GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);\r
57         GridLayoutFactory.fillDefaults().applyTo(sc);\r
58         sc.setExpandHorizontal(true);\r
59         sc.setExpandVertical(true);\r
60 \r
61         composite = new Composite(sc, SWT.NONE);\r
62         GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite);\r
63 \r
64         // General properties\r
65         Group general = new Group(composite, SWT.NONE);\r
66         GridDataFactory.fillDefaults().grab(true, false).applyTo(general);\r
67         GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(general);\r
68         general.setText("General");\r
69 \r
70         // Name\r
71         Label label = new Label(general, SWT.NONE);\r
72         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
73         label.setText("Name:");\r
74 \r
75         Composite c = new Composite(general, SWT.NONE);\r
76         GridDataFactory.fillDefaults().applyTo(c);\r
77         GridLayoutFactory.fillDefaults().numColumns(3).applyTo(c);\r
78 \r
79         name = new org.simantics.browsing.ui.swt.widgets.TrackedText(c, support, SWT.BORDER);\r
80         GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());\r
81         name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel));\r
82         name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
83         name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));\r
84 \r
85         // Type\r
86         label = new Label(c, SWT.NONE);\r
87         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
88         label.setText("Type:");\r
89 \r
90         type = new Combo(c, SWT.BORDER | SWT.READ_ONLY);\r
91         type.setItems(new String[] {"Normal", "Stacked"});\r
92         type.select(0);\r
93 \r
94         // Title (Which is different than name)\r
95         label = new Label(general, SWT.NONE);\r
96         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
97         label.setText("Title:");\r
98 \r
99         title = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER);\r
100         GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget());\r
101         title.setTextFactory(new TitleFactory());\r
102         title.addModifyListener(new TitleModifier());\r
103         title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));\r
104 \r
105         // Group for hide options\r
106         Group hideGroup = new Group(composite, SWT.NONE);\r
107         GridDataFactory.fillDefaults().applyTo(hideGroup);\r
108         GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup);\r
109         hideGroup.setText("Hide");\r
110 \r
111         htitle = new Button(hideGroup, support, SWT.CHECK);\r
112         htitle.setText("Title");\r
113         htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true));\r
114         htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible));\r
115         hlegend = new Button(hideGroup, support, SWT.CHECK);\r
116         hlegend.setText("Legend");\r
117         hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true));\r
118         hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend));\r
119         \r
120         sc.setContent(composite);\r
121         Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
122         sc.setMinSize(size);\r
123     }\r
124 }\r