1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.simulation.ui.handlers.e4;
\r
14 import org.eclipse.core.runtime.IProgressMonitor;
\r
15 import org.eclipse.core.runtime.IStatus;
\r
16 import org.eclipse.core.runtime.Status;
\r
17 import org.eclipse.core.runtime.jobs.Job;
\r
18 import org.eclipse.e4.core.di.annotations.Execute;
\r
19 import org.simantics.ObjectIdentitySchedulingRule;
\r
20 import org.simantics.simulation.experiment.IExperiment;
\r
21 import org.simantics.simulation.project.IExperimentManager;
\r
22 import org.simantics.simulation.ui.Activator;
\r
23 import org.simantics.ui.SimanticsUI;
\r
25 public class Reload {
\r
28 public void execute() {
\r
29 IExperimentManager manager =
\r
30 SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
\r
31 IExperiment experiment = manager.getActiveExperiment();
\r
32 if (experiment != null) {
\r
33 Job j = new RefreshJob(experiment);
\r
34 j.setRule(new ObjectIdentitySchedulingRule(experiment));
\r
40 static class RefreshJob extends Job {
\r
41 private final IExperiment experiment;
\r
43 public RefreshJob(IExperiment experiment) {
\r
44 super("Refresh Experiment");
\r
45 this.experiment = experiment;
\r
49 protected IStatus run(IProgressMonitor monitor) {
\r
51 monitor.beginTask("", IProgressMonitor.UNKNOWN);
\r
52 experiment.refresh(SimanticsUI.getSession());
\r
53 if (monitor.isCanceled())
\r
54 return Status.CANCEL_STATUS;
\r
55 return Status.OK_STATUS;
\r
56 } catch (Throwable t) {
\r
57 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to refresh experiment "
\r
58 + experiment + " with ID " + experiment.getIdentifier(), t);
\r