blob: d752746bc1a6fa6872bd5a2f5898b0646a27bd7c [file] [log] [blame]
<!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>Implementing multiplexing components</title>
</HEAD>
<BODY BGCOLOR="#ffffff">
<H2>Implementing multiplexing components</H2>
In order to be used in a Multiplexer, site interfaces need to register an alternative
default implementation with the <span
style="font-style: italic;">org.eclipse.ui.part.SiteMultiplexerInitializer</span>
scope. Since this extends the site scope, the more specific multiplexer version
will take priority over the default version when used in a Multiplexer. <br>
<br>
A multiplexed component will almost always use the following pattern:
<ol>
<li>Implement the INestedComponent lifecycle interface;</li>
<li>Take an IMultiplexer in their constructor and use it to access the shared
version of their interface; </li>
<li>Store the part's state;</li>
<li>Listen to state changes in the child and update the stored state appropriately;</li>
<li>Each time the component is activated, it should forward the stored state
to the shared interface in the multiplexer; </li>
<li>While the component is active, it should forward state changes directly
to the shared interface.</li>
</ol>
The following example demonstrates the code used by the workbench to multiplex
the ISelectionHandler interface with ChildSelectionHandler.
<pre>
/**
* Multiplexed version of the ISelectionHandler interface
*
* @since 3.1
*/
public class ChildSelectionHandler implements ISelectionHandler, INestedComponent {
private ISelectionHandler parent;
private ISelection selection;
private boolean isActive = false;
private IMultiplexer multiplexer;
public ChildSelectionHandler(IMultiplexer mplex) throws DependencyException {
this.multiplexer = mplex;
// Get access to the shared ISelectionHandler being multiplexed (we should
// only modify it when we're the active child)
this.parent = (ISelectionHandler)
mplex.getSharedComponents().getComponent(ISelectionHandler.class);
// Set the initial state (the part's initial selection will be null
// until it explicitly sets it).
}
public IMultiplexer getMultiplexer() {
// Return the multiplexer we were created with
return multiplexer;
}
public void activate() {
// Forward our stored selection to the shared interface
parent.setSelection(selection);
isActive = true;
}
public void deactivate() {
isActive = false;
}
public void setSelection(ISelection newSelection) {
// Remember the child's new selection
selection = newSelection;
if (isActive) {
// If we're active, forward the selection directly to the
// shared interface
parent.setSelection(newSelection);
}
}
}
</pre>
Here is the associated extension point markup for ChildSelectionHandler.
<pre>
&lt;extension point="org.eclipse.core.component.types"&gt;
&lt;component
implementation="org.eclipse.ui.internal.part.services.ChildSelectionHandler"
interface="org.eclipse.ui.part.services.ISelectionHandler"
singleton="false"
initializer="org.eclipse.ui.part.SiteMultiplexerInitializer"/&gt;
&lt;/extension&gt;
</pre>
<div style="margin-left: 40px;"><img src="images/composite_view.PNG" alt="Screenshot of TestCompositeView"><br>
<br>
</div>
</BODY>
</HTML>