]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/Dispose.java
Remove usage of deprecated SimanticsUI-methods
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / handlers / Dispose.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;
13
14 import java.lang.reflect.InvocationTargetException;
15
16 import org.eclipse.core.commands.AbstractHandler;
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.SubMonitor;
21 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
22 import org.eclipse.jface.operation.IRunnableWithProgress;
23 import org.eclipse.ui.handlers.HandlerUtil;
24 import org.simantics.Simantics;
25 import org.simantics.project.IProject;
26 import org.simantics.simulation.experiment.IExperiment;
27 import org.simantics.simulation.project.IExperimentManager;
28 import org.simantics.utils.ui.ExceptionUtils;
29
30 public class Dispose extends AbstractHandler {
31
32     @Override
33     public Object execute(ExecutionEvent event) throws ExecutionException {
34         IProject project = Simantics.getProject();
35         IExperimentManager manager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
36         final IExperiment experiment = manager.getActiveExperiment();
37         if (experiment == null)
38             return null;
39
40         try {
41             new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)).run(true, false, new IRunnableWithProgress() {
42                 @Override
43                 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
44                     SubMonitor mon = SubMonitor.convert(monitor, "Shutdown experiment...", 10000);
45                     try {
46                         experiment.shutdown(mon.newChild(10000));
47                     } finally {
48                         monitor.done();
49                     }
50                 }
51             });
52         } catch (InvocationTargetException e) {
53             ExceptionUtils.logAndShowError(e.getCause());
54         } catch (InterruptedException e) {
55             ExceptionUtils.logAndShowError(e.getCause());
56         }
57
58         return null;
59     }
60
61 }