Mercurial > projects > dwt-addons
comparison dwtx/core/commands/AbstractHandler.d @ 3:6518c18a01f7
eclipse.core package without osgi dependencies
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 26 Mar 2008 00:57:19 +0100 |
parents | |
children | 46a6e0e6ccd4 |
comparison
equal
deleted
inserted
replaced
2:a012107a911c | 3:6518c18a01f7 |
---|---|
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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.core.commands.AbstractHandler; | |
14 | |
15 import dwtx.core.commands.common.EventManager; | |
16 import dwtx.core.commands.IHandler; | |
17 import dwtx.core.commands.IHandlerListener; | |
18 import dwtx.core.commands.HandlerEvent; | |
19 | |
20 import dwt.dwthelper.utils; | |
21 | |
22 /** | |
23 * <p> | |
24 * This class is a partial implementation of <code>IHandler</code>. This | |
25 * abstract implementation provides support for handler listeners. You should | |
26 * subclass from this method unless you want to implement your own listener | |
27 * support. Subclasses should call | |
28 * {@link AbstractHandler#fireHandlerChanged(HandlerEvent)}when the handler | |
29 * changes. Subclasses can also override {@link AbstractHandler#isEnabled()} and | |
30 * {@link AbstractHandler#isHandled()}. | |
31 * </p> | |
32 * | |
33 * @since 3.1 | |
34 */ | |
35 public abstract class AbstractHandler : EventManager, IHandler { | |
36 | |
37 /** | |
38 * @see IHandler#addHandlerListener(IHandlerListener) | |
39 */ | |
40 public void addHandlerListener(IHandlerListener handlerListener) { | |
41 addListenerObject(cast(Object)handlerListener); | |
42 } | |
43 | |
44 /** | |
45 * The default implementation does nothing. Subclasses who attach listeners | |
46 * to other objects are encouraged to detach them in this method. | |
47 * | |
48 * @see dwtx.core.commands.IHandler#dispose() | |
49 */ | |
50 public void dispose() { | |
51 // Do nothing. | |
52 } | |
53 | |
54 /** | |
55 * Fires an event to all registered listeners describing changes to this | |
56 * instance. | |
57 * <p> | |
58 * Subclasses may extend the definition of this method (i.e., if a different | |
59 * type of listener can be attached to a subclass). This is used primarily | |
60 * for support of <code>AbstractHandler</code> in | |
61 * <code>dwtx.ui.workbench</code>, and clients should be wary of | |
62 * overriding this behaviour. If this method is overridden, then the first | |
63 * line of the method should be "<code>super.fireHandlerChanged(handlerEvent);</code>". | |
64 * </p> | |
65 * | |
66 * @param handlerEvent | |
67 * the event describing changes to this instance. Must not be | |
68 * <code>null</code>. | |
69 */ | |
70 protected void fireHandlerChanged(HandlerEvent handlerEvent) { | |
71 if (handlerEvent is null) { | |
72 throw new NullPointerException(); | |
73 } | |
74 | |
75 Object[] listeners = getListeners(); | |
76 for (int i = 0; i < listeners.length; i++) { | |
77 IHandlerListener listener = cast(IHandlerListener) listeners[i]; | |
78 listener.handlerChanged(handlerEvent); | |
79 } | |
80 } | |
81 | |
82 /** | |
83 * Whether this handler is capable of executing at this time. Subclasses may | |
84 * override this method. | |
85 * | |
86 * @return <code>true</code> | |
87 */ | |
88 public bool isEnabled() { | |
89 return true; | |
90 } | |
91 | |
92 /** | |
93 * Whether this handler is capable of handling delegated responsibilities at | |
94 * this time. Subclasses may override this method. | |
95 * | |
96 * @return <code>true</code> | |
97 */ | |
98 public bool isHandled() { | |
99 return true; | |
100 } | |
101 | |
102 /** | |
103 * <p> | |
104 * Returns true iff there is one or more IHandlerListeners attached to this | |
105 * AbstractHandler. | |
106 * </p> | |
107 * <p> | |
108 * Subclasses may extend the definition of this method (i.e., if a different | |
109 * type of listener can be attached to a subclass). This is used primarily | |
110 * for support of <code>AbstractHandler</code> in | |
111 * <code>dwtx.ui.workbench</code>, and clients should be wary of | |
112 * overriding this behaviour. If this method is overridden, then the return | |
113 * value should include "<code>super.hasListeners() ||</code>". | |
114 * </p> | |
115 * | |
116 * @return true iff there is one or more IHandlerListeners attached to this | |
117 * AbstractHandler | |
118 */ | |
119 protected bool hasListeners() { | |
120 return isListenerAttached(); | |
121 } | |
122 | |
123 /** | |
124 * @see IHandler#removeHandlerListener(IHandlerListener) | |
125 */ | |
126 public void removeHandlerListener(IHandlerListener handlerListener) { | |
127 removeListenerObject(cast(Object)handlerListener); | |
128 } | |
129 } |