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