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