Mercurial > projects > dwt-addons
annotate dwtx/jface/action/IAction.d @ 70:46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 22 May 2008 01:36:46 +0200 |
parents | e0f0aaf75edd |
children | 7ffeace6c47f |
rev | line source |
---|---|
4 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2005 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.jface.action.IAction; | |
14 | |
15 import dwtx.jface.action.IMenuCreator; | |
16 | |
17 import dwt.events.HelpListener; | |
18 import dwt.widgets.Event; | |
19 import dwtx.core.commands.IHandlerAttributes; | |
20 import dwtx.jface.resource.ImageDescriptor; | |
21 import dwtx.jface.util.IPropertyChangeListener; | |
22 | |
23 import dwt.dwthelper.utils; | |
24 | |
25 /** | |
26 * An action represents the non-UI side of a command which can be triggered | |
27 * by the end user. Actions are typically associated with buttons, menu items, | |
28 * and items in tool bars. The controls for a command are built by some container, | |
29 * which furnished the context where these controls appear and configures | |
30 * them with data from properties declared by the action. When the end user | |
31 * triggers the command via its control, the action's <code>run</code> | |
32 * method is invoked to do the real work. | |
33 * <p> | |
34 * Actions support a predefined set of properties (and possibly others as well). | |
35 * Clients of an action may register property change listeners so that they get | |
36 * notified whenever the value of a property changes. | |
37 * </p> | |
38 * <p> | |
39 * Clients should subclass the abstract base class <code>Action</code> to define | |
40 * concrete actions rather than implementing <code>IAction</code> from scratch. | |
41 * </p> | |
42 * <p> | |
43 * This interface exists only to define the API for actions. | |
44 * It is not intended to be implemented by clients. | |
45 * </p> | |
46 * | |
47 * @see Action | |
48 */ | |
49 public interface IAction { | |
50 | |
51 /** | |
52 * Action style constant (value <code>0</code>) indicating action style | |
53 * is not specified yet. By default, the action will assume a push button | |
54 * style. If <code>setChecked</code> is called, then the style will change | |
55 * to a check box, or if <code>setMenuCreator</code> is called, then the | |
56 * style will change to a drop down menu. | |
57 * | |
58 * @since 2.1 | |
59 */ | |
16
e0f0aaf75edd
PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
60 public static const int AS_UNSPECIFIED = 0x00; |
4 | 61 |
62 /** | |
63 * Action style constant (value <code>1</code>) indicating action is | |
64 * a simple push button. | |
65 */ | |
16
e0f0aaf75edd
PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
66 public static const int AS_PUSH_BUTTON = 0x01; |
4 | 67 |
68 /** | |
69 * Action style constant (value <code>2</code>) indicating action is | |
70 * a check box (or a toggle button). | |
71 */ | |
16
e0f0aaf75edd
PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
72 public static const int AS_CHECK_BOX = 0x02; |
4 | 73 |
74 /** | |
75 * Action style constant (value <code>4</code>) indicating action is | |
76 * a drop down menu. | |
77 */ | |
16
e0f0aaf75edd
PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
78 public static const int AS_DROP_DOWN_MENU = 0x04; |
4 | 79 |
80 /** | |
81 * Action style constant (value <code>8</code>) indicating action is | |
82 * a radio button. | |
83 * | |
84 * @since 2.1 | |
85 */ | |
16
e0f0aaf75edd
PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
86 public static const int AS_RADIO_BUTTON = 0x08; |
4 | 87 |
88 /** | |
89 * Property name of an action's text (value <code>"text"</code>). | |
90 */ | |
91 public static const String TEXT = "text"; //$NON-NLS-1$ | |
92 | |
93 /** | |
94 * Property name of an action's enabled state | |
95 * (value <code>"enabled"</code>). | |
96 */ | |
97 public static const String ENABLED = "enabled"; //$NON-NLS-1$ | |
98 | |
99 /** | |
100 * Property name of an action's image (value <code>"image"</code>). | |
101 */ | |
102 public static const String IMAGE = "image"; //$NON-NLS-1$ | |
103 | |
104 /** | |
105 * Property name of an action's tooltip text (value <code>"toolTipText"</code>). | |
106 */ | |
107 public static const String TOOL_TIP_TEXT = "toolTipText"; //$NON-NLS-1$ | |
108 | |
109 /** | |
110 * Property name of an action's description (value <code>"description"</code>). | |
111 * Typically the description is shown as a (longer) help text in the status line. | |
112 */ | |
113 public static const String DESCRIPTION = "description"; //$NON-NLS-1$ | |
114 | |
115 /** | |
116 * Property name of an action's checked status (value | |
117 * <code>"checked"</code>). Applicable when the style is | |
118 * <code>AS_CHECK_BOX</code> or <code>AS_RADIO_BUTTON</code>. | |
119 */ | |
120 public static const String CHECKED = "checked"; //$NON-NLS-1$ | |
121 | |
122 /** | |
123 * Property name of an action's success/fail result | |
124 * (value <code>"result"</code>). The values are | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
125 * <code>Boolean.TRUE</code> if running the action succeeded and |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
126 * <code>Boolean.FALSE</code> if running the action failed or did not |
4 | 127 * complete. |
128 * <p> | |
129 * Not all actions report whether they succeed or fail. This property | |
130 * is provided for use by actions that may be invoked by clients that can | |
131 * take advantage of this information when present (for example, actions | |
132 * used in cheat sheets). Clients should always assume that running the | |
133 * action succeeded in the absence of notification to the contrary. | |
134 * </p> | |
135 * | |
136 * @since 3.0 | |
137 */ | |
138 public static const String RESULT = "result"; //$NON-NLS-1$ | |
139 | |
140 /** | |
141 * Property name of an action's handler. Some actions delegate some or all | |
142 * of their behaviour or state to another object. In this case, if the | |
143 * object to which behaviour has been delegated changes, then a property | |
144 * change event should be sent with this name. | |
145 * | |
146 * This is used to support backward compatibility of actions within the | |
147 * commands framework. | |
148 * | |
149 * @since 3.1 | |
150 */ | |
151 public static const String HANDLED = IHandlerAttributes.ATTRIBUTE_HANDLED; | |
152 | |
153 /** | |
154 * Adds a property change listener to this action. | |
155 * Has no effect if an identical listener is already registered. | |
156 * | |
157 * @param listener a property change listener | |
158 */ | |
159 public void addPropertyChangeListener(IPropertyChangeListener listener); | |
160 | |
161 /** | |
162 * Returns the accelerator keycode for this action. | |
163 * The result is the bit-wise OR of zero or more modifier masks | |
164 * and a key, as explained in <code>MenuItem.getAccelerator</code>. | |
165 * | |
166 * @return the accelerator keycode | |
167 * @see dwt.widgets.MenuItem#getAccelerator() | |
168 */ | |
169 public int getAccelerator(); | |
170 | |
171 /** | |
172 * Returns the action definition id of this action. | |
173 * | |
174 * @return the action definition id of this action, or | |
175 * <code>null</code> if none | |
176 * @since 2.0 | |
177 */ | |
178 public String getActionDefinitionId(); | |
179 | |
180 /** | |
181 * Returns the action's description if it has one. | |
182 * Otherwise it returns <code>getToolTipText()</code>. | |
183 * | |
184 * @return a description for the action; may be <code>null</code> | |
185 */ | |
186 public String getDescription(); | |
187 | |
188 /** | |
189 * Returns the disabled image for this action as an image descriptor. | |
190 * <p> | |
191 * This method is associated with the <code>IMAGE</code> property; | |
192 * property change events are reported when its value changes. | |
193 * </p> | |
194 * | |
195 * @return the image, or <code>null</code> if this action has no image | |
196 * @see #IMAGE | |
197 */ | |
198 public ImageDescriptor getDisabledImageDescriptor(); | |
199 | |
200 /** | |
201 * Returns a help listener for this action. | |
202 * | |
203 * @return a help listener for this action | |
204 */ | |
205 public HelpListener getHelpListener(); | |
206 | |
207 /** | |
208 * Returns the hover image for this action as an image descriptor. | |
209 * <p> | |
210 * Hover images will be used on platforms that support changing the image | |
211 * when the user hovers over the item. This method is associated with | |
212 * the <code>IMAGE</code> property; | |
213 * property change events are reported when its value changes. | |
214 * </p> | |
215 * | |
216 * @return the image, or <code>null</code> if this action has no image | |
217 * @see #IMAGE | |
218 */ | |
219 public ImageDescriptor getHoverImageDescriptor(); | |
220 | |
221 /** | |
222 * Returns a unique identifier for this action, or <code>null</code> if it has | |
223 * none. | |
224 * | |
225 * @return the action id, or <code>null</code> if none | |
226 */ | |
227 public String getId(); | |
228 | |
229 /** | |
230 * Returns the image for this action as an image descriptor. | |
231 * <p> | |
232 * This method is associated with the <code>IMAGE</code> property; | |
233 * property change events are reported when its value changes. | |
234 * </p> | |
235 * | |
236 * @return the image, or <code>null</code> if this action has no image | |
237 * @see #IMAGE | |
238 */ | |
239 public ImageDescriptor getImageDescriptor(); | |
240 | |
241 /** | |
242 * Returns the menu creator for this action. | |
243 * | |
244 * @return the menu creator, or <code>null</code> if none | |
245 */ | |
246 public IMenuCreator getMenuCreator(); | |
247 | |
248 /** | |
249 * Return this action's style. | |
250 * | |
251 * @return one of <code>AS_PUSH_BUTTON</code>, <code>AS_CHECK_BOX</code>, | |
252 * <code>AS_RADIO_BUTTON</code> and <code>AS_DROP_DOWN_MENU</code>. | |
253 */ | |
254 public int getStyle(); | |
255 | |
256 /** | |
257 * Returns the text for this action. | |
258 * <p> | |
259 * This method is associated with the <code>TEXT</code> property; | |
260 * property change events are reported when its value changes. | |
261 * </p> | |
262 * | |
263 * @return the text, or <code>null</code> if none | |
264 * @see #TEXT | |
265 */ | |
266 public String getText(); | |
267 | |
268 /** | |
269 * Returns the tool tip text for this action. | |
270 * <p> | |
271 * This method is associated with the <code>TOOL_TIP_TEXT</code> property; | |
272 * property change events are reported when its value changes. | |
273 * </p> | |
274 * | |
275 * @return the tool tip text, or <code>null</code> if none | |
276 * @see #TOOL_TIP_TEXT | |
277 */ | |
278 public String getToolTipText(); | |
279 | |
280 /** | |
281 * Returns the checked status of this action. Applicable only if the style is | |
282 * <code>AS_CHECK_BOX</code> or <code>AS_RADIO_BUTTON</code>. | |
283 * <p> | |
284 * This method is associated with the <code>CHECKED</code> property; | |
285 * property change events are reported when its value changes. | |
286 * </p> | |
287 * | |
288 * @return the checked status | |
289 * @see #CHECKED | |
290 */ | |
291 public bool isChecked(); | |
292 | |
293 /** | |
294 * Returns whether this action is enabled. | |
295 * <p> | |
296 * This method is associated with the <code>ENABLED</code> property; | |
297 * property change events are reported when its value changes. | |
298 * </p> | |
299 * | |
300 * @return <code>true</code> if enabled, and | |
301 * <code>false</code> if disabled | |
302 * @see #ENABLED | |
303 */ | |
304 public bool isEnabled(); | |
305 | |
306 /** | |
307 * Returns whether this action is handled. In the default case, this is | |
308 * always <code>true</code>. However, if the action delegates some of its | |
309 * behaviour to some other object, then this method should answer whether | |
310 * such an object is currently available. | |
311 * | |
312 * @return <code>true</code> if all of the action's behaviour is | |
313 * available; <code>false</code> otherwise. | |
314 * @since 3.1 | |
315 */ | |
316 public bool isHandled(); | |
317 | |
318 /** | |
319 * Removes the given listener from this action. | |
320 * Has no effect if an identical listener is not registered. | |
321 * | |
322 * @param listener a property change listener | |
323 */ | |
324 public void removePropertyChangeListener(IPropertyChangeListener listener); | |
325 | |
326 /** | |
327 * Runs this action. | |
328 * Each action implementation must define the steps needed to carry out this action. | |
329 * The default implementation of this method in <code>Action</code> | |
330 * does nothing. | |
331 */ | |
332 public void run(); | |
333 | |
334 /** | |
335 * Runs this action, passing the triggering DWT event. | |
336 * As of 2.0, <code>ActionContributionItem</code> calls this method | |
337 * instead of <code>run()</code>. | |
338 * The default implementation of this method in <code>Action</code> | |
339 * simply calls <code>run()</code> for backwards compatibility. | |
340 * | |
341 * @param event the DWT event which triggered this action being run | |
342 * @since 2.0 | |
343 */ | |
344 public void runWithEvent(Event event); | |
345 | |
346 /** | |
347 * Sets the action definition id of this action. | |
348 * | |
349 * @param id the action definition id | |
350 * @since 2.0 | |
351 */ | |
352 public void setActionDefinitionId(String id); | |
353 | |
354 /** | |
355 * Sets the checked status of this action. Applicable for the styles | |
356 * <code>AS_CHECK_BOX</code> or <code>AS_RADIO_BUTTON</code>. | |
357 * <p> | |
358 * Fires a property change event for the <code>CHECKED</code> property | |
359 * if the checked status actually changes as a consequence. | |
360 * </p> | |
361 * | |
362 * @param checked the new checked status | |
363 * @see #CHECKED | |
364 */ | |
365 public void setChecked(bool checked); | |
366 | |
367 /** | |
368 * Sets this action's description. | |
369 * Typically the description is shown as a (longer) help text in the status line. | |
370 * <p> | |
371 * Fires a property change event for the <code>DESCRIPTION</code> property | |
372 * if the description actually changes as a consequence. | |
373 * </p> | |
374 * | |
375 * @param text the description, or <code>null</code> to clear the description | |
376 * @see #DESCRIPTION | |
377 */ | |
378 public void setDescription(String text); | |
379 | |
380 /** | |
381 * Sets the disabled image for this action, as an image descriptor. | |
382 * <p> | |
383 * Disabled images will be used on platforms that support changing the image | |
384 * when the item is disabled.Fires a property change event for | |
385 * the <code>IMAGE</code> property | |
386 * if the image actually changes as a consequence. | |
387 * </p> | |
388 * | |
389 * @param newImage the image, or <code>null</code> if this | |
390 * action should not have an image | |
391 * @see #IMAGE | |
392 */ | |
393 public void setDisabledImageDescriptor(ImageDescriptor newImage); | |
394 | |
395 /** | |
396 * Sets the enabled state of this action. | |
397 * <p> | |
398 * When an action is in the enabled state, the control associated with | |
399 * it is active; triggering it will end up inkoking this action's | |
400 * <code>run</code> method. | |
401 * </p> | |
402 * <p> | |
403 * Fires a property change event for the <code>ENABLED</code> property | |
404 * if the enabled state actually changes as a consequence. | |
405 * </p> | |
406 * | |
407 * @param enabled <code>true</code> to enable, and | |
408 * <code>false</code> to disable | |
409 * @see #ENABLED | |
410 */ | |
411 public void setEnabled(bool enabled); | |
412 | |
413 /** | |
414 * Sets a help listener for this action. | |
415 * | |
416 * @param listener a help listener for this action | |
417 */ | |
418 public void setHelpListener(HelpListener listener); | |
419 | |
420 /** | |
421 * Sets the hover image for this action, as an image descriptor. | |
422 * <p> | |
423 * Hover images will be used on platforms that support changing the image | |
424 * when the user hovers over the item.Fires a property change event for | |
425 * the <code>IMAGE</code> property | |
426 * if the image actually changes as a consequence. | |
427 * </p> | |
428 * | |
429 * @param newImage the image, or <code>null</code> if this | |
430 * action should not have an image | |
431 * @see #IMAGE | |
432 */ | |
433 public void setHoverImageDescriptor(ImageDescriptor newImage); | |
434 | |
435 /** | |
436 * Sets the unique identifier for this action. This is used to identify actions | |
437 * when added to a contribution manager. | |
438 * It should be set when the action is created. It should not be modified once | |
439 * the action is part of an action contribution item. | |
440 * | |
441 * @param id the action id | |
442 * | |
443 * @see ActionContributionItem | |
444 * @see IContributionItem#getId | |
445 */ | |
446 public void setId(String id); | |
447 | |
448 /** | |
449 * Sets the image for this action, as an image descriptor. | |
450 * <p> | |
451 * Fires a property change event for the <code>IMAGE</code> property | |
452 * if the image actually changes as a consequence. | |
453 * </p> | |
454 * | |
455 * @param newImage the image, or <code>null</code> if this | |
456 * action should not have an image | |
457 * @see #IMAGE | |
458 */ | |
459 public void setImageDescriptor(ImageDescriptor newImage); | |
460 | |
461 /** | |
462 * Sets the menu creator for this action. Applicable for style | |
463 * <code>AS_DROP_DOWN_MENU</code>. | |
464 * | |
465 * @param creator the menu creator, or <code>null</code> if none | |
466 */ | |
467 public void setMenuCreator(IMenuCreator creator); | |
468 | |
469 /** | |
470 * Sets the text for this action. | |
471 * <p> | |
472 * An accelerator specification may follow the actual text, separated from it by | |
473 * an '@' or a '\t' character. An accelerator specification consists of zero or more | |
474 * modifier tokens followed by a key code token. The tokens are separated by a '+' character. | |
475 * </p> | |
476 * <p> | |
477 * Fires a property change event for the <code>TEXT</code> property | |
478 * if the text actually changes as a consequence. | |
479 * </p> | |
480 * | |
481 * @param text the text, or <code>null</code> if none | |
482 * @see #TEXT | |
483 * @see Action#findModifier | |
484 * @see Action#findKeyCode | |
485 */ | |
486 public void setText(String text); | |
487 | |
488 /** | |
489 * Sets the tool tip text for this action. | |
490 * <p> | |
491 * Fires a property change event for the <code>TOOL_TIP_TEXT</code> property | |
492 * if the tool tip text actually changes as a consequence. | |
493 * </p> | |
494 * | |
495 * @param text the tool tip text, or <code>null</code> if none | |
496 * @see #TOOL_TIP_TEXT | |
497 */ | |
498 public void setToolTipText(String text); | |
499 | |
500 /** | |
501 * <p> | |
502 * Sets the accelerator keycode that this action maps to. This is a bitwise OR | |
503 * of zero or more DWT key modifier masks (i.e. DWT.CTRL or DWT.ALT) and a | |
504 * character code. For example, for Ctrl+Z, use <code>DWT.CTRL | 'Z'</code>. | |
505 * Use 0 for no accelerator. | |
506 * </p> | |
507 * <p> | |
508 * This method should no longer be used for actions in the Eclipse workbench. | |
509 * <code>IWorkbenchCommandSupport</code> and | |
510 * <code>IWorkbenchContextSupport</code> provide all the functionality | |
511 * required for key bindings. If you set an accelerator using this method, then | |
512 * it will not work in the workbench if it conflicts any existing key binding, | |
513 * or if there is a different key binding defined for this action's definition | |
514 * id. The definition id should be used instead -- referring to the command in | |
515 * the workbench from which the key binding should be retrieved. | |
516 * </p> | |
517 * | |
518 * @param keycode | |
519 * the keycode to be accepted. | |
520 */ | |
521 public void setAccelerator(int keycode); | |
522 } |