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 | 0 | private IProject project = null; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public AbstractProjectAction() { |
41 | 0 | super(); |
42 | 0 | } |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public void selectionChanged(IAction action, ISelection selection) { |
51 | 0 | if (selection instanceof IStructuredSelection) { |
52 | 0 | IStructuredSelection ss = (IStructuredSelection) selection; |
53 | 0 | Object o = ss.getFirstElement(); |
54 | 0 | this.project = AdaptableUtil.toProject(o); |
55 | 0 | if (this.project == null) { |
56 | 0 | IResource r = AdaptableUtil.toResource(o); |
57 | 0 | if (r != null) { |
58 | 0 | this.project = r.getProject(); |
59 | |
} |
60 | |
} |
61 | |
} |
62 | 0 | } |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public void run(IAction action) { |
70 | |
try { |
71 | 0 | if (this.project == null) { |
72 | 0 | this.project = ProjectUtil.getCurrentSelectedProject(); |
73 | |
} |
74 | 0 | if (this.project != null) { |
75 | 0 | run(action, this.project); |
76 | |
} |
77 | 0 | } catch (CoreException e) { |
78 | 0 | CommonPlugin.log(e); |
79 | 0 | } |
80 | 0 | } |
81 | |
|
82 | |
public abstract void run(IAction action, IProject project) |
83 | |
throws CoreException; |
84 | |
} |