Un plugin aggiunge una azione ridestinabile per una vista o per una parte di editor implementando una IAction e registrandola come gestore di azioni globale con le barre delle azioni della parte. In views, this is usually done at the time that the part creates its actions and controls. For editors see Retargetable editor actions. The name of the retargeted action (as defined in IWorkbenchActionConstants) is used to specify which action the handler is intended for. The following shows how the workbench task list view registers its handler for the PROPERTIES action.
public void createPartControl(Composite parent) { ... makeActions(); ... // Aggiungere gestori di azione globali. ... getViewSite().getActionBars().setGlobalActionHandler( IWorkbenchActionConstants.PROPERTIES, propertiesAction); ...
L'azione proprietà viene creata nel metodo locale makeActions:
void makeActions() { ... // proprietà propertiesAction = new TaskPropertiesAction(this, "properties"); propertiesAction.setText(TaskListMessages.getString("Properties.text")); propertiesAction.setToolTipText(TaskListMessages.getString("Properties.tooltip")); propertiesAction.setEnabled(false); }
Questo è tutto quanto è richiesto. L'azione viene eseguita quando l'utente sceglie l'azione dalla barra dei menu o dalla barra degli strumenti del workbench e la vista o l'editor sono attivi. The workbench handles the details of ensuring that the retargeted action is always associated with the currently active view. The same applies to editor actions supplied through the EditorActionBarContributor.