]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/DelayedIntegerToDoublePropertyModifier.java
(refs #7571) Fixed incorrect handling of effects in edo
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / chart / property / DelayedIntegerToDoublePropertyModifier.java
1 /*******************************************************************************
2  * Copyright (c) 2010, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.ui.chart.property;
13
14 import org.eclipse.swt.events.SelectionEvent;
15 import org.eclipse.swt.widgets.Widget;
16 import org.simantics.browsing.ui.swt.widgets.Scale;
17 import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;
18 import org.simantics.databoard.Bindings;
19 import org.simantics.db.Resource;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.management.ISessionContext;
23
24 /**
25  * @author Tuukka Lehtonen
26  */
27 public class DelayedIntegerToDoublePropertyModifier extends SelectionListenerImpl<Resource> {
28
29     private final Scale slider;
30     private final String propertyURI;
31     private int selection;
32
33     public DelayedIntegerToDoublePropertyModifier(Scale slider, ISessionContext context, String propertyURI) {
34         super(context);
35         this.slider = slider;
36         this.propertyURI = propertyURI;
37     }
38
39     @Override
40     public void beforeApply() {
41         this.selection = slider.getWidget().getSelection();
42     }
43
44     @Override
45     public void apply(WriteGraph graph, Resource input) throws DatabaseException {
46         graph.claimLiteral(input, graph.getResource(propertyURI), (double) selection, Bindings.DOUBLE);
47     }
48
49     private void super$widgetSelected(SelectionEvent e) {
50         super.widgetSelected(e);
51     }
52
53     int modCount = 0;
54
55     @Override
56     public void widgetSelected(final SelectionEvent e) {
57         final int mod = ++modCount;
58         final Widget widget = slider.getWidget();
59         widget.getDisplay().timerExec(250, new Runnable() {
60             @Override
61             public void run() {
62                 if (widget.isDisposed() || mod != modCount)
63                     return;
64                 super$widgetSelected(e);
65             }
66         });
67     }
68
69 }