1 /*
2 * Copyright 2004-2008 the Seasar Foundation and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.seasar.uruma.binding.method;
17
18 import org.eclipse.jface.action.Action;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.action.IMenuCreator;
21 import org.eclipse.swt.events.HelpListener;
22 import org.eclipse.swt.widgets.Event;
23 import org.eclipse.swt.widgets.Listener;
24 import org.seasar.framework.container.annotation.tiger.Binding;
25 import org.seasar.framework.container.annotation.tiger.BindingType;
26 import org.seasar.uruma.log.UrumaLogger;
27
28 /**
29 * 汎用的な {@link IAction} クラスです。<br />
30 *
31 * @author y-komori
32 */
33 public class GenericAction extends Action {
34 private static final UrumaLogger logger = UrumaLogger
35 .getLogger(GenericAction.class);
36
37 private Listener listener;
38
39 /**
40 * {@link GenericAction} を構築します。<br />
41 *
42 */
43 public GenericAction() {
44 super();
45 }
46
47 /**
48 * {@link GenericAction} を構築します。<br />
49 *
50 * @param text
51 * テキスト
52 */
53 public GenericAction(final String text) {
54 super(text);
55 }
56
57 /**
58 * {@link GenericAction} を構築します。<br />
59 *
60 * @param text
61 * テキスト
62 * @param style
63 * スタイル
64 */
65 public GenericAction(final String text, final int style) {
66 super(text, style);
67 }
68
69 /**
70 * {@link Listener} を設定します。<br />
71 *
72 * @param listener
73 * {@link Listener} オブジェクト
74 */
75 public void setListener(final Listener listener) {
76 this.listener = listener;
77 }
78
79 /*
80 * @see org.eclipse.jface.action.Action#run()
81 */
82 @Override
83 public void runWithEvent(final Event event) {
84 try {
85 if (listener != null) {
86 listener.handleEvent(event);
87 }
88 } catch (Throwable ex) {
89 logger.log(ex);
90 }
91 }
92
93 /*
94 * @see org.eclipse.jface.action.Action#run()
95 */
96 @Override
97 public void run() {
98 runWithEvent(null);
99 }
100
101 /*
102 * @see org.eclipse.jface.action.Action#setHelpListener(org.eclipse.swt.events.HelpListener)
103 */
104 @Override
105 @Binding(bindingType = BindingType.MAY)
106 public void setHelpListener(final HelpListener listener) {
107 super.setHelpListener(listener);
108 }
109
110 /*
111 * @see org.eclipse.jface.action.Action#setMenuCreator(org.eclipse.jface.action.IMenuCreator)
112 */
113 @Override
114 @Binding(bindingType = BindingType.MAY)
115 public void setMenuCreator(final IMenuCreator creator) {
116 super.setMenuCreator(creator);
117 }
118
119 }