Class ViewPart
- All Implemented Interfaces:
IAdaptable
,IExecutableExtension
,IPersistable
,IViewPart
,IWorkbenchPart
,IWorkbenchPart2
,IWorkbenchPart3
,IWorkbenchPartOrientation
- Direct Known Subclasses:
CommonNavigator
,E4PartWrapper
,ErrorViewPart
,org.eclipse.ui.internal.views.markers.ExtendedMarkersView
,PageBookView
,ViewIntroAdapterPart
This class should be subclassed by clients wishing to define new views. The
name of the subclass should be given as the "class"
attribute in
a view
extension contributed to the workbench's view extension
point (named "org.eclipse.ui.views"
). For example, the plug-in's
XML markup might contain:
<extension point="org.eclipse.ui.views"> <view id="com.example.myplugin.view" name="My View" class="com.example.myplugin.MyView" icon="images/eview.gif" /> </extension>
where com.example.myplugin.MyView
is the name of the
ViewPart
subclass.
Subclasses must implement the following methods:
createPartControl
- to create the view's controlssetFocus
- to accept focus
Subclasses may extend or reimplement the following methods as required:
setInitializationData
- extend to provide additional initialization when view extension is instantiatedinit(IWorkbenchPartSite)
- extend to provide additional initialization when view is assigned its sitedispose
- extend to provide additional cleanupgetAdapter
- reimplement to make their view adaptable
-
Field Summary
Fields inherited from interface org.eclipse.ui.IWorkbenchPart
PROP_TITLE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final void
checkSite
(IWorkbenchPartSite site) Checks that the given site is valid for this type of part.Returns the site for this view.void
Initializes this view with the given view site.void
Initializes this view with the given view site.void
Saves the object state within a memento.protected void
setContentDescription
(String description) Sets the content description for this part.void
setInitializationData
(IConfigurationElement cfig, String propertyName, Object data) This method is called by the implementation of the methodIConfigurationElement.createExecutableExtension
on a newly constructed extension, passing it its relevant configuration information.protected void
setPartName
(String partName) Sets the name of this part.Methods inherited from class org.eclipse.ui.part.WorkbenchPart
addPartPropertyListener, addPropertyListener, createPartControl, dispose, firePartPropertyChanged, firePropertyChange, getAdapter, getConfigurationElement, getContentDescription, getDefaultImage, getOrientation, getPartName, getPartProperties, getPartProperty, getSite, getTitle, getTitleImage, getTitleToolTip, removePartPropertyListener, removePropertyListener, setFocus, setPartProperty, setSite, setTitle, setTitleImage, setTitleToolTip, showBusy
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapter
Methods inherited from interface org.eclipse.ui.IWorkbenchPart
addPropertyListener, createPartControl, dispose, getSite, getTitle, getTitleImage, getTitleToolTip, removePropertyListener, setFocus
-
Constructor Details
-
ViewPart
protected ViewPart()Creates a new view.
-
-
Method Details
-
getViewSite
Description copied from interface:IViewPart
Returns the site for this view. This method is equivalent to(IViewSite) getSite()
.The site can be
null
while the view is being initialized. After the initialization is complete, this value must be non-null
for the remainder of the view's life cycle.- Specified by:
getViewSite
in interfaceIViewPart
- Returns:
- the view site; this value may be
null
if the view has not yet been initialized
-
init
Description copied from interface:IViewPart
Initializes this view with the given view site.This method is automatically called by the workbench shortly after the part is instantiated. It marks the start of the views's lifecycle. Clients must not call this method.
- Specified by:
init
in interfaceIViewPart
- Parameters:
site
- the view site- Throws:
PartInitException
- may be thrown from overrides
-
init
Description copied from interface:IViewPart
Initializes this view with the given view site. A memento is passed to the view which contains a snapshot of the views state from a previous session. Where possible, the view should try to recreate that state within the part controls.This method is automatically called by the workbench shortly after the part is instantiated. It marks the start of the views's lifecycle. Clients must not call this method.
- Specified by:
init
in interfaceIViewPart
- Parameters:
site
- the view sitememento
- the IViewPart state or null if there is no previous saved state- Throws:
PartInitException
- if this view was not initialized successfully
-
saveState
Description copied from interface:IViewPart
Saves the object state within a memento.- Specified by:
saveState
in interfaceIPersistable
- Specified by:
saveState
in interfaceIViewPart
- Parameters:
memento
- a memento to receive the object state
-
setPartName
Description copied from class:WorkbenchPart
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.
- Overrides:
setPartName
in classWorkbenchPart
- Parameters:
partName
- the part name, as it should be displayed in tabs.
-
setContentDescription
Description copied from class:WorkbenchPart
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
- Overrides:
setContentDescription
in classWorkbenchPart
- Parameters:
description
- the content description
-
setInitializationData
Description copied from class:WorkbenchPart
This method is called by the implementation of the methodIConfigurationElement.createExecutableExtension
on 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
Hashtable
containing the actual parameter names and values (bothString
s)
WorkbenchPart
implementation of thisIExecutableExtension
records 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:
setInitializationData
in interfaceIExecutableExtension
- Overrides:
setInitializationData
in classWorkbenchPart
- 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:
-
checkSite
Description copied from class:WorkbenchPart
Checks that the given site is valid for this type of part. The default implementation does nothing.- Overrides:
checkSite
in classWorkbenchPart
- Parameters:
site
- the site to check
-