blob: 8dd1516a8380a30e84d6ed9aab45c1177d814f26 [file]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
<HEAD>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="../book.css" CHARSET="ISO-8859-1" TYPE="text/css">
<title>Site interfaces</title>
</HEAD>
<BODY BGCOLOR="#ffffff">
<H2> Site interfaces</H2>
The arguments in a part's constructor are known as dependencies. Part dependencies
replace the various adapters and get methods, for example, to access a site's
IActionBars, a component-based part would take an IActionBars instance in its
constructor. <br>
<br>
New-style sites offer an open-ended set of interfaces. Any plug-in can extend
the set of site interfaces using the <span
style="font-style: italic;">org.eclipse.core.component.types</span> extension
point. Although the set of site interfaces can be extended, all sites support
the same set, ensuring that any part can be plugged into any site. It is possible
to view the complete set of site interfaces using the PDE plug-in registry view.<br>
<br>
The workbench supplies the following site interfaces:<br>
<br>
<table style="width: 100%; text-align: left;" border="1" cellpadding="2"
cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; font-weight: bold;">Interface<br> </td>
<td style="vertical-align: top; font-weight: bold;">Description<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">IErrorContext<br> </td>
<td style="vertical-align: top;">Constructs and logs IStatus messages to
the plug-in log.<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">Bundle<br> </td>
<td style="vertical-align: top;">The plug-in bundle containing the part's
implementation. This informs other components, such as the implementation
of IErrorContext, automatically of their plug-ins.<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">IContainer<br> </td>
<td style="vertical-align: top;">The site's container. This object can be
queried for any of the other site interfaces, which can be useful if the
part wants to redirect or multiplex everything from its site to its children.<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;">INameable<br> </td>
<td style="vertical-align: top;">Allows a part to set its name, icon, tooltip,
and content description. Replaces the various get methods and listeners
on IWorkbenchPart.<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">Composite<br> </td>
<td style="vertical-align: top;">Parent composite for the part. This composite
is not shared with any other parts, and will be disposed at the same time
as the part. The part is allowed to set the layout and attach listeners
to this composite.<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">ISecondaryId<br> </td>
<td style="vertical-align: top;">Interface that returns a part's secondary
ID when used as a multi-instance view.<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">ResourceManager<br> </td>
<td style="vertical-align: top;">Safely allocates and deallocates Images,
Fonts, Colors, and other SWT resources. Ensures that identical resources
are shared between parts and that any leaks get cleaned up when the part
is closed.<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">IDirtyHandler<br> </td>
<td style="vertical-align: top;">Allows parts to set or clear their dirty
state.<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">IMessageDialogs<br> </td>
<td style="vertical-align: top;">Displays error, warning, and info dialogs
to the user.<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">IActionBars<br> </td>
<td style="vertical-align: top;"><font color="#FF0000">Serves the same purpose
as getViewSite().getActionBars() did with the Eclipse 3.0 API.<br>
</font> </td>
</tr>
<tr>
<td style="vertical-align: top;">IMultiplexer<br> </td>
<td style="vertical-align: top;">Provides a multiplexed component with access
to its multiplexer and any shared interfaces<br>
. </td>
</tr>
<tr>
<td style="vertical-align: top;">ISavedState<br> </td>
<td style="vertical-align: top;">Holds the previously-persisted state of
the part.<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">IPartFactory<br> </td>
<td style="vertical-align: top;">Allows a part to create nested views and
editors.<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">IPartDescriptor<br> </td>
<td style="vertical-align: top;">Holds meta-info about a part such as its
ID, title, default image, and so on.<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">IEditorInput<br> </td>
<td style="vertical-align: top;">Holds the editor input for an editor. Points
to an empty editor input for views.<br> </td>
</tr>
<tr>
<td style="vertical-align: top;">ISelectionHandler<br> </td>
<td style="vertical-align: top;">Handles selection changes. Parts can use
this to change the selection they provide to the workbench.<br> </td>
</tr>
</tbody>
</table>
<p>It is up to the part's containing context to determine whether the part gets
a unique instance for each interface or an object shared among several parts.
The part's constructor never receives a null argument.</p>
<p>&nbsp;</p>
<h3>Using new site interfaces with existing parts</h3>
<p>Although constructor injection is convenient, it would be impractical to rewrite
every existing editor and view to use constructor injection in order to take
advantage of the new site interfaces. For this reason, all of the new interfaces
are also available to existing views as adapters on IWorkbenchPartSite. <br>
</p>
<p>Here is a view containing a single button that opens a message dialog.</p>
<p><img
src="images/dependencies_view.PNG" alt="Image of DependenciesViewOld"></p>
<p> The following example shows the source for a new-style view that opens the
dialog using the new IMessageDialogs interface.</p>
<div style="margin-left: 40px;">
<p><code>/**<br>
&nbsp;* Demonstrates how to use component dependencies in a new-style part.<br>
&nbsp;* <br>
&nbsp;* @since 3.1<br>
&nbsp;*/<br>
public class DependenciesViewNew {<br>
&nbsp;&nbsp;&nbsp; // Dependencies<br>
&nbsp;&nbsp;&nbsp; private IMessageDialogs dialogs;<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; /**<br>
&nbsp;&nbsp;&nbsp;&nbsp; * Component constructor. Do not invoke directly.<br>
&nbsp;&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp; public DependenciesViewNew(Composite parent, <span
style="color: rgb(255, 0, 0);">IMessageDialogs dialogs</span>) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
style="color: rgb(255, 0, 0);">this.dialogs = dialogs;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Button testButton = new Button(parent,
SWT.PUSH);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; testButton.setText("Open a dialog");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; testButton.addSelectionListener(new
SelectionAdapter() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* (non-Javadoc)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void widgetSelected(SelectionEvent
e) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; openADialog();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; private void openADialog() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
style="color: rgb(255, 0, 0);">dialogs.open(IStatus.INFO, "This is a message");</span><br>
&nbsp;&nbsp;&nbsp; }<br>
}</code><br>
</p>
</div>
<p>This example shows a traditional view that opens a dialog using IMessageDialogs
demonstartes that this is also possible using a traditional workbench part.
The lines in red font show how the IMessageDialogs interface is initialized
and used in each case. <br>
</p>
<div style="margin-left: 40px;">
<p><code>/**<br>
&nbsp;* Demonstrates how to use component dependencies in an old-style view<br>
&nbsp;* <br>
&nbsp;* @since 3.1<br>
&nbsp;*/<br>
public class DependenciesViewOld extends ViewPart {<br>
&nbsp;&nbsp;&nbsp; // Dependencies<br>
&nbsp;&nbsp;&nbsp; private IMessageDialogs dialogs;<br>
&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp;&nbsp; // Main widget<br>
&nbsp;&nbsp;&nbsp; private Composite parent;<br>
&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp;&nbsp; /* (non-Javadoc)<br>
&nbsp;&nbsp;&nbsp;&nbsp; * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)<br>
&nbsp;&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp; public void createPartControl(Composite parent) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.parent = parent;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
style="color: rgb(255, 0, 0);">this.dialogs = (IMessageDialogs)getSite().getAdapter(IMessageDialogs.class);</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Button testButton = new Button(parent,
SWT.PUSH);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; testButton.setText("Open a dialog");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; testButton.addSelectionListener(new
SelectionAdapter() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* (non-Javadoc)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void widgetSelected(SelectionEvent
e) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; openADialog();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp;&nbsp; private void openADialog() {<br>
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if (dialogs != null) {</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
dialogs.open(IStatus.INFO, "This is a message");</span><br
style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}</span><br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; /* (non-Javadoc)<br>
&nbsp;&nbsp;&nbsp;&nbsp; * @see org.eclipse.ui.IWorkbenchPart#setFocus()<br>
&nbsp;&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp; public void setFocus() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parent.setFocus();<br>
&nbsp;&nbsp;&nbsp; }<br>
}</code></p>
<p>&nbsp; </p>
</div>
</BODY>
</HTML>