Class WorkbenchPart
- All Implemented Interfaces:
IAdaptable,IExecutableExtension,IWorkbenchPart,IWorkbenchPart2,IWorkbenchPart3,IWorkbenchPartOrientation
- Direct Known Subclasses:
EditorPart,ViewPart
This class is not intended to be subclassed by clients outside this package;
clients should instead subclass ViewPart or
EditorPart.
- See Also:
- Restriction:
- This class is not intended to be subclassed by clients.
-
Field Summary
Fields inherited from interface org.eclipse.ui.IWorkbenchPart
PROP_TITLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a listener for changes in the arbitrary properties set.voidAdds a listener for changes to properties of this workbench part.protected voidcheckSite(IWorkbenchPartSite site) Checks that the given site is valid for this type of part.abstract voidcreatePartControl(Composite parent) Creates the SWT controls for this workbench part.voiddispose()TheWorkbenchPartimplementation of thisIWorkbenchPartmethod disposes the title image loaded bysetInitializationData.protected voidfirePartPropertyChanged(String key, String oldValue, String newValue) protected voidfirePropertyChange(int propertyId) Fires a property changed event.<T> TgetAdapter(Class<T> adapter) Returns an object which is an instance of the given class associated with this object.protected IConfigurationElementReturns the configuration element for this part.Returns the content description of this part.protected ImageReturns the default title image.intReturn the orientation of this part.Returns the name of this part.Return an unmodifiable map of the arbitrary properties.getPartProperty(String key) Return the value for the arbitrary property key, ornull.getSite()Returns the site for this workbench part.getTitle()Returns the title of this workbench part.Returns the title image of this workbench part.Returns the title tool tip text of this workbench part.voidRemove a change listener from the arbitrary properties set.voidRemoves the given property listener from this workbench part.protected voidsetContentDescription(String description) Sets the content description for this part.abstract voidsetFocus()Asks this part to take focus within the workbench.voidsetInitializationData(IConfigurationElement cfig, String propertyName, Object data) This method is called by the implementation of the methodIConfigurationElement.createExecutableExtensionon a newly constructed extension, passing it its relevant configuration information.protected voidsetPartName(String partName) Sets the name of this part.voidsetPartProperty(String key, String value) Set an arbitrary property on the part.protected voidsetSite(IWorkbenchPartSite site) Sets the part site.protected voidDeprecated.new code should use setPartName and setContentDescriptionprotected voidsetTitleImage(Image titleImage) Sets or clears the title image of this part.protected voidsetTitleToolTip(String toolTip) Sets or clears the title tool tip text of this part.voidshowBusy(boolean busy) Show that this part is busy due to a Job running that it is listening to.Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
-
Constructor Details
-
WorkbenchPart
protected WorkbenchPart()Creates a new workbench part.
-
-
Method Details
-
addPropertyListener
Description copied from interface:IWorkbenchPartAdds a listener for changes to properties of this workbench part. Has no effect if an identical listener is already registered.The property ids are defined in
IWorkbenchPartConstants.- Specified by:
addPropertyListenerin interfaceIWorkbenchPart- Parameters:
l- a property listener
-
createPartControl
Description copied from interface:IWorkbenchPartCreates the SWT controls for this workbench part.Clients should not call this method (the workbench calls this method when it needs to, which may be never).
For implementors this is a multi-step process:
- Create one or more controls within the parent.
- Set the parent layout as needed.
- Register any global actions with the site's
IActionBars. - Register any context menus with the site.
- Register a selection provider with the site, to make it available to the
workbench's
ISelectionService(optional).
- Specified by:
createPartControlin interfaceIWorkbenchPart- Parameters:
parent- the parent control
-
dispose
public void dispose()TheWorkbenchPartimplementation of thisIWorkbenchPartmethod disposes the title image loaded bysetInitializationData. Subclasses may extend.- Specified by:
disposein interfaceIWorkbenchPart
-
firePropertyChange
protected void firePropertyChange(int propertyId) Fires a property changed event.- Parameters:
propertyId- the id of the property that changed
-
getAdapter
Returns an object which is an instance of the given class associated with this object. Returnsnullif no such object can be found.Clients may implement this method but should generally call
Adapters.adapt(Object, Class, boolean)rather than invoking it directly. Subclasses may override this method (however, if they do so, they should invoke the method on their superclass to ensure that the Platform's adapter manager is consulted).- Specified by:
getAdapterin interfaceIAdaptable- Type Parameters:
T- the class type- Parameters:
adapter- the adapter class to look up- Returns:
- a object of the given class, or
nullif this object does not have an adapter for the given class
-
getConfigurationElement
Returns the configuration element for this part. The configuration element comes from the plug-in registry entry for the extension defining this part.- Returns:
- the configuration element for this part
-
getDefaultImage
Returns the default title image.- Returns:
- the default image
-
getSite
Description copied from interface:IWorkbenchPartReturns the site for this workbench part. The site can benullwhile the workbench part is being initialized. After the initialization is complete, this value must be non-nullfor the remainder of the part's life cycle.- Specified by:
getSitein interfaceIWorkbenchPart- Returns:
- The part site; this value may be
nullif the part has not yet been initialized
-
getTitle
Returns the title of this workbench part. If this value changes the part must fire a property listener event withPROP_TITLE.The title is used to populate the title bar of this part's visual container.
It is considered bad practise to overload or extend this method. Parts should set their title by calling setPartName and/or setContentDescription.
- Specified by:
getTitlein interfaceIWorkbenchPart- Returns:
- the workbench part title (not
null)
-
getTitleImage
Description copied from interface:IWorkbenchPartReturns the title image of this workbench part. If this value changes the part must fire a property listener event withPROP_TITLE.The title image is usually used to populate the title bar of this part's visual container. Since this image is managed by the part itself, callers must not dispose the returned image.
- Specified by:
getTitleImagein interfaceIWorkbenchPart- Returns:
- the title image
-
getTitleToolTip
Description copied from interface:IWorkbenchPartReturns the title tool tip text of this workbench part. An empty string result indicates no tool tip. If this value changes the part must fire a property listener event withPROP_TITLE.The tool tip text is used to populate the title bar of this part's visual container.
- Specified by:
getTitleToolTipin interfaceIWorkbenchPart- Returns:
- the workbench part title tool tip (not
null)
-
removePropertyListener
Description copied from interface:IWorkbenchPartRemoves the given property listener from this workbench part. Has no effect if an identical listener is not registered.- Specified by:
removePropertyListenerin interfaceIWorkbenchPart- Parameters:
l- a property listener
-
setFocus
public abstract void setFocus()Description copied from interface:IWorkbenchPartAsks this part to take focus within the workbench. Parts must assign focus to one of the controls contained in the part's parent composite.Clients should not call this method (the workbench calls this method at appropriate times). To have the workbench activate a part, use
IWorkbenchPage.activate(IWorkbenchPart) instead.- Specified by:
setFocusin interfaceIWorkbenchPart
-
setInitializationData
This method is called by the implementation of the methodIConfigurationElement.createExecutableExtensionon a newly constructed extension, passing it its relevant configuration information. Most executable extensions only make use of the first two call arguments.Regular executable extensions specify their Java implementation class name as an attribute of the configuration element for the extension. For example
<action run="com.example.BaseAction"/>In the above example, this method would be called with a reference to the
<action>element (first argument), and"run"as the name of the attribute that defined this executable extension (second argument).The last parameter is for the specific use of extension adapters and is typically not used by regular executable extensions.
There are two supported ways of associating additional adapter-specific data with the configuration in a way that is transparent to the extension point implementor:
(1) by specifying adapter data as part of the implementation class attribute value. The Java class name can be followed by a ":" separator, followed by any adapter data in string form. For example, if the extension point specifies an attribute
"run"to contain the name of the extension implementation, an adapter can be configured as<action run="com.example.ExternalAdapter:./cmds/util.exe -opt 3"/>(2) by converting the attribute used to specify the executable extension to a child element of the original configuration element, and specifying the adapter data in the form of xml markup. Using this form, the example above would become
<action> <run class="com.xyz.ExternalAdapter"> <parameter name="exec" value="./cmds/util.exe"/> <parameter name="opt" value="3"/> </run> </action>Form (2) will typically only be used for extension points that anticipate the majority of extensions configured into it will in fact be in the form of adapters.
In either case, the specified adapter class is instantiated using its 0-argument public constructor. The adapter data is passed as the last argument of this method. The data argument is defined as Object. It can have the following values:
null, if no adapter data was supplied- in case (1), the initialization data string is passed as a
String - in case (2), the initialization data is passed as a
Hashtablecontaining the actual parameter names and values (bothStrings)
WorkbenchPartimplementation of thisIExecutableExtensionrecords the configuration element in and internal state variable (accessible viagetConfigElement). It also loads the title image, if one is specified in the configuration element. Subclasses may extend. Should not be called by clients. It is called by the core plugin when creating this executable extension.- Specified by:
setInitializationDatain interfaceIExecutableExtension- Parameters:
cfig- the configuration element used to trigger this execution. It can be queried by the executable extension for specific configuration propertiespropertyName- the name of an attribute of the configuration element used on thecreateExecutableExtension(String)call. This argument can be used in the cases where a single configuration element is used to define multiple executable extensions.data- adapter data in the form of aString, aHashtable, ornull.- See Also:
-
setSite
Sets the part site.Subclasses must invoke this method from
IEditorPart.initandIViewPart.init.- Parameters:
site- the workbench part site
-
checkSite
Checks that the given site is valid for this type of part. The default implementation does nothing.- Parameters:
site- the site to check- Since:
- 3.1
-
setTitle
Deprecated.new code should use setPartName and setContentDescriptionSets or clears the title of this part. Clients should call this method instead of overriding getTitle.This may change a title that was previously set using setPartName or setContentDescription.
- Parameters:
title- the title, ornullto clear
-
setTitleImage
Sets or clears the title image of this part.- Parameters:
titleImage- the title image, ornullto clear
-
setTitleToolTip
Sets or clears the title tool tip text of this part. Clients should call this method instead of overridinggetTitleToolTip- Parameters:
toolTip- the new tool tip text, ornullto clear
-
showBusy
public void showBusy(boolean busy) Show that this part is busy due to a Job running that it is listening to.- Parameters:
busy- boolean to indicate that the busy state has started or ended.- Since:
- 3.0
- See Also:
-
getPartName
Returns the name of this part. If this value changes the part must fire a property listener event withIWorkbenchPartConstants.PROP_PART_NAME.It is considered bad practise to overload or extend this method. Parts should call setPartName to change their part name.
- Specified by:
getPartNamein interfaceIWorkbenchPart2- Returns:
- the name of this view, or the empty string if the name is being
managed by the workbench (not
null)
-
setPartName
Sets the name of this part. The name will be shown in the tab area for the part. Clients should call this method instead of overriding getPartName. Setting this to the empty string will cause a default part name to be used.setPartName and setContentDescription are intended to replace setTitle. This may change a value that was previously set using setTitle.
- Parameters:
partName- the part name, as it should be displayed in tabs.- Since:
- 3.0
-
getContentDescription
Returns the content description of this part. The content description is an optional user-readable string that describes what is currently being displayed in the part. By default, the workbench will display the content description in a line near the top of the view or editor. An empty string indicates no content description text. If this value changes the part must fire a property listener event withIWorkbenchPartConstants.PROP_CONTENT_DESCRIPTION.It is considered bad practise to overload or extend this method. Parts should call setContentDescription to change their content description.
- Specified by:
getContentDescriptionin interfaceIWorkbenchPart2- Returns:
- the content description of this part (not
null)
-
setContentDescription
Sets the content description for this part. The content description is typically a short string describing the current contents of the part. Setting this to the empty string will cause a default content description to be used. Clients should call this method instead of overriding getContentDescription(). For views, the content description is shown (by default) in a line near the top of the view. For editors, the content description is shown beside the part name when showing a list of editors. If the editor is open on a file, this typically contains the path to the input file, without the filename or trailing slash.This may overwrite a value that was previously set in setTitle
- Parameters:
description- the content description- Since:
- 3.0
-
getOrientation
public int getOrientation()Description copied from interface:IWorkbenchPartOrientationReturn the orientation of this part.- Specified by:
getOrientationin interfaceIWorkbenchPartOrientation- Returns:
- int SWT#RIGHT_TO_LEFT or SWT#LEFT_TO_RIGHT
- See Also:
-
addPartPropertyListener
Description copied from interface:IWorkbenchPart3Add a listener for changes in the arbitrary properties set.Note: this is a different set of properties than the ones covered by the IWorkbenchPartConstants.PROP_* constants.
- Specified by:
addPartPropertyListenerin interfaceIWorkbenchPart3- Parameters:
listener- Must not benull.
-
removePartPropertyListener
Description copied from interface:IWorkbenchPart3Remove a change listener from the arbitrary properties set.Note: this is a different set of properties than the ones covered by the IWorkbenchPartConstants.PROP_* constants.
- Specified by:
removePartPropertyListenerin interfaceIWorkbenchPart3- Parameters:
listener- Must not benull.
-
firePartPropertyChanged
- Since:
- 3.3
-
setPartProperty
Description copied from interface:IWorkbenchPart3Set an arbitrary property on the part. It is the implementor's responsibility to fire the corresponding PropertyChangeEvent.A default implementation has been added to WorkbenchPart.
- Specified by:
setPartPropertyin interfaceIWorkbenchPart3- Parameters:
key- the arbitrary property. Must not benull.value- the property value. Anullvalue will remove that property.
-
getPartProperty
Description copied from interface:IWorkbenchPart3Return the value for the arbitrary property key, ornull.- Specified by:
getPartPropertyin interfaceIWorkbenchPart3- Parameters:
key- the arbitrary property. Must not benull.- Returns:
- the property value, or
null.
-
getPartProperties
Description copied from interface:IWorkbenchPart3Return an unmodifiable map of the arbitrary properties. This method can be used to save the properties during workbench save/restore.- Specified by:
getPartPropertiesin interfaceIWorkbenchPart3- Returns:
- A Map of the properties. Must not be
null.
-