Class AbstractInformationControl
- java.lang.Object
-
- org.eclipse.jface.text.AbstractInformationControl
-
- All Implemented Interfaces:
IInformationControl
,IInformationControlExtension
,IInformationControlExtension3
,IInformationControlExtension4
,IInformationControlExtension5
- Direct Known Subclasses:
DefaultInformationControl
public abstract class AbstractInformationControl extends Object implements IInformationControl, IInformationControlExtension, IInformationControlExtension3, IInformationControlExtension4, IInformationControlExtension5
An abstract information control that can show content inside a shell. The information control can be created in two styles:- non-resizable tooltip with optional status
- resizable tooltip with optional tool bar
Subclasses must either override
IInformationControl.setInformation(String)
or implementIInformationControlExtension2
. They should also extendcomputeTrim()
if they create a content area with additional trim (e.g. scrollbars) and overridegetInformationPresenterControlCreator()
.- Since:
- 3.4
-
-
Constructor Summary
Constructors Constructor Description AbstractInformationControl(Shell parentShell, boolean isResizable)
Creates an abstract information control with the given shell as parent.AbstractInformationControl(Shell parentShell, String statusFieldText)
Creates an abstract information control with the given shell as parent.AbstractInformationControl(Shell parentShell, ToolBarManager toolBarManager)
Creates an abstract information control with the given shell as parent.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addDisposeListener(DisposeListener listener)
Adds the given listener to the list of dispose listeners.void
addFocusListener(FocusListener listener)
Adds the given listener to the list of focus listeners.Point
computeSizeConstraints(int widthInChars, int heightInChars)
Computes the size constraints based on thedialog font
.Point
computeSizeHint()
Computes and returns a proposal for the size of this information control depending on the information to present.Rectangle
computeTrim()
Computes the trim (status text and tool bar are considered as trim).boolean
containsControl(Control control)
Tests whether the given control is this information control or a child of this information control.protected void
create()
Creates the content of this information control.protected abstract void
createContent(Composite parent)
Creates the content of the popup window.void
dispose()
Disposes this information control.Rectangle
getBounds()
Returns a rectangle describing the receiver's size and location relative to its parent (or its display if its parent is null).IInformationControlCreator
getInformationPresenterControlCreator()
Returns the rich information control creator for this information control.Shell
getShell()
The shell of the popup window.protected Point
getSizeConstraints()
Returns the size constraints.protected ToolBarManager
getToolBarManager()
The toolbar manager used to manage the toolbar, ornull
if no toolbar is shown.protected void
handleDispose()
Frees all resources allocated by this information control.boolean
isFocusControl()
Returns whether this information control (or one of its children) has the focus.boolean
isResizable()
Returns whether the information control is resizable.boolean
isVisible()
void
removeDisposeListener(DisposeListener listener)
Removes the given listeners from the list of dispose listeners.void
removeFocusListener(FocusListener listener)
Removes the given listeners from the list of focus listeners.boolean
restoresLocation()
Tells whether this control allows to restore the previously used location.boolean
restoresSize()
Tells whether this control allows to restore the previously used size.void
setBackgroundColor(Color background)
Sets the background color of this information control.void
setFocus()
This default implementation sets the focus on the popup shell.void
setForegroundColor(Color foreground)
Sets the foreground color of this information control.void
setInformation(String information)
Sets the information to be presented by this information control.void
setLocation(Point location)
Sets the location of this information control.void
setSize(int width, int height)
Sets the size of this information control.void
setSizeConstraints(int maxWidth, int maxHeight)
Sets the information control's size constraints.void
setStatusText(String statusFieldText)
Sets the text of the status field.void
setVisible(boolean visible)
Controls the visibility of this information control.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.jface.text.IInformationControlExtension
hasContents
-
-
-
-
Constructor Detail
-
AbstractInformationControl
public AbstractInformationControl(Shell parentShell, String statusFieldText)
Creates an abstract information control with the given shell as parent. The control will not be resizable and optionally show a status line with the given status field text.Important: Subclasses are required to call
create()
at the end of their constructor.- Parameters:
parentShell
- the parent of this control's shellstatusFieldText
- the text to be used in the status field ornull
to hide the status field
-
AbstractInformationControl
public AbstractInformationControl(Shell parentShell, ToolBarManager toolBarManager)
Creates an abstract information control with the given shell as parent. The control will be resizable and optionally show a tool bar managed by the given tool bar manager.Important: Subclasses are required to call
create()
at the end of their constructor.- Parameters:
parentShell
- the parent of this control's shelltoolBarManager
- the manager ornull
if toolbar is not desired
-
AbstractInformationControl
public AbstractInformationControl(Shell parentShell, boolean isResizable)
Creates an abstract information control with the given shell as parent.Important: Subclasses are required to call
create()
at the end of their constructor.- Parameters:
parentShell
- the parent of this control's shellisResizable
-true
if the control should be resizable
-
-
Method Detail
-
getShell
public final Shell getShell()
The shell of the popup window.- Returns:
- the shell used for the popup window
- Since:
- 3.13
-
getToolBarManager
protected final ToolBarManager getToolBarManager()
The toolbar manager used to manage the toolbar, ornull
if no toolbar is shown.- Returns:
- the tool bar manager or
null
-
create
protected final void create()
Creates the content of this information control. Subclasses must call this method at the end of their constructor(s).
-
createContent
protected abstract void createContent(Composite parent)
Creates the content of the popup window.Implementors will usually take over
Control.getBackground()
andControl.getForeground()
fromparent
.Implementors must either use the dialog font or override
computeSizeConstraints(int, int)
.Implementors are expected to consider
isResizable()
: Iftrue
, they should show scrollbars if their content may exceed the size of the information control. Iffalse
, they should never show scrollbars.The given
parent
comes with aFillLayout
. Subclasses may set a different layout.- Parameters:
parent
- the container of the content
-
setInformation
public void setInformation(String information)
Sets the information to be presented by this information control.The default implementation does nothing. Subclasses must either override this method or implement
IInformationControlExtension2
.- Specified by:
setInformation
in interfaceIInformationControl
- Parameters:
information
- the information to be presented- See Also:
IInformationControl.setInformation(java.lang.String)
-
isResizable
public boolean isResizable()
Returns whether the information control is resizable.- Returns:
true
if the information control is resizable,false
if it is not resizable.
-
setVisible
public void setVisible(boolean visible)
Description copied from interface:IInformationControl
Controls the visibility of this information control.Note: The information control must not grab focus when made visible.
- Specified by:
setVisible
in interfaceIInformationControl
- Parameters:
visible
-true
if the control should be visible
-
dispose
public void dispose()
Description copied from interface:IInformationControl
Disposes this information control.- Specified by:
dispose
in interfaceIInformationControl
-
handleDispose
protected void handleDispose()
Frees all resources allocated by this information control. Internally called when the information control's shell has been disposed.- Since:
- 3.6
-
setSize
public void setSize(int width, int height)
Description copied from interface:IInformationControl
Sets the size of this information control.- Specified by:
setSize
in interfaceIInformationControl
- Parameters:
width
- the width of the controlheight
- the height of the control
-
setLocation
public void setLocation(Point location)
Description copied from interface:IInformationControl
Sets the location of this information control.- Specified by:
setLocation
in interfaceIInformationControl
- Parameters:
location
- the location
-
setSizeConstraints
public void setSizeConstraints(int maxWidth, int maxHeight)
Description copied from interface:IInformationControl
Sets the information control's size constraints. A constraint value ofSWT.DEFAULT
indicates no constraint. This method must be called beforeIInformationControl.computeSizeHint()
is called.Note: An information control which implements
IInformationControlExtension3
may ignore this method or use it as hint for its very first appearance.- Specified by:
setSizeConstraints
in interfaceIInformationControl
- Parameters:
maxWidth
- the maximal width of the control to present the information, orSWT.DEFAULT
for not constraintmaxHeight
- the maximal height of the control to present the information, orSWT.DEFAULT
for not constraint
-
getSizeConstraints
protected final Point getSizeConstraints()
Returns the size constraints.- Returns:
- the size constraints or
null
if not set - See Also:
setSizeConstraints(int, int)
-
computeSizeHint
public Point computeSizeHint()
Description copied from interface:IInformationControl
Computes and returns a proposal for the size of this information control depending on the information to present. The method tries to honor known size constraints but might return a size that exceeds them.- Specified by:
computeSizeHint
in interfaceIInformationControl
- Returns:
- the computed size hint
-
computeTrim
public Rectangle computeTrim()
Computes the trim (status text and tool bar are considered as trim). Subclasses can extend this method to add additional trim (e.g. scroll bars for resizable information controls).- Specified by:
computeTrim
in interfaceIInformationControlExtension3
- Returns:
- The receiver's trim.
x
andy
denote the upper left corner of the trimming relative to this control's location i.e. this will most likely be negative values.width
andheight
represent the border sizes (the sum of the horizontal and vertical trimmings, respectively). - See Also:
IInformationControlExtension3.computeTrim()
-
getBounds
public Rectangle getBounds()
Description copied from interface:IInformationControlExtension3
Returns a rectangle describing the receiver's size and location relative to its parent (or its display if its parent is null).Note: If the receiver is already disposed then this methods must return the last valid location and size.
- Specified by:
getBounds
in interfaceIInformationControlExtension3
- Returns:
- the receiver's bounding rectangle
-
restoresLocation
public boolean restoresLocation()
Tells whether this control allows to restore the previously used location.Note: This is not a static property - it can change during the lifetime of this control.
The default implementation always returns
false
.- Specified by:
restoresLocation
in interfaceIInformationControlExtension3
- Returns:
true
if restoring location is supported- See Also:
IInformationControlExtension3.restoresLocation()
-
restoresSize
public boolean restoresSize()
Tells whether this control allows to restore the previously used size.Note: This is not a static property - it can change during the lifetime of this control.
The default implementation always returns
false
.- Specified by:
restoresSize
in interfaceIInformationControlExtension3
- Returns:
true
if restoring size is supported- See Also:
IInformationControlExtension3.restoresSize()
-
addDisposeListener
public void addDisposeListener(DisposeListener listener)
Description copied from interface:IInformationControl
Adds the given listener to the list of dispose listeners. If the listener is already registered it is not registered again.- Specified by:
addDisposeListener
in interfaceIInformationControl
- Parameters:
listener
- the listener to be added
-
removeDisposeListener
public void removeDisposeListener(DisposeListener listener)
Description copied from interface:IInformationControl
Removes the given listeners from the list of dispose listeners. If the listener is not registered this call has no effect.- Specified by:
removeDisposeListener
in interfaceIInformationControl
- Parameters:
listener
- the listener to be removed
-
setForegroundColor
public void setForegroundColor(Color foreground)
Description copied from interface:IInformationControl
Sets the foreground color of this information control.- Specified by:
setForegroundColor
in interfaceIInformationControl
- Parameters:
foreground
- the foreground color of this information control
-
setBackgroundColor
public void setBackgroundColor(Color background)
Description copied from interface:IInformationControl
Sets the background color of this information control.- Specified by:
setBackgroundColor
in interfaceIInformationControl
- Parameters:
background
- the background color of this information control
-
isFocusControl
public boolean isFocusControl()
Returns whether this information control (or one of its children) has the focus. The suggested implementation is like this (fShell
is this information control's shell):return fShell.getDisplay().getActiveShell() == fShell
Note that implementations of
This method is not intended to be overridden by subclasses.IInformationControlExtension5
are required to use this suggested implementation.- Specified by:
isFocusControl
in interfaceIInformationControl
- Returns:
true
when the information control has the focus, otherwisefalse
-
setFocus
public void setFocus()
This default implementation sets the focus on the popup shell. Subclasses can override or extend.- Specified by:
setFocus
in interfaceIInformationControl
- See Also:
IInformationControl.setFocus()
-
addFocusListener
public void addFocusListener(FocusListener listener)
Adds the given listener to the list of focus listeners. If the listener is already registered it is not registered again.The suggested implementation is to install listeners for
This method is not intended to be overridden by subclasses.SWT.Activate
andSWT.Deactivate
on the shell and forward events to the focus listeners. Clients are encouraged to subclassAbstractInformationControl
, which does this for free.- Specified by:
addFocusListener
in interfaceIInformationControl
- Parameters:
listener
- the listener to be added
-
removeFocusListener
public void removeFocusListener(FocusListener listener)
Removes the given listeners from the list of focus listeners. If the listener is not registered this call has no effect. This method is not intended to be overridden by subclasses.- Specified by:
removeFocusListener
in interfaceIInformationControl
- Parameters:
listener
- the listener to be removed
-
setStatusText
public void setStatusText(String statusFieldText)
Sets the text of the status field.The default implementation currently only updates the status field when the popup shell is not visible. The status field can currently only be shown if the information control has been created with a non-null status field text.
- Specified by:
setStatusText
in interfaceIInformationControlExtension4
- Parameters:
statusFieldText
- the text to be used in the optional status field ornull
if the status field should be hidden- See Also:
IInformationControlExtension4.setStatusText(java.lang.String)
-
containsControl
public boolean containsControl(Control control)
Description copied from interface:IInformationControlExtension5
Tests whether the given control is this information control or a child of this information control.- Specified by:
containsControl
in interfaceIInformationControlExtension5
- Parameters:
control
- the control to test- Returns:
true
iff the given control is this information control or a child of this information control
-
isVisible
public boolean isVisible()
- Specified by:
isVisible
in interfaceIInformationControlExtension5
- Returns:
true
iff the information control is currently visible
-
getInformationPresenterControlCreator
public IInformationControlCreator getInformationPresenterControlCreator()
Returns the rich information control creator for this information control.The returned information control creator is used to create an enriched version of this information control, e.g. when the mouse is moved into this control and it needs to be
enriched
or when it needs to be made sticky for other reasons.The returned information control creator must create information controls that implement
IInformationControlExtension3
andIInformationControlExtension2
, and whoseIInformationControlExtension2.setInput(Object)
accepts all inputs that are also supported by this information control.Note that automatic enriching of this information control works only if it also implements
IInformationControlExtension3
.This method may be called frequently, so implementors should ensure it returns quickly, e.g. by caching the returned creator.
This default implementation returnsnull
. Subclasses may override.- Specified by:
getInformationPresenterControlCreator
in interfaceIInformationControlExtension5
- Returns:
- the information presenter control creator or
null
to disable enriching
-
computeSizeConstraints
public Point computeSizeConstraints(int widthInChars, int heightInChars)
Computes the size constraints based on thedialog font
. Subclasses can override or extend.- Specified by:
computeSizeConstraints
in interfaceIInformationControlExtension5
- Parameters:
widthInChars
- the width constraint in number of charactersheightInChars
- the height constraint in number of characters- Returns:
- a point with width and height in pixels, or
null
to use the subject control's font to calculate the size - See Also:
IInformationControlExtension5.computeSizeConstraints(int, int)
-
-