01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso.actions;
05:
06: import org.eclipse.core.runtime.IProgressMonitor;
07: import org.eclipse.jdt.core.IJavaProject;
08: import org.eclipse.jface.action.IAction;
09: import org.eclipse.jface.dialogs.MessageDialog;
10: import org.eclipse.jface.operation.IRunnableWithProgress;
11: import org.eclipse.jface.viewers.ISelection;
12: import org.eclipse.swt.widgets.Shell;
13: import org.eclipse.ui.IObjectActionDelegate;
14: import org.eclipse.ui.IWorkbenchPart;
15: import org.eclipse.ui.IWorkbenchWindow;
16: import org.eclipse.ui.PlatformUI;
17: import org.terracotta.dso.ServerTracker;
18:
19: import java.lang.reflect.InvocationTargetException;
20:
21: /**
22: * Shutdown the currently running server.
23: */
24:
25: public class StopServerAction implements IObjectActionDelegate,
26: IRunnableWithProgress {
27: private IJavaProject m_currentProject;
28:
29: public StopServerAction() {
30: super ();
31: }
32:
33: public void setActivePart(IAction action, IWorkbenchPart targetPart) {/**/
34: }
35:
36: public void run(IAction action) {
37: try {
38: IWorkbenchWindow window = PlatformUI.getWorkbench()
39: .getActiveWorkbenchWindow();
40: window.run(true, true, this );
41: } catch (Exception e) {
42: Shell shell = new Shell();
43: MessageDialog.openInformation(shell, "Terracotta",
44: "Cannot stop Terracotta Server:\n"
45: + ActionUtil.getStatusMessages(e));
46: }
47: }
48:
49: public void run(IProgressMonitor monitor)
50: throws InvocationTargetException, InterruptedException {
51: if (monitor != null && monitor.isCanceled())
52: throw new InterruptedException("Canceled");
53: ServerTracker.getDefault()
54: .stopServer(m_currentProject, monitor);
55: }
56:
57: public void selectionChanged(IAction action, ISelection selection) {
58: m_currentProject = ActionUtil
59: .findSelectedJavaProject(selection);
60: }
61: }
|