01: /*
02:
03: Derby - Class org.apache.derby.ui.actions.StopAction
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derby.ui.actions;
23:
24: import org.apache.derby.ui.common.CommonNames;
25: import org.apache.derby.ui.common.Messages;
26: import org.apache.derby.ui.util.DerbyServerUtils;
27: import org.apache.derby.ui.util.SelectionUtil;
28: import org.eclipse.core.resources.IProject;
29: import org.eclipse.jdt.core.IJavaProject;
30: import org.eclipse.jface.action.IAction;
31: import org.eclipse.jface.dialogs.MessageDialog;
32: import org.eclipse.jface.viewers.ISelection;
33: import org.eclipse.swt.widgets.Shell;
34: import org.eclipse.ui.IObjectActionDelegate;
35: import org.eclipse.ui.IWorkbenchPart;
36:
37: public class StopAction implements IObjectActionDelegate {
38:
39: private IJavaProject currentJavaProject;
40: private IProject currentProject;
41: private Thread server = null;
42:
43: public StopAction() {
44: super ();
45: }
46:
47: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
48: }
49:
50: public void run(IAction action) {
51: try {
52: if (currentJavaProject != null) {
53: currentProject = currentJavaProject.getProject();
54:
55: }
56: DerbyServerUtils.getDefault().stopDerbyServer(
57: currentProject);
58:
59: } catch (Exception e) {
60: e.printStackTrace();
61: Shell shell = new Shell();
62: MessageDialog.openInformation(shell,
63: CommonNames.PLUGIN_NAME, Messages.D_NS_STOP_ERROR
64: + SelectionUtil.getStatusMessages(e));
65: }
66: }
67:
68: public void selectionChanged(IAction action, ISelection selection) {
69: currentJavaProject = SelectionUtil
70: .findSelectedJavaProject(selection);
71: if (currentJavaProject == null) {
72: currentProject = org.apache.derby.ui.util.SelectionUtil
73: .findSelectedProject(selection);
74: }
75: }
76: }
|