comparison org.eclipse.jface/src/org/eclipse/jface/action/IAction.d @ 12:bc29606a740c

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