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 java.lang.reflect.InvocationTargetException;
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;
30 public class Dispose extends AbstractHandler {
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)
41 new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)).run(true, false, new IRunnableWithProgress() {
43 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
44 SubMonitor mon = SubMonitor.convert(monitor, "Shutdown experiment...", 10000);
46 experiment.shutdown(mon.newChild(10000));
52 } catch (InvocationTargetException e) {
53 ExceptionUtils.logAndShowError(e.getCause());
54 } catch (InterruptedException e) {
55 ExceptionUtils.logAndShowError(e.getCause());