All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.jface.action.IAction Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2000, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jface.action;

import org.eclipse.core.commands.IHandlerAttributes;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.pde.api.tools.annotations.NoImplement;
import org.eclipse.swt.events.HelpListener;
import org.eclipse.swt.widgets.Event;

/**
 * An action represents the non-UI side of a command which can be triggered
 * by the end user. Actions are typically associated with buttons, menu items,
 * and items in tool bars. The controls for a command are built by some container,
 * which furnished the context where these controls appear and configures
 * them with data from properties declared by the action. When the end user
 * triggers the command via its control, the action's run
 * method is invoked to do the real work.
 * 

* Actions support a predefined set of properties (and possibly others as well). * Clients of an action may register property change listeners so that they get * notified whenever the value of a property changes. *

*

* Clients should subclass the abstract base class Action to define * concrete actions rather than implementing IAction from scratch. *

*

* This interface exists only to define the API for actions. * It is not intended to be implemented by clients. *

* * @see Action */ @NoImplement public interface IAction { /** * Action style constant (value 0) indicating action style * is not specified yet. By default, the action will assume a push button * style. If setChecked is called, then the style will change * to a check box, or if setMenuCreator is called, then the * style will change to a drop down menu. * * @since 2.1 */ int AS_UNSPECIFIED = 0x00; /** * Action style constant (value 1) indicating action is * a simple push button. */ int AS_PUSH_BUTTON = 0x01; /** * Action style constant (value 2) indicating action is * a check box (or a toggle button). *

* Note: The action is also run when a check box gets * deselected. Use {@link #isChecked} to determine the selection state. *

*/ int AS_CHECK_BOX = 0x02; /** * Action style constant (value 4) indicating action is * a drop down menu. */ int AS_DROP_DOWN_MENU = 0x04; /** * Action style constant (value 8) indicating action is * a radio button. *

* Note: When a radio button gets selected, the action for * the unselected radio button will also be run. Use {@link #isChecked} to * determine the selection state. *

* * @since 2.1 */ int AS_RADIO_BUTTON = 0x08; /** * Property name of an action's text (value "text"). */ String TEXT = "text"; //$NON-NLS-1$ /** * Property name of an action's enabled state * (value "enabled"). */ String ENABLED = "enabled"; //$NON-NLS-1$ /** * Property name of an action's image (value "image"). */ String IMAGE = "image"; //$NON-NLS-1$ /** * Property name of an action's tooltip text (value "toolTipText"). */ String TOOL_TIP_TEXT = "toolTipText"; //$NON-NLS-1$ /** * Property name of an action's description (value "description"). * Typically the description is shown as a (longer) help text in the status line. */ String DESCRIPTION = "description"; //$NON-NLS-1$ /** * Property name of an action's checked status (value * "checked"). Applicable when the style is * AS_CHECK_BOX or AS_RADIO_BUTTON. */ String CHECKED = "checked"; //$NON-NLS-1$ /** * Property name of an action's success/fail result * (value "result"). The values are * Boolean.TRUE if running the action succeeded and * Boolean.FALSE if running the action failed or did not * complete. *

* Not all actions report whether they succeed or fail. This property * is provided for use by actions that may be invoked by clients that can * take advantage of this information when present (for example, actions * used in cheat sheets). Clients should always assume that running the * action succeeded in the absence of notification to the contrary. *

* * @since 3.0 */ String RESULT = "result"; //$NON-NLS-1$ /** * Property name of an action's handler. Some actions delegate some or all * of their behaviour or state to another object. In this case, if the * object to which behaviour has been delegated changes, then a property * change event should be sent with this name. * * This is used to support backward compatibility of actions within the * commands framework. * * @since 3.1 */ String HANDLED = IHandlerAttributes.ATTRIBUTE_HANDLED; /** * Adds a property change listener to this action. * Has no effect if an identical listener is already registered. * * @param listener a property change listener */ void addPropertyChangeListener(IPropertyChangeListener listener); /** * Returns the accelerator keycode for this action. * The result is the bit-wise OR of zero or more modifier masks * and a key, as explained in MenuItem.getAccelerator. * * @return the accelerator keycode * @see org.eclipse.swt.widgets.MenuItem#getAccelerator() */ int getAccelerator(); /** * Returns the action definition id of this action. * * @return the action definition id of this action, or * null if none * @since 2.0 */ String getActionDefinitionId(); /** * Returns the action's description if it has one. * Otherwise it returns getToolTipText(). * * @return a description for the action; may be null */ String getDescription(); /** * Returns the disabled image for this action as an image descriptor. *

* This method is associated with the IMAGE property; * property change events are reported when its value changes. *

* * @return the image, or null if this action has no image * @see #IMAGE */ ImageDescriptor getDisabledImageDescriptor(); /** * Returns a help listener for this action. * * @return a help listener for this action */ HelpListener getHelpListener(); /** * Returns the hover image for this action as an image descriptor. *

* Hover images will be used on platforms that support changing the image * when the user hovers over the item. This method is associated with * the IMAGE property; * property change events are reported when its value changes. *

* * @return the image, or null if this action has no image * @see #IMAGE */ ImageDescriptor getHoverImageDescriptor(); /** * Returns a unique identifier for this action, or null if it has * none. * * @return the action id, or null if none */ String getId(); /** * Returns the image for this action as an image descriptor. *

* This method is associated with the IMAGE property; * property change events are reported when its value changes. *

* * @return the image, or null if this action has no image * @see #IMAGE */ ImageDescriptor getImageDescriptor(); /** * Returns the menu creator for this action. * * @return the menu creator, or null if none */ IMenuCreator getMenuCreator(); /** * Return this action's style. * * @return one of AS_PUSH_BUTTON, AS_CHECK_BOX, * AS_RADIO_BUTTON and AS_DROP_DOWN_MENU. */ int getStyle(); /** * Returns the text for this action. *

* This method is associated with the TEXT property; * property change events are reported when its value changes. *

* * @return the text, or null if none * @see #TEXT */ String getText(); /** * Returns the tool tip text for this action. *

* This method is associated with the TOOL_TIP_TEXT property; * property change events are reported when its value changes. *

* * @return the tool tip text, or null if none * @see #TOOL_TIP_TEXT */ String getToolTipText(); /** * Returns the checked status of this action. Applicable only if the style is * AS_CHECK_BOX or AS_RADIO_BUTTON. *

* This method is associated with the CHECKED property; * property change events are reported when its value changes. *

* * @return the checked status * @see #CHECKED */ boolean isChecked(); /** * Returns whether this action is enabled. *

* This method is associated with the ENABLED property; * property change events are reported when its value changes. *

* * @return true if enabled, and * false if disabled * @see #ENABLED */ boolean isEnabled(); /** * Returns whether this action is handled. In the default case, this is * always true. However, if the action delegates some of its * behaviour to some other object, then this method should answer whether * such an object is currently available. * * @return true if all of the action's behaviour is * available; false otherwise. * @since 3.1 */ boolean isHandled(); /** * Removes the given listener from this action. * Has no effect if an identical listener is not registered. * * @param listener a property change listener */ void removePropertyChangeListener(IPropertyChangeListener listener); /** * Runs this action. * Each action implementation must define the steps needed to carry out this action. * The default implementation of this method in Action * does nothing. * * @see #AS_RADIO_BUTTON How radio buttons are handled * @see #AS_CHECK_BOX How check boxes are handled */ void run(); /** * Runs this action, passing the triggering SWT event. * As of 2.0, ActionContributionItem calls this method * instead of run(). * The default implementation of this method in Action * simply calls run() for backwards compatibility. * * @param event the SWT event which triggered this action being run * @since 2.0 * * @see #AS_RADIO_BUTTON How radio buttons are handled * @see #AS_CHECK_BOX How check boxes are handled */ void runWithEvent(Event event); /** * Sets the action definition id of this action. * * @param id the action definition id * @since 2.0 */ void setActionDefinitionId(String id); /** * Sets the checked status of this action. Applicable for the styles * AS_CHECK_BOX or AS_RADIO_BUTTON. *

* Fires a property change event for the CHECKED property * if the checked status actually changes as a consequence. *

* * @param checked the new checked status * @see #CHECKED */ void setChecked(boolean checked); /** * Sets this action's description. * Typically the description is shown as a (longer) help text in the status line. *

* Fires a property change event for the DESCRIPTION property * if the description actually changes as a consequence. *

* * @param text the description, or null to clear the description * @see #DESCRIPTION */ void setDescription(String text); /** * Sets the disabled image for this action, as an image descriptor. *

* Disabled images will be used on platforms that support changing the image * when the item is disabled.Fires a property change event for * the IMAGE property * if the image actually changes as a consequence. *

* * @param newImage the image, or null if this * action should not have an image * @see #IMAGE */ void setDisabledImageDescriptor(ImageDescriptor newImage); /** * Sets the enabled state of this action. *

* When an action is in the enabled state, the control associated with * it is active; triggering it will end up inkoking this action's * run method. *

*

* Fires a property change event for the ENABLED property * if the enabled state actually changes as a consequence. *

* * @param enabled true to enable, and * false to disable * @see #ENABLED */ void setEnabled(boolean enabled); /** * Sets a help listener for this action. * * @param listener a help listener for this action */ void setHelpListener(HelpListener listener); /** * Sets the hover image for this action, as an image descriptor. *

* Hover images will be used on platforms that support changing the image * when the user hovers over the item.Fires a property change event for * the IMAGE property * if the image actually changes as a consequence. *

* * @param newImage the image, or null if this * action should not have an image * @see #IMAGE */ void setHoverImageDescriptor(ImageDescriptor newImage); /** * Sets the unique identifier for this action. This is used to identify actions * when added to a contribution manager. * It should be set when the action is created. It should not be modified once * the action is part of an action contribution item. * * @param id the action id * * @see ActionContributionItem * @see IContributionItem#getId */ void setId(String id); /** * Sets the image for this action, as an image descriptor. *

* Fires a property change event for the IMAGE property if the * image actually changes as a consequence. *

*

* Note: This operation is a hint and is not supported in all contexts on * platforms that do not have this concept (for example, Windows NT). * Furthermore, some platforms (such as GTK), cannot display both a check * box and an image at the same time. Instead, they hide the image and * display the check box. *

* * @param newImage * the image, or null if this action should not have * an image * @see #IMAGE */ void setImageDescriptor(ImageDescriptor newImage); /** * Sets the menu creator for this action. Applicable for style * AS_DROP_DOWN_MENU. * * @param creator the menu creator, or null if none */ void setMenuCreator(IMenuCreator creator); /** * Sets the text for this action. *

* An accelerator is identified by the last index of a '\t' character. If * there are no '\t' characters, then it is identified by the last index of an * '@' character. If neither, then there is no accelerator text. Note that * if you want to insert an '@' character into the text (but no accelerator), * then you can simply insert an '@' or a '\t' at the end of the text. *
* An accelerator specification consists of zero or more * modifier tokens followed by a key code token. The tokens are separated by a '+' character. *

*

* Fires a property change event for the TEXT property * if the text actually changes as a consequence. *

* * @param text the text, or null if none * @see #TEXT * @see Action#findModifier * @see Action#findKeyCode */ void setText(String text); /** * Sets the tool tip text for this action. *

* Fires a property change event for the TOOL_TIP_TEXT property * if the tool tip text actually changes as a consequence. *

* * @param text the tool tip text, or null if none * @see #TOOL_TIP_TEXT */ void setToolTipText(String text); /** *

* Sets the accelerator keycode that this action maps to. This is a bitwise OR * of zero or more SWT key modifier masks (i.e. SWT.CTRL or SWT.ALT) and a * character code. For example, for Ctrl+Z, use SWT.CTRL | 'Z'. * Use 0 for no accelerator. *

*

* This method should no longer be used for actions in the Eclipse workbench. * IWorkbenchCommandSupport and * IWorkbenchContextSupport provide all the functionality * required for key bindings. If you set an accelerator using this method, then * it will not work in the workbench if it conflicts any existing key binding, * or if there is a different key binding defined for this action's definition * id. The definition id should be used instead -- referring to the command in * the workbench from which the key binding should be retrieved. *

* * @param keycode * the keycode to be accepted. */ void setAccelerator(int keycode); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy