KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > actions > StopServerAction


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso.actions;
5
6 import org.eclipse.jdt.core.IJavaProject;
7 import org.eclipse.jface.action.IAction;
8 import org.eclipse.jface.dialogs.MessageDialog;
9 import org.eclipse.jface.viewers.ISelection;
10 import org.eclipse.jface.window.ApplicationWindow;
11 import org.eclipse.swt.widgets.Shell;
12 import org.eclipse.ui.IObjectActionDelegate;
13 import org.eclipse.ui.IWorkbenchPart;
14 import org.eclipse.ui.IWorkbenchWindow;
15 import org.eclipse.ui.PlatformUI;
16
17 import org.terracotta.dso.ServerTracker;
18 import org.terracotta.dso.actions.ActionUtil;
19
20 /**
21  * Shutdown the currently running server.
22  */

23
24 public class StopServerAction implements IObjectActionDelegate {
25   private IJavaProject m_currentProject;
26     
27   public StopServerAction() {
28     super();
29   }
30
31   public void setActivePart(IAction action, IWorkbenchPart targetPart) {/**/}
32
33   public void run(IAction action) {
34     IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
35
36     try {
37       ServerTracker.getDefault().stopServer(m_currentProject);
38       ((ApplicationWindow)window).setStatus("Terracotta Server Stopped.");
39     }
40     catch(Exception JavaDoc e) {
41       Shell shell = new Shell();
42       MessageDialog.openInformation(
43         shell,
44         "Terracotta",
45         "Cannot stop Terracotta Server:\n" +
46         ActionUtil.getStatusMessages(e));
47     }
48   }
49
50   public void selectionChanged(IAction action, ISelection selection) {
51     m_currentProject = ActionUtil.findSelectedJavaProject(selection);
52   }
53 }
54
Popular Tags