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.simulation.experiment.IExperiment;
23 import org.simantics.simulation.project.IExperimentManager;
24 import org.simantics.simulation.ui.Activator;
25 import org.simantics.ui.SimanticsUI;
27 public class Reload extends AbstractHandler {
30 public Object execute(ExecutionEvent event) throws ExecutionException {
31 IExperimentManager manager =
32 SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
33 IExperiment experiment = manager.getActiveExperiment();
34 if (experiment != null) {
35 Job j = new RefreshJob(experiment);
36 j.setRule(new ObjectIdentitySchedulingRule(experiment));
42 static class RefreshJob extends Job {
43 private final IExperiment experiment;
45 public RefreshJob(IExperiment experiment) {
46 super("Refresh Experiment");
47 this.experiment = experiment;
51 protected IStatus run(IProgressMonitor monitor) {
53 monitor.beginTask("", IProgressMonitor.UNKNOWN);
54 experiment.refresh(SimanticsUI.getSession());
55 if (monitor.isCanceled())
56 return Status.CANCEL_STATUS;
57 return Status.OK_STATUS;
58 } catch (Throwable t) {
59 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to refresh experiment "
60 + experiment + " with ID " + experiment.getIdentifier(), t);