KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > action > IAction


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  *******************************************************************************/

11 package org.eclipse.jface.action;
12
13 import org.eclipse.core.commands.IHandlerAttributes;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.jface.util.IPropertyChangeListener;
16 import org.eclipse.swt.events.HelpListener;
17 import org.eclipse.swt.widgets.Event;
18
19 /**
20  * An action represents the non-UI side of a command which can be triggered
21  * by the end user. Actions are typically associated with buttons, menu items,
22  * and items in tool bars. The controls for a command are built by some container,
23  * which furnished the context where these controls appear and configures
24  * them with data from properties declared by the action. When the end user
25  * triggers the command via its control, the action's <code>run</code>
26  * method is invoked to do the real work.
27  * <p>
28  * Actions support a predefined set of properties (and possibly others as well).
29  * Clients of an action may register property change listeners so that they get
30  * notified whenever the value of a property changes.
31  * </p>
32  * <p>
33  * Clients should subclass the abstract base class <code>Action</code> to define
34  * concrete actions rather than implementing <code>IAction</code> from scratch.
35  * </p>
36  * <p>
37  * This interface exists only to define the API for actions.
38  * It is not intended to be implemented by clients.
39  * </p>
40  *
41  * @see Action
42  */

43 public interface IAction {
44
45     /**
46      * Action style constant (value <code>0</code>) indicating action style
47      * is not specified yet. By default, the action will assume a push button
48      * style. If <code>setChecked</code> is called, then the style will change
49      * to a check box, or if <code>setMenuCreator</code> is called, then the
50      * style will change to a drop down menu.
51      *
52      * @since 2.1
53      */

54     public static int AS_UNSPECIFIED = 0x00;
55
56     /**
57      * Action style constant (value <code>1</code>) indicating action is
58      * a simple push button.
59      */

60     public static int AS_PUSH_BUTTON = 0x01;
61
62     /**
63      * Action style constant (value <code>2</code>) indicating action is
64      * a check box (or a toggle button).
65      */

66     public static int AS_CHECK_BOX = 0x02;
67
68     /**
69      * Action style constant (value <code>4</code>) indicating action is
70      * a drop down menu.
71      */

72     public static int AS_DROP_DOWN_MENU = 0x04;
73
74     /**
75      * Action style constant (value <code>8</code>) indicating action is
76      * a radio button.
77      *
78      * @since 2.1
79      */

80     public static int AS_RADIO_BUTTON = 0x08;
81
82     /**
83      * Property name of an action's text (value <code>"text"</code>).
84      */

85     public static final String JavaDoc TEXT = "text"; //$NON-NLS-1$
86

87     /**
88      * Property name of an action's enabled state
89      * (value <code>"enabled"</code>).
90      */

91     public static final String JavaDoc ENABLED = "enabled"; //$NON-NLS-1$
92

93     /**
94      * Property name of an action's image (value <code>"image"</code>).
95      */

96     public static final String JavaDoc IMAGE = "image"; //$NON-NLS-1$
97

98     /**
99      * Property name of an action's tooltip text (value <code>"toolTipText"</code>).
100      */

101     public static final String JavaDoc TOOL_TIP_TEXT = "toolTipText"; //$NON-NLS-1$
102

103     /**
104      * Property name of an action's description (value <code>"description"</code>).
105      * Typically the description is shown as a (longer) help text in the status line.
106      */

107     public static final String JavaDoc DESCRIPTION = "description"; //$NON-NLS-1$
108

109     /**
110      * Property name of an action's checked status (value
111      * <code>"checked"</code>). Applicable when the style is
112      * <code>AS_CHECK_BOX</code> or <code>AS_RADIO_BUTTON</code>.
113      */

114     public static final String JavaDoc CHECKED = "checked"; //$NON-NLS-1$
115

116     /**
117      * Property name of an action's success/fail result
118      * (value <code>"result"</code>). The values are
119      * <code>Boolean.TRUE</code> if running the action succeeded and
120      * <code>Boolean.FALSE</code> if running the action failed or did not
121      * complete.
122      * <p>
123      * Not all actions report whether they succeed or fail. This property
124      * is provided for use by actions that may be invoked by clients that can
125      * take advantage of this information when present (for example, actions
126      * used in cheat sheets). Clients should always assume that running the
127      * action succeeded in the absence of notification to the contrary.
128      * </p>
129      *
130      * @since 3.0
131      */

132     public static final String JavaDoc RESULT = "result"; //$NON-NLS-1$
133

134     /**
135      * Property name of an action's handler. Some actions delegate some or all
136      * of their behaviour or state to another object. In this case, if the
137      * object to which behaviour has been delegated changes, then a property
138      * change event should be sent with this name.
139      *
140      * This is used to support backward compatibility of actions within the
141      * commands framework.
142      *
143      * @since 3.1
144      */

145     public static final String JavaDoc HANDLED = IHandlerAttributes.ATTRIBUTE_HANDLED;
146
147     /**
148      * Adds a property change listener to this action.
149      * Has no effect if an identical listener is already registered.
150      *
151      * @param listener a property change listener
152      */

153     public void addPropertyChangeListener(IPropertyChangeListener listener);
154
155     /**
156      * Returns the accelerator keycode for this action.
157      * The result is the bit-wise OR of zero or more modifier masks
158      * and a key, as explained in <code>MenuItem.getAccelerator</code>.
159      *
160      * @return the accelerator keycode
161      * @see org.eclipse.swt.widgets.MenuItem#getAccelerator()
162      */

163     public int getAccelerator();
164
165     /**
166      * Returns the action definition id of this action.
167      *
168      * @return the action definition id of this action, or
169      * <code>null</code> if none
170      * @since 2.0
171      */

172     public String JavaDoc getActionDefinitionId();
173
174     /**
175      * Returns the action's description if it has one.
176      * Otherwise it returns <code>getToolTipText()</code>.
177      *
178      * @return a description for the action; may be <code>null</code>
179      */

180     public String JavaDoc getDescription();
181
182     /**
183      * Returns the disabled image for this action as an image descriptor.
184      * <p>
185      * This method is associated with the <code>IMAGE</code> property;
186      * property change events are reported when its value changes.
187      * </p>
188      *
189      * @return the image, or <code>null</code> if this action has no image
190      * @see #IMAGE
191      */

192     public ImageDescriptor getDisabledImageDescriptor();
193
194     /**
195      * Returns a help listener for this action.
196      *
197      * @return a help listener for this action
198      */

199     public HelpListener getHelpListener();
200
201     /**
202      * Returns the hover image for this action as an image descriptor.
203      * <p>
204      * Hover images will be used on platforms that support changing the image
205      * when the user hovers over the item. This method is associated with
206      * the <code>IMAGE</code> property;
207      * property change events are reported when its value changes.
208      * </p>
209      *
210      * @return the image, or <code>null</code> if this action has no image
211      * @see #IMAGE
212      */

213     public ImageDescriptor getHoverImageDescriptor();
214
215     /**
216      * Returns a unique identifier for this action, or <code>null</code> if it has
217      * none.
218      *
219      * @return the action id, or <code>null</code> if none
220      */

221     public String JavaDoc getId();
222
223     /**
224      * Returns the image for this action as an image descriptor.
225      * <p>
226      * This method is associated with the <code>IMAGE</code> property;
227      * property change events are reported when its value changes.
228      * </p>
229      *
230      * @return the image, or <code>null</code> if this action has no image
231      * @see #IMAGE
232      */

233     public ImageDescriptor getImageDescriptor();
234
235     /**
236      * Returns the menu creator for this action.
237      *
238      * @return the menu creator, or <code>null</code> if none
239      */

240     public IMenuCreator getMenuCreator();
241
242     /**
243      * Return this action's style.
244      *
245      * @return one of <code>AS_PUSH_BUTTON</code>, <code>AS_CHECK_BOX</code>,
246      * <code>AS_RADIO_BUTTON</code> and <code>AS_DROP_DOWN_MENU</code>.
247      */

248     public int getStyle();
249
250     /**
251      * Returns the text for this action.
252      * <p>
253      * This method is associated with the <code>TEXT</code> property;
254      * property change events are reported when its value changes.
255      * </p>
256      *
257      * @return the text, or <code>null</code> if none
258      * @see #TEXT
259      */

260     public String JavaDoc getText();
261
262     /**
263      * Returns the tool tip text for this action.
264      * <p>
265      * This method is associated with the <code>TOOL_TIP_TEXT</code> property;
266      * property change events are reported when its value changes.
267      * </p>
268      *
269      * @return the tool tip text, or <code>null</code> if none
270      * @see #TOOL_TIP_TEXT
271      */

272     public String JavaDoc getToolTipText();
273
274     /**
275      * Returns the checked status of this action. Applicable only if the style is
276      * <code>AS_CHECK_BOX</code> or <code>AS_RADIO_BUTTON</code>.
277      * <p>
278      * This method is associated with the <code>CHECKED</code> property;
279      * property change events are reported when its value changes.
280      * </p>
281      *
282      * @return the checked status
283      * @see #CHECKED
284      */

285     public boolean isChecked();
286
287     /**
288      * Returns whether this action is enabled.
289      * <p>
290      * This method is associated with the <code>ENABLED</code> property;
291      * property change events are reported when its value changes.
292      * </p>
293      *
294      * @return <code>true</code> if enabled, and
295      * <code>false</code> if disabled
296      * @see #ENABLED
297      */

298     public boolean isEnabled();
299
300     /**
301      * Returns whether this action is handled. In the default case, this is
302      * always <code>true</code>. However, if the action delegates some of its
303      * behaviour to some other object, then this method should answer whether
304      * such an object is currently available.
305      *
306      * @return <code>true</code> if all of the action's behaviour is
307      * available; <code>false</code> otherwise.
308      * @since 3.1
309      */

310     public boolean isHandled();
311
312     /**
313      * Removes the given listener from this action.
314      * Has no effect if an identical listener is not registered.
315      *
316      * @param listener a property change listener
317      */

318     public void removePropertyChangeListener(IPropertyChangeListener listener);
319
320     /**
321      * Runs this action.
322      * Each action implementation must define the steps needed to carry out this action.
323      * The default implementation of this method in <code>Action</code>
324      * does nothing.
325      */

326     public void run();
327
328     /**
329      * Runs this action, passing the triggering SWT event.
330      * As of 2.0, <code>ActionContributionItem</code> calls this method
331      * instead of <code>run()</code>.
332      * The default implementation of this method in <code>Action</code>
333      * simply calls <code>run()</code> for backwards compatibility.
334      *
335      * @param event the SWT event which triggered this action being run
336      * @since 2.0
337      */

338     public void runWithEvent(Event event);
339
340     /**
341      * Sets the action definition id of this action.
342      *
343      * @param id the action definition id
344      * @since 2.0
345      */

346     public void setActionDefinitionId(String JavaDoc id);
347
348     /**
349      * Sets the checked status of this action. Applicable for the styles
350      * <code>AS_CHECK_BOX</code> or <code>AS_RADIO_BUTTON</code>.
351      * <p>
352      * Fires a property change event for the <code>CHECKED</code> property
353      * if the checked status actually changes as a consequence.
354      * </p>
355      *
356      * @param checked the new checked status
357      * @see #CHECKED
358      */

359     public void setChecked(boolean checked);
360
361     /**
362      * Sets this action's description.
363      * Typically the description is shown as a (longer) help text in the status line.
364      * <p>
365      * Fires a property change event for the <code>DESCRIPTION</code> property
366      * if the description actually changes as a consequence.
367      * </p>
368      *
369      * @param text the description, or <code>null</code> to clear the description
370      * @see #DESCRIPTION
371      */

372     public void setDescription(String JavaDoc text);
373
374     /**
375      * Sets the disabled image for this action, as an image descriptor.
376      * <p>
377      * Disabled images will be used on platforms that support changing the image
378      * when the item is disabled.Fires a property change event for
379      * the <code>IMAGE</code> property
380      * if the image actually changes as a consequence.
381      * </p>
382      *
383      * @param newImage the image, or <code>null</code> if this
384      * action should not have an image
385      * @see #IMAGE
386      */

387     public void setDisabledImageDescriptor(ImageDescriptor newImage);
388
389     /**
390      * Sets the enabled state of this action.
391      * <p>
392      * When an action is in the enabled state, the control associated with
393      * it is active; triggering it will end up inkoking this action's
394      * <code>run</code> method.
395      * </p>
396      * <p>
397      * Fires a property change event for the <code>ENABLED</code> property
398      * if the enabled state actually changes as a consequence.
399      * </p>
400      *
401      * @param enabled <code>true</code> to enable, and
402      * <code>false</code> to disable
403      * @see #ENABLED
404      */

405     public void setEnabled(boolean enabled);
406
407     /**
408      * Sets a help listener for this action.
409      *
410      * @param listener a help listener for this action
411      */

412     public void setHelpListener(HelpListener listener);
413
414     /**
415      * Sets the hover image for this action, as an image descriptor.
416      * <p>
417      * Hover images will be used on platforms that support changing the image
418      * when the user hovers over the item.Fires a property change event for
419      * the <code>IMAGE</code> property
420      * if the image actually changes as a consequence.
421      * </p>
422      *
423      * @param newImage the image, or <code>null</code> if this
424      * action should not have an image
425      * @see #IMAGE
426      */

427     public void setHoverImageDescriptor(ImageDescriptor newImage);
428
429     /**
430      * Sets the unique identifier for this action. This is used to identify actions
431      * when added to a contribution manager.
432      * It should be set when the action is created. It should not be modified once
433      * the action is part of an action contribution item.
434      *
435      * @param id the action id
436      *
437      * @see ActionContributionItem
438      * @see IContributionItem#getId
439      */

440     public void setId(String JavaDoc id);
441
442     /**
443      * Sets the image for this action, as an image descriptor.
444      * <p>
445      * Fires a property change event for the <code>IMAGE</code> property
446      * if the image actually changes as a consequence.
447      * </p>
448      *
449      * @param newImage the image, or <code>null</code> if this
450      * action should not have an image
451      * @see #IMAGE
452      */

453     public void setImageDescriptor(ImageDescriptor newImage);
454
455     /**
456      * Sets the menu creator for this action. Applicable for style
457      * <code>AS_DROP_DOWN_MENU</code>.
458      *
459      * @param creator the menu creator, or <code>null</code> if none
460      */

461     public void setMenuCreator(IMenuCreator creator);
462
463     /**
464      * Sets the text for this action.
465      * <p>
466      * An accelerator specification may follow the actual text, separated from it by
467      * an '@' or a '\t' character. An accelerator specification consists of zero or more
468      * modifier tokens followed by a key code token. The tokens are separated by a '+' character.
469      * </p>
470      * <p>
471      * Fires a property change event for the <code>TEXT</code> property
472      * if the text actually changes as a consequence.
473      * </p>
474      *
475      * @param text the text, or <code>null</code> if none
476      * @see #TEXT
477      * @see Action#findModifier
478      * @see Action#findKeyCode
479      */

480     public void setText(String JavaDoc text);
481
482     /**
483      * Sets the tool tip text for this action.
484      * <p>
485      * Fires a property change event for the <code>TOOL_TIP_TEXT</code> property
486      * if the tool tip text actually changes as a consequence.
487      * </p>
488      *
489      * @param text the tool tip text, or <code>null</code> if none
490      * @see #TOOL_TIP_TEXT
491      */

492     public void setToolTipText(String JavaDoc text);
493
494     /**
495      * <p>
496      * Sets the accelerator keycode that this action maps to. This is a bitwise OR
497      * of zero or more SWT key modifier masks (i.e. SWT.CTRL or SWT.ALT) and a
498      * character code. For example, for Ctrl+Z, use <code>SWT.CTRL | 'Z'</code>.
499      * Use 0 for no accelerator.
500      * </p>
501      * <p>
502      * This method should no longer be used for actions in the Eclipse workbench.
503      * <code>IWorkbenchCommandSupport</code> and
504      * <code>IWorkbenchContextSupport</code> provide all the functionality
505      * required for key bindings. If you set an accelerator using this method, then
506      * it will not work in the workbench if it conflicts any existing key binding,
507      * or if there is a different key binding defined for this action's definition
508      * id. The definition id should be used instead -- referring to the command in
509      * the workbench from which the key binding should be retrieved.
510      * </p>
511      *
512      * @param keycode
513      * the keycode to be accepted.
514      */

515     public void setAccelerator(int keycode);
516 }
517
Popular Tags