- 浏览: 24787 次
- 性别:
- 来自: 重庆
文章分类
最新评论
1: /*******************************************************************************
2: * Copyright (c) 2004, 2006 IBM Corporation and others.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * IBM Corporation - initial API and implementation
10: *******************************************************************************/
11: package org.eclipse.jface.commands;
12:
13: import org.eclipse.core.commands.AbstractHandler;
14: import org.eclipse.core.commands.ExecutionEvent;
15: import org.eclipse.core.commands.ExecutionException;
16: import org.eclipse.core.commands.HandlerEvent;
17: import org.eclipse.core.commands.IHandlerListener;
18: import org.eclipse.jface.action.IAction;
19: import org.eclipse.jface.util.IPropertyChangeListener;
20: import org.eclipse.jface.util.PropertyChangeEvent;
21: import org.eclipse.swt.widgets.Event;
22:
23: /**
24: * <p>
25: * This class adapts instances of <code>IAction</code> to
26: * <code>IHandler</code>.
27: * </p>
28: *
29: * @since 3.1
30: */
31: public final class ActionHandler extends AbstractHandler {
32:
33: /**
34: * The wrapped action. This value is never <code>null</code>.
35: */
36: private final IAction action;
37:
38: /**
39: * The property change listener hooked on to the action. This is initialized
40: * when the first listener is attached to this handler, and is removed when
41: * the handler is disposed or the last listener is removed.
42: */
43: private IPropertyChangeListener propertyChangeListener;
44:
45: /**
46: * Creates a new instance of this class given an instance of
47: * <code>IAction</code>.
48: *
49: * @param action
50: * the action. Must not be <code>null</code>.
51: */
52: public ActionHandler(final IAction action) {
53: if (action == null) {
54: throw new NullPointerException();
55: }
56:
57: this.action = action;
58: }
59:
60: public final void addHandlerListener(final IHandlerListener handlerListener) {
61: if (!hasListeners()) {
62: attachListener();
63: }
64:
65: super.addHandlerListener(handlerListener);
66: }
67:
68: /**
69: * When a listener is attached to this handler, then this registers a
70: * listener with the underlying action.
71: *
72: * @since 3.1
73: */
74: private final void attachListener() {
75: if (propertyChangeListener == null) {
76: propertyChangeListener = new IPropertyChangeListener() {
77: public final void propertyChange(
78: final PropertyChangeEvent propertyChangeEvent) {
79: final String property = propertyChangeEvent.getProperty();
80: fireHandlerChanged(new HandlerEvent(ActionHandler.this,
81: IAction.ENABLED.equals(property), IAction.HANDLED
82: .equals(property)));
83: }
84: };
85: }
86:
87: this.action.addPropertyChangeListener(propertyChangeListener);
88: }
89:
90: /**
91: * When no more listeners are registered, then this is used to removed the
92: * property change listener from the underlying action.
93: */
94: private final void detachListener() {
95: this.action.removePropertyChangeListener(propertyChangeListener);
96: propertyChangeListener = null;
97: }
98:
99: /**
100: * Removes the property change listener from the action.
101: *
102: * @see org.eclipse.core.commands.IHandler#dispose()
103: */
104: public final void dispose() {
105: if (hasListeners()) {
106: action.removePropertyChangeListener(propertyChangeListener);
107: }
108: }
109:
110: public final Object execute(final ExecutionEvent event)
111: throws ExecutionException {
112: if ((action.getStyle() == IAction.AS_CHECK_BOX)
113: || (action.getStyle() == IAction.AS_RADIO_BUTTON)) {
114: action.setChecked(!action.isChecked());
115: }
116: final Object trigger = event.getTrigger();
117: try {
118: if (trigger instanceof Event) {
119: action.runWithEvent((Event) trigger);
120: } else {
121: action.runWithEvent(new Event());
122: }
123: } catch (Exception e) {
124: throw new ExecutionException(
125: "While executing the action, an exception occurred", e); //$NON-NLS-1$
126: }
127: return null;
128: }
129:
130: /**
131: * Returns the action associated with this handler
132: *
133: * @return the action associated with this handler (not null)
134: * @since 3.1
135: */
136: public final IAction getAction() {
137: return action;
138: }
139:
140: public final boolean isEnabled() {
141: return action.isEnabled();
142: }
143:
144: public final boolean isHandled() {
145: return action.isHandled();
146: }
147:
148: public final void removeHandlerListener(
149: final IHandlerListener handlerListener) {
150: super.removeHandlerListener(handlerListener);
151:
152: if (!hasListeners()) {
153: detachListener();
154: }
155: }
156:
157: public final String toString() {
158: final StringBuffer buffer = new StringBuffer();
159:
160: buffer.append("ActionHandler("); //$NON-NLS-1$
161: buffer.append(action);
162: buffer.append(')');
163:
164: return buffer.toString();
165: }
166:}
2: * Copyright (c) 2004, 2006 IBM Corporation and others.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * IBM Corporation - initial API and implementation
10: *******************************************************************************/
11: package org.eclipse.jface.commands;
12:
13: import org.eclipse.core.commands.AbstractHandler;
14: import org.eclipse.core.commands.ExecutionEvent;
15: import org.eclipse.core.commands.ExecutionException;
16: import org.eclipse.core.commands.HandlerEvent;
17: import org.eclipse.core.commands.IHandlerListener;
18: import org.eclipse.jface.action.IAction;
19: import org.eclipse.jface.util.IPropertyChangeListener;
20: import org.eclipse.jface.util.PropertyChangeEvent;
21: import org.eclipse.swt.widgets.Event;
22:
23: /**
24: * <p>
25: * This class adapts instances of <code>IAction</code> to
26: * <code>IHandler</code>.
27: * </p>
28: *
29: * @since 3.1
30: */
31: public final class ActionHandler extends AbstractHandler {
32:
33: /**
34: * The wrapped action. This value is never <code>null</code>.
35: */
36: private final IAction action;
37:
38: /**
39: * The property change listener hooked on to the action. This is initialized
40: * when the first listener is attached to this handler, and is removed when
41: * the handler is disposed or the last listener is removed.
42: */
43: private IPropertyChangeListener propertyChangeListener;
44:
45: /**
46: * Creates a new instance of this class given an instance of
47: * <code>IAction</code>.
48: *
49: * @param action
50: * the action. Must not be <code>null</code>.
51: */
52: public ActionHandler(final IAction action) {
53: if (action == null) {
54: throw new NullPointerException();
55: }
56:
57: this.action = action;
58: }
59:
60: public final void addHandlerListener(final IHandlerListener handlerListener) {
61: if (!hasListeners()) {
62: attachListener();
63: }
64:
65: super.addHandlerListener(handlerListener);
66: }
67:
68: /**
69: * When a listener is attached to this handler, then this registers a
70: * listener with the underlying action.
71: *
72: * @since 3.1
73: */
74: private final void attachListener() {
75: if (propertyChangeListener == null) {
76: propertyChangeListener = new IPropertyChangeListener() {
77: public final void propertyChange(
78: final PropertyChangeEvent propertyChangeEvent) {
79: final String property = propertyChangeEvent.getProperty();
80: fireHandlerChanged(new HandlerEvent(ActionHandler.this,
81: IAction.ENABLED.equals(property), IAction.HANDLED
82: .equals(property)));
83: }
84: };
85: }
86:
87: this.action.addPropertyChangeListener(propertyChangeListener);
88: }
89:
90: /**
91: * When no more listeners are registered, then this is used to removed the
92: * property change listener from the underlying action.
93: */
94: private final void detachListener() {
95: this.action.removePropertyChangeListener(propertyChangeListener);
96: propertyChangeListener = null;
97: }
98:
99: /**
100: * Removes the property change listener from the action.
101: *
102: * @see org.eclipse.core.commands.IHandler#dispose()
103: */
104: public final void dispose() {
105: if (hasListeners()) {
106: action.removePropertyChangeListener(propertyChangeListener);
107: }
108: }
109:
110: public final Object execute(final ExecutionEvent event)
111: throws ExecutionException {
112: if ((action.getStyle() == IAction.AS_CHECK_BOX)
113: || (action.getStyle() == IAction.AS_RADIO_BUTTON)) {
114: action.setChecked(!action.isChecked());
115: }
116: final Object trigger = event.getTrigger();
117: try {
118: if (trigger instanceof Event) {
119: action.runWithEvent((Event) trigger);
120: } else {
121: action.runWithEvent(new Event());
122: }
123: } catch (Exception e) {
124: throw new ExecutionException(
125: "While executing the action, an exception occurred", e); //$NON-NLS-1$
126: }
127: return null;
128: }
129:
130: /**
131: * Returns the action associated with this handler
132: *
133: * @return the action associated with this handler (not null)
134: * @since 3.1
135: */
136: public final IAction getAction() {
137: return action;
138: }
139:
140: public final boolean isEnabled() {
141: return action.isEnabled();
142: }
143:
144: public final boolean isHandled() {
145: return action.isHandled();
146: }
147:
148: public final void removeHandlerListener(
149: final IHandlerListener handlerListener) {
150: super.removeHandlerListener(handlerListener);
151:
152: if (!hasListeners()) {
153: detachListener();
154: }
155: }
156:
157: public final String toString() {
158: final StringBuffer buffer = new StringBuffer();
159:
160: buffer.append("ActionHandler("); //$NON-NLS-1$
161: buffer.append(action);
162: buffer.append(')');
163:
164: return buffer.toString();
165: }
166:}
发表评论
-
CoolBar CoolBarManager应用到任何ViewForm
2012-07-03 10:44 1491ViewForm viewForm = new ViewFor ... -
eclipse 透视图切换监听 和 视图激活监听
2012-06-28 16:24 1954<extension point=&q ... -
动态更新或者删除菜单
2012-06-08 12:42 846@Override public void postWind ... -
网址收集
2012-06-07 15:05 581http://wiki.eclipse.org/Platfor ... -
Toggle & Radio menu contributions
2012-06-07 15:04 919转载于:http://blog.eclipse-tips.co ... -
eclilpse check 菜单 --Toggle Handler for Eclipse Commands_1
2012-06-07 14:59 1099转载:http://eclipsesource.com/blo ... -
eclilpse check 菜单 --Toggle Handler for Eclipse Commands
2012-06-07 14:55 1258转载:http://www.ralfebert.de/blog ... -
RCP3.5版本 help所需的依赖包
2012-05-15 15:05 7391. org.apache.lucene 2. ...
相关推荐
This script is used to send the REST API to MuleSoft. MuleSoft will pass the request to Ansible Tower to run the specific template. the related playbook will perform some remedy or query on related ...
一个Java客户端和处理框架,用于使用Google助手创建转换。 API版本2中Webhook请求和响应的序列化/反序列化 不错的api,可在以下支持下定义对话 ssml 文本 建议筹码 基本卡 带注释的处理框架可实现清晰的代码分离 ...
function dhtmlXTreeItemObject(itemId,itemText,parentObject,treeObject,actionHandler,mode,url,target) 并在方法体中添加赋值语句:this.itemURL=url;this.itemTarget=target; 2、然后修改所有与...
GrowingTextView 自动调整UITextView的大小这是一个具有动态height的UITextView。 它还包括最小/最大高度和行号。 设备旋转也得到管理。 当高度大于最大高度时,您可以滚动文本视图。文本视图是为消息应用程序目的而...
AAPullToRefresh *tv = [self.scrollView addPullToRefreshPosition:AAPullToRefreshPositionTop actionHandler:^(AAPullToRefresh *v){ // do something... // then must call stopIndicatorAnimation method. ...
1)执行java代码,比如说创建task instance(任务实例)、发出通知、更新数据库等等。很典型的就是在node 上挂上我们的action 2) 控制流程的执行: A、等待状态:流程进入到这个node时将处于等待状态,直到一个...
主要对Teamcenter Engineering系统中的ITK(Integration Tool Kit)技术以及Windows平台下的VBA技术进行了相关的研究,并且开发了一个新的ActionHandler以及相应的Windows脚本文件,使得Teamcenter Engineering的...
CHQPullToRefresh 基于的 允许您向任何 ScrollView(任何地方!...- ( void )addPullToRefreshWithActionHandler:( void (^)( void ))actionHandler WithConfigurator:(CHQPullToRefreshConfigurator *)configura
PlayerEngine接口不对外开放,防止出现错误的调用,外部想进行播放,暂停,上下切换等操作时,需要通过调用ActionHandler中的execute接口, 并传入对应的枚举类型来执行。 注:MediaBase是准备作为一个jar包存在的,...