]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/e4/Reload.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / handlers / e4 / Reload.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.simulation.ui.handlers.e4;
13
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.core.runtime.jobs.Job;
18 import org.eclipse.e4.core.di.annotations.Execute;
19 import org.simantics.ObjectIdentitySchedulingRule;
20 import org.simantics.simulation.experiment.IExperiment;
21 import org.simantics.simulation.project.IExperimentManager;
22 import org.simantics.simulation.ui.Activator;
23 import org.simantics.ui.SimanticsUI;
24
25 public class Reload {
26
27     @Execute
28     public void execute() {
29         IExperimentManager manager =
30             SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
31         IExperiment experiment = manager.getActiveExperiment();
32         if (experiment != null) {
33             Job j = new RefreshJob(experiment);
34             j.setRule(new ObjectIdentitySchedulingRule(experiment));
35             j.schedule();
36         }
37         return;
38     }
39
40     static class RefreshJob extends Job {
41         private final IExperiment experiment;
42
43         public RefreshJob(IExperiment experiment) {
44             super("Refresh Experiment");
45             this.experiment = experiment;
46         }
47
48         @Override
49         protected IStatus run(IProgressMonitor monitor) {
50             try {
51                 monitor.beginTask("", IProgressMonitor.UNKNOWN);
52                 experiment.refresh(SimanticsUI.getSession());
53                 if (monitor.isCanceled())
54                     return Status.CANCEL_STATUS;
55                 return Status.OK_STATUS;
56             } catch (Throwable t) {
57                 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to refresh experiment "
58                         + experiment + " with ID " + experiment.getIdentifier(), t);
59             } finally {
60                 monitor.done();
61             }
62         }
63     }
64
65 }