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