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.resources.IProject;
07: import org.eclipse.core.runtime.CoreException;
08: import org.eclipse.jdt.core.IJavaProject;
09: import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
10: import org.eclipse.jface.action.Action;
11: import org.eclipse.jface.action.IAction;
12: import org.eclipse.jface.viewers.ISelection;
13: import org.eclipse.jface.viewers.IStructuredSelection;
14: import org.eclipse.ui.IActionDelegate;
15: import org.eclipse.ui.IWorkbenchWindow;
16: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
17: import org.eclipse.ui.PartInitException;
18: import org.terracotta.dso.ProjectNature;
19: import org.terracotta.dso.TcPlugin;
20:
21: public class ShowConfigEditorAction extends Action implements
22: IActionDelegate, IWorkbenchWindowActionDelegate,
23: IJavaLaunchConfigurationConstants, IProjectAction {
24: private IJavaProject m_javaProject;
25: private IAction m_action;
26:
27: public ShowConfigEditorAction() {
28: super ("Open config editor");
29: TcPlugin.getDefault().registerProjectAction(this );
30: }
31:
32: public ShowConfigEditorAction(IJavaProject javaProject) {
33: super ("Open config editor");
34: m_javaProject = javaProject;
35: }
36:
37: public void run(IAction action) {
38: TcPlugin plugin = TcPlugin.getDefault();
39: try {
40: plugin.openConfigurationEditor(m_javaProject.getProject());
41: } catch (PartInitException pie) {
42: plugin.openError("Unable to open config editor", pie);
43: }
44: }
45:
46: public void selectionChanged(IAction action, ISelection selection) {
47: m_action = action;
48:
49: if (m_javaProject == null
50: || selection instanceof IStructuredSelection) {
51: update(ActionUtil.locateSelectedJavaProject(selection));
52: } else {
53: action.setEnabled(true);
54: }
55: }
56:
57: private void update(IJavaProject javaProject) {
58: if (javaProject != null) {
59: try {
60: if (javaProject.getProject().hasNature(
61: ProjectNature.NATURE_ID)) {
62: m_javaProject = javaProject;
63: } else {
64: m_javaProject = null;
65: }
66: } catch (CoreException ce) {/**/
67: }
68: } else {
69: m_javaProject = null;
70: }
71:
72: m_action.setEnabled(m_javaProject != null);
73: }
74:
75: public void update(IProject project) {
76: update(ActionUtil.findJavaProject(project));
77: }
78:
79: public void dispose() {
80: /**/
81: }
82:
83: public void init(IWorkbenchWindow window) {
84: /**/
85: }
86: }
|