Package org.eclipse.ui.swt
Interface IFocusService
-
public interface IFocusService
Tracks focusGained and focusLost events for a Control registered with this service, and provides the control and its registered ID as variables to the application evaluation context for evaluation by the various services.This service provides 2 variables, activeFocusControl (a Control) and activeFocusControlId (the ID registered with the service).
You can use this service to provide default cut/copy/paste/selectAll for specific text controls outside of the normal workbench part lifecycle, like a control contributed to the trim. For example:
<handler class="org.eclipse.ui.internal.handlers.WidgetMethodHandler:paste" commandId="org.eclipse.ui.edit.paste"> <activeWhen> <with variable="activeFocusControlId"> <equals value="org.eclipse.ui.tests.focusText"/> </with> </activeWhen> </handler>
This service can be acquired from your service locator:
IFocusService service = (IFocusService) getSite().getService(IFocusService.class);
- This service is available globally.
- Since:
- 3.3
- See Also:
ISources
- Restriction:
- This interface is not intended to be implemented by clients.
-
-
Field Summary
Fields Modifier and Type Field Description static String
COPY_HANDLER
Use the value to provide default copy behaviour in a handler element class attribute.static String
CUT_HANDLER
Use the value to provide default cut behaviour in a handler element class attribute.static String
PASTE_HANDLER
Use the value to provide default paste behaviour in a handler element class attribute.static String
SELECT_ALL_HANDLER
Use the value to provide default select all behaviour in a handler element class attribute.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addFocusTracker(Control control, String id)
A Control for which the service will track focus.void
removeFocusTracker(Control control)
No longer track focus events for this control.
-
-
-
Field Detail
-
COPY_HANDLER
static final String COPY_HANDLER
Use the value to provide default copy behaviour in a handler element class attribute.- See Also:
- Constant Field Values
-
PASTE_HANDLER
static final String PASTE_HANDLER
Use the value to provide default paste behaviour in a handler element class attribute.- See Also:
- Constant Field Values
-
CUT_HANDLER
static final String CUT_HANDLER
Use the value to provide default cut behaviour in a handler element class attribute.- See Also:
- Constant Field Values
-
SELECT_ALL_HANDLER
static final String SELECT_ALL_HANDLER
Use the value to provide default select all behaviour in a handler element class attribute.- See Also:
- Constant Field Values
-
-
Method Detail
-
addFocusTracker
void addFocusTracker(Control control, String id)
A Control for which the service will track focus. When in focus, this Control and its ID will be provided as variables to core expressions for the various services, as activeFocusControl and activeFocusControlId respectively.A control must only be registered once, but different controls can be registered with the same ID. Expressions evaluated against the activeFocusControlId would then be true for all of the controls thus registered.
We will remove ourselves as a listener when the Control is disposed.
- Parameters:
control
- the control. Must not benull
. If the control is already registered with this service this call is a no-op.id
- an ID for this control. Must not benull
.
-
removeFocusTracker
void removeFocusTracker(Control control)
No longer track focus events for this control. Use this method when the control should no longer be tracked, but is not disposed.- Parameters:
control
- the control registered with the service. Must not benull
.
-
-