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.IResource;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.ui.IEditorActionDelegate;
23 import org.eclipse.ui.IEditorPart;
24 import org.seasar.eclipse.common.util.AdaptableUtil;
25
26
27
28
29
30 public abstract class AbstractEditorActionDelegate implements
31 IEditorActionDelegate {
32
33 protected IEditorPart editorPart;
34
35 protected IResource resource;
36
37
38
39
40
41
42
43 public void setActiveEditor(IAction action, IEditorPart targetEditor) {
44 this.editorPart = targetEditor;
45 if (targetEditor != null) {
46 this.resource = AdaptableUtil.toResource(targetEditor
47 .getEditorInput());
48 }
49 }
50
51
52
53
54
55
56
57 public void selectionChanged(IAction action, ISelection selection) {
58 if (selection instanceof IStructuredSelection
59 && selection.isEmpty() == false) {
60 IStructuredSelection struct = (IStructuredSelection) selection;
61 Object o = struct.getFirstElement();
62 if (o instanceof IResource) {
63 this.resource = (IResource) o;
64 }
65 }
66 }
67 }