Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / editor / TrackExperimentTimeAction.java
1 package org.simantics.charts.editor;\r
2 \r
3 import org.eclipse.core.runtime.IStatus;\r
4 import org.eclipse.core.runtime.Status;\r
5 import org.eclipse.jface.action.Action;\r
6 import org.simantics.Simantics;\r
7 import org.simantics.charts.Activator;\r
8 import org.simantics.charts.ontology.ChartResource;\r
9 import org.simantics.charts.query.SetProperty;\r
10 import org.simantics.databoard.Bindings;\r
11 import org.simantics.db.Resource;\r
12 import org.simantics.db.Session;\r
13 import org.simantics.db.exception.DatabaseException;\r
14 \r
15 /**\r
16  * @author Tuukka Lehtonen\r
17  */\r
18 public class TrackExperimentTimeAction extends Action {\r
19 \r
20     private Resource chart;\r
21     private Boolean currentValue;\r
22 \r
23     public TrackExperimentTimeAction(String name, Resource chart, boolean currentValue) {\r
24         super(name, Action.AS_CHECK_BOX);\r
25         this.chart = chart;\r
26         this.currentValue = currentValue;\r
27         setChecked(currentValue);\r
28     }\r
29 \r
30     @Override\r
31     public void run() {\r
32         setTracking(chart, !currentValue);\r
33     }\r
34 \r
35     public static void setTracking(Resource chart, boolean newValue) {\r
36         try {\r
37             Session session = Simantics.getSession();\r
38             ChartResource CHART = ChartResource.getInstance(session);\r
39             session.markUndoPoint();\r
40             session.syncRequest(new SetProperty(chart, CHART.Chart_trackExperimentTime, newValue, Bindings.BOOLEAN));\r
41         } catch (DatabaseException e) {\r
42             Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to set track experiment time.", e));\r
43         }\r
44     }\r
45 \r
46 }