1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.eclipse.common.action;
17
18 import org.eclipse.core.resources.IProject;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.viewers.ISelection;
23 import org.eclipse.jface.viewers.IStructuredSelection;
24 import org.eclipse.ui.IActionDelegate;
25 import org.seasar.eclipse.common.CommonPlugin;
26 import org.seasar.eclipse.common.util.AdaptableUtil;
27 import org.seasar.eclipse.common.util.ProjectUtil;
28
29
30
31
32
33 public abstract class AbstractProjectAction implements IActionDelegate {
34
35 private IProject project = null;
36
37
38
39
40 public AbstractProjectAction() {
41 super();
42 }
43
44
45
46
47
48
49
50 public void selectionChanged(IAction action, ISelection selection) {
51 if (selection instanceof IStructuredSelection) {
52 IStructuredSelection ss = (IStructuredSelection) selection;
53 Object o = ss.getFirstElement();
54 this.project = AdaptableUtil.toProject(o);
55 if (this.project == null) {
56 IResource r = AdaptableUtil.toResource(o);
57 if (r != null) {
58 this.project = r.getProject();
59 }
60 }
61 }
62 }
63
64
65
66
67
68
69 public void run(IAction action) {
70 try {
71 if (this.project == null) {
72 this.project = ProjectUtil.getCurrentSelectedProject();
73 }
74 if (this.project != null) {
75 run(action, this.project);
76 }
77 } catch (CoreException e) {
78 CommonPlugin.log(e);
79 }
80 }
81
82 public abstract void run(IAction action, IProject project)
83 throws CoreException;
84 }