]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/DelayedIntegerToDoublePropertyModifier.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / chart / property / DelayedIntegerToDoublePropertyModifier.java
1 /*******************************************************************************\r
2  * Copyright (c) 2010, 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.modeling.ui.chart.property;\r
13 \r
14 import org.eclipse.swt.events.SelectionEvent;\r
15 import org.eclipse.swt.widgets.Widget;\r
16 import org.simantics.browsing.ui.swt.widgets.Scale;\r
17 import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
18 import org.simantics.databoard.Bindings;\r
19 import org.simantics.db.Resource;\r
20 import org.simantics.db.WriteGraph;\r
21 import org.simantics.db.exception.DatabaseException;\r
22 import org.simantics.db.management.ISessionContext;\r
23 \r
24 /**\r
25  * @author Tuukka Lehtonen\r
26  */\r
27 public class DelayedIntegerToDoublePropertyModifier extends SelectionListenerImpl<Resource> {\r
28 \r
29     private final Scale slider;\r
30     private final String propertyURI;\r
31     private int selection;\r
32 \r
33     public DelayedIntegerToDoublePropertyModifier(Scale slider, ISessionContext context, String propertyURI) {\r
34         super(context);\r
35         this.slider = slider;\r
36         this.propertyURI = propertyURI;\r
37     }\r
38 \r
39     @Override\r
40     public void beforeApply() {\r
41         this.selection = slider.getWidget().getSelection();\r
42     }\r
43 \r
44     @Override\r
45     public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
46         graph.claimLiteral(input, graph.getResource(propertyURI), (double) selection, Bindings.DOUBLE);\r
47     }\r
48 \r
49     private void super$widgetSelected(SelectionEvent e) {\r
50         super.widgetSelected(e);\r
51     }\r
52 \r
53     int modCount = 0;\r
54 \r
55     @Override\r
56     public void widgetSelected(final SelectionEvent e) {\r
57         final int mod = ++modCount;\r
58         final Widget widget = slider.getWidget();\r
59         widget.getDisplay().timerExec(250, new Runnable() {\r
60             @Override\r
61             public void run() {\r
62                 if (widget.isDisposed() || mod != modCount)\r
63                     return;\r
64                 super$widgetSelected(e);\r
65             }\r
66         });\r
67     }\r
68 \r
69 }\r