+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.simulation.ui.handlers.e4;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.core.runtime.jobs.Job;\r
+import org.eclipse.e4.core.di.annotations.Execute;\r
+import org.simantics.ObjectIdentitySchedulingRule;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.simulation.ui.Activator;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class Reload {\r
+\r
+ @Execute\r
+ public void execute() {\r
+ IExperimentManager manager =\r
+ SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+ IExperiment experiment = manager.getActiveExperiment();\r
+ if (experiment != null) {\r
+ Job j = new RefreshJob(experiment);\r
+ j.setRule(new ObjectIdentitySchedulingRule(experiment));\r
+ j.schedule();\r
+ }\r
+ return;\r
+ }\r
+\r
+ static class RefreshJob extends Job {\r
+ private final IExperiment experiment;\r
+\r
+ public RefreshJob(IExperiment experiment) {\r
+ super("Refresh Experiment");\r
+ this.experiment = experiment;\r
+ }\r
+\r
+ @Override\r
+ protected IStatus run(IProgressMonitor monitor) {\r
+ try {\r
+ monitor.beginTask("", IProgressMonitor.UNKNOWN);\r
+ experiment.refresh(SimanticsUI.getSession());\r
+ if (monitor.isCanceled())\r
+ return Status.CANCEL_STATUS;\r
+ return Status.OK_STATUS;\r
+ } catch (Throwable t) {\r
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to refresh experiment "\r
+ + experiment + " with ID " + experiment.getIdentifier(), t);\r
+ } finally {\r
+ monitor.done();\r
+ }\r
+ }\r
+ }\r
+\r
+}\r