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;
\r
14 import java.lang.reflect.InvocationTargetException;
\r
16 import org.eclipse.core.commands.AbstractHandler;
\r
17 import org.eclipse.core.commands.ExecutionEvent;
\r
18 import org.eclipse.core.commands.ExecutionException;
\r
19 import org.eclipse.core.runtime.IProgressMonitor;
\r
20 import org.eclipse.core.runtime.SubMonitor;
\r
21 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
\r
22 import org.eclipse.jface.operation.IRunnableWithProgress;
\r
23 import org.eclipse.ui.handlers.HandlerUtil;
\r
24 import org.simantics.project.IProject;
\r
25 import org.simantics.simulation.experiment.IExperiment;
\r
26 import org.simantics.simulation.project.IExperimentManager;
\r
27 import org.simantics.ui.SimanticsUI;
\r
28 import org.simantics.utils.ui.ExceptionUtils;
\r
30 public class Dispose extends AbstractHandler {
\r
33 public Object execute(ExecutionEvent event) throws ExecutionException {
\r
34 IProject project = SimanticsUI.getProject();
\r
35 IExperimentManager manager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
\r
36 final IExperiment experiment = manager.getActiveExperiment();
\r
37 if (experiment == null)
\r
41 new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)).run(true, false, new IRunnableWithProgress() {
\r
43 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
\r
44 SubMonitor mon = SubMonitor.convert(monitor, "Shutdown experiment...", 10000);
\r
46 experiment.shutdown(mon.newChild(10000));
\r
52 } catch (InvocationTargetException e) {
\r
53 ExceptionUtils.logAndShowError(e.getCause());
\r
54 } catch (InterruptedException e) {
\r
55 ExceptionUtils.logAndShowError(e.getCause());
\r