X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Feditor%2FTrackExperimentTimeAction.java;fp=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Feditor%2FTrackExperimentTimeAction.java;h=482ac3acf41180fed530cc9dc9621d3e79b50137;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/editor/TrackExperimentTimeAction.java b/bundles/org.simantics.charts/src/org/simantics/charts/editor/TrackExperimentTimeAction.java new file mode 100644 index 000000000..482ac3acf --- /dev/null +++ b/bundles/org.simantics.charts/src/org/simantics/charts/editor/TrackExperimentTimeAction.java @@ -0,0 +1,46 @@ +package org.simantics.charts.editor; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.Action; +import org.simantics.Simantics; +import org.simantics.charts.Activator; +import org.simantics.charts.ontology.ChartResource; +import org.simantics.charts.query.SetProperty; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; + +/** + * @author Tuukka Lehtonen + */ +public class TrackExperimentTimeAction extends Action { + + private Resource chart; + private Boolean currentValue; + + public TrackExperimentTimeAction(String name, Resource chart, boolean currentValue) { + super(name, Action.AS_CHECK_BOX); + this.chart = chart; + this.currentValue = currentValue; + setChecked(currentValue); + } + + @Override + public void run() { + setTracking(chart, !currentValue); + } + + public static void setTracking(Resource chart, boolean newValue) { + try { + Session session = Simantics.getSession(); + ChartResource CHART = ChartResource.getInstance(session); + session.markUndoPoint(); + session.syncRequest(new SetProperty(chart, CHART.Chart_trackExperimentTime, newValue, Bindings.BOOLEAN)); + } catch (DatabaseException e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to set track experiment time.", e)); + } + } + +} \ No newline at end of file