diff options
author | Eike Stepper | 2012-01-10 14:52:23 +0000 |
---|---|---|
committer | Eike Stepper | 2012-01-10 14:52:23 +0000 |
commit | 0e4d5df279b8c92255af38579cdc15a545766a21 (patch) | |
tree | cf094bfa94317154c470987581c3ba8677792f34 /plugins/org.eclipse.emf.cdo.doc/html/programmers/client/ViewProviders.html | |
parent | b7cb58538e6371d97fecb399d5d35f514dca4351 (diff) | |
download | cdo-0e4d5df279b8c92255af38579cdc15a545766a21.tar.gz cdo-0e4d5df279b8c92255af38579cdc15a545766a21.tar.xz cdo-0e4d5df279b8c92255af38579cdc15a545766a21.zip |
[367905] [CDO] Allow Adapters to be notified during loading
https://bugs.eclipse.org/bugs/show_bug.cgi?id=367905
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.doc/html/programmers/client/ViewProviders.html')
-rw-r--r-- | plugins/org.eclipse.emf.cdo.doc/html/programmers/client/ViewProviders.html | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/ViewProviders.html b/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/ViewProviders.html new file mode 100644 index 0000000000..d1d2cf3a59 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/ViewProviders.html @@ -0,0 +1,190 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<HTML> + +<HEAD> +<TITLE>View Providers (CDO Model Repository Documentation)</TITLE> + +<LINK REL="STYLESHEET" HREF="../../book.css" CHARSET="ISO-8859-1" TYPE="text/css"> + +<SCRIPT type="text/javascript"> +function windowTitle() +{ + if (location.href.indexOf('is-external=true') == -1) { + parent.document.title="View Providers (CDO Model Repository Documentation)"; + } +} +</SCRIPT> +<NOSCRIPT></NOSCRIPT> +</HEAD> + +<BODY BGCOLOR="white" onload="windowTitle();"> +<!-- <div class="help_breadcrumbs"><a href="../../Overview.html" title="CDO Model Repository Documentation">CDO Model Repository Documentation</a> > <a href="../index.html" title="Category in CDO Model Repository Documentation">Programmer's Guide</a> > <a href="index.html" title="Category in CDO Model Repository Documentation">Developing Client Applications</a></div> --> + +<table border="0"> + <tr> + <td width="100%"><h1>View Providers</h1></td> + <td align="right" valign="middle" nowrap><a href="Architecture.html" title="Backward to Understanding the Architecture of a Client Application"><img src="../../../images/backward.png" border="0"></a> <a href="../server/index.html" title="Forward to Dealing with Servers"><img src="../../../images/forward.png" border="0"></a></td> + </tr> +</table> +<p class="author">Author: Victor Roldan Betancort</p> +<p> + A <a href="../../../javadoc/org/eclipse/emf/cdo/view/CDOViewProvider.html" title="Interface in org.eclipse.emf.cdo.view"><code>view provider</code></a> allows clients to inject custom logic into the <a href="../../../javadoc/org/eclipse/emf/cdo/eresource/CDOResourceFactory.html" title="Interface in org.eclipse.emf.cdo.eresource"><code>resource factory</code></a> mechansim, capable of handling the whole <a href="../../../javadoc/org/eclipse/emf/cdo/session/CDOSession.html" title="Interface in org.eclipse.emf.cdo.session"><code>session</code></a> and <a href="../../../javadoc/org/eclipse/emf/cdo/view/CDOView.html" title="Interface in org.eclipse.emf.cdo.view"><code>view</code></a> + instantiation process. This permits to obtain <a href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.7.0/org/eclipse/emf/ecore/resource/Resource.html" title="Interface in org.eclipse.emf.ecore.resource"><code>resources</code></a> through the <a href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.7.0/org/eclipse/emf/ecore/resource/ResourceSet.html" title="Interface in org.eclipse.emf.ecore.resource"><code>resource set</code></a> + API transparently, without any prior CDO client API code. The view provider automatically kicks in the middle of the + <a href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.7.0/org/eclipse/emf/ecore/resource/ResourceSet.html" title="Interface in org.eclipse.emf.ecore.resource"><code>ResourceSet.getResource()</code></a> call, forgetting + about the whole openning session / openning transaction process, which happens behind the scenes. + <p> + This is quite useful when integrating CDO with EMF-based frameworks and tools that are not prepared for a CDO + scenario themselves. + <p> + <b>Table of Contents</b> <p> +<table border="0"> +<tr><td>1 </td><td colspan="3"><a href="ViewProviders.html#ProviderImplementation" title="Chapter in CDO Model Repository Documentation">Implementing a View Provider</a></td></tr> +<tr><td>2 </td><td colspan="3"><a href="ViewProviders.html#ContributeProviderProgrammatically" title="Chapter in CDO Model Repository Documentation">Contributing View Providers Programmatically</a></td></tr> +<tr><td>3 </td><td colspan="3"><a href="ViewProviders.html#ContributeProviderUsingExtensionPoint" title="Chapter in CDO Model Repository Documentation">Contributing View Providers Using Extension Points</a></td></tr> +</table> +</p> + + +<h2><a name="ProviderImplementation"></a>1 Implementing a View Provider</h2> +<p> + Clients should implement the <a href="../../../javadoc/org/eclipse/emf/cdo/view/CDOViewProvider.html" title="Interface in org.eclipse.emf.cdo.view"><code>CDOViewProvider</code></a> interface, or sub class the <a href="../../../javadoc/org/eclipse/emf/cdo/view/AbstractCDOViewProvider.html" title="Class in org.eclipse.emf.cdo.view"><code>AbstractCDOViewProvider</code></a> + class, which provides common functionality. + <p> + The example below shows a simple implementation that opens a <b>new</b> <a href="../../../javadoc/org/eclipse/emf/cdo/session/CDOSession.html" title="Interface in org.eclipse.emf.cdo.session"><code>session</code></a> to a local + server and a <b>new</b> <a href="../../../javadoc/org/eclipse/emf/cdo/transaction/CDOTransaction.html" title="Interface in org.eclipse.emf.cdo.transaction"><code>transaction</code></a> on that session. + <p> + + +<div class="snippet" style="margin-left:24px;" align="left"> + <a name="snippet_example"></a> + <table border="0" cellspacing="0" cellpadding="0"> + <tr> + <td><img src="../../../images/editor-top-left-java.png"></td> + <td style="background-image:url(../../../images/editor-top1.png); background-repeat:repeat-x;" width="1px"><font face="Segoe UI,Arial" size="-1">ExampleViewProvider.java</font></td> + <td width="1px"><img src="../../../images/editor-close.png"></td> + <td style="background-image:url(../../../images/editor-top2.png); background-repeat:repeat-x;"> </td> + <td><img src="../../../images/editor-top-right.png"></td> + </tr> + <tr> + <td style="background-image:url(../../../images/editor-left.png); background-repeat:repeat-y;"> </td> + <td colspan="3" align="left" valign="top" nowrap> + <div style="margin:10px 0px 10px 0px;"> + <code> + <a name="callout_example_1_code" href="#callout_example_1" alt="The example provider catches all URIs with shape "cdo.local:"." title="The example provider catches all URIs with shape "cdo.local:"."><img src="../../../images/callout-1.png" width="16" height="16" border="0" align="top"></a> <font color="#7f0055"><b>new </b></font>AbstractCDOViewProvider(<font color="#2a00ff">"cdo\\.local:.*"</font>, <font color="#990000">100</font>)<br/>
+ {<br/>
+ <font color="#7f0055"><b>private </b></font>IManagedContainer container;<br/>
+ <br/>
+ <a name="callout_example_2_code" href="#callout_example_2" alt="Register the provider with CDOViewProviderRegistry." title="Register the provider with CDOViewProviderRegistry."><img src="../../../images/callout-2.png" width="16" height="16" border="0" align="top"></a> <font color="#7f0055"><b>public </b></font>CDOView getView(URI uri, ResourceSet resourceSet)<br/>
+ {<br/>
+ <font color="#7f0055"><b>if </b></font>(container == <font color="#7f0055"><b>null</b></font>)<br/>
+ {<br/>
+ container = <font color="#7f0055"><b>new </b></font>ManagedContainer();<br/>
+ Net4jUtil.prepareContainer(container);<br/>
+ TCPUtil.prepareContainer(container);<br/>
+ container.activate();<br/>
+ }<br/>
+ <br/>
+ <font color="#7f0055"><b>int </b></font>startIndex = uri.toString().indexOf(<font color="#990000">':'</font>);<br/>
+ String repoName = uri.toString().substring(startIndex);<br/>
+ <br/>
+ IConnector connector = (IConnector)container.getElement(<font color="#2a00ff">"org.eclipse.net4j.connectors"</font>, <font color="#2a00ff">"tcp"</font>, <font color="#2a00ff">"localhost"</font>);<br/>
+ <br/>
+ CDONet4jSessionConfiguration config = CDONet4jUtil.createNet4jSessionConfiguration();<br/>
+ config.setConnector(connector);<br/>
+ config.setRepositoryName(repoName);<br/>
+ <br/>
+ CDOSession session = config.openNet4jSession();<br/>
+ <font color="#7f0055"><b>return </b></font>session.openTransaction();<br/>
+ }<br/>
+ }; + </code> + </div> + </td> + <td style="background-image:url(../../../images/editor-right.png); background-repeat:repeat-y;"> </td> + </tr> + <tr> + <td><img src="../../../images/editor-bottom-left.png"></td> + <td style="background-image:url(../../../images/editor-bottom.png); background-repeat:repeat-x;" colspan="3"> </td> + <td><img src="../../../images/editor-bottom-right.png"></td> + </tr> + </table> +</div> +<p> +<div style="margin-left:24px;"><a name="callout_example_1" href="#callout_example_1_code" alt="Jump to snippet..." title="Jump to snippet..."><img src="../../../images/callout-1.png" width="16" height="16" border="0" align="top"></a> The example provider catches all URIs with shape "cdo.local:<repoName>". + +</div> +<div style="margin-left:24px;"><a name="callout_example_2" href="#callout_example_2_code" alt="Jump to snippet..." title="Jump to snippet..."><img src="../../../images/callout-2.png" width="16" height="16" border="0" align="top"></a> Register the provider with <a href="../../../javadoc/org/eclipse/emf/cdo/view/CDOViewProviderRegistry.html" title="Interface in org.eclipse.emf.cdo.view"><code>CDOViewProviderRegistry</code></a>. + +</div> +<p> + + +<h2><a name="ContributeProviderProgrammatically"></a>2 Contributing View Providers Programmatically</h2> +<p> + A client's view provider implementation can be contributed programmatically to the <a href="../../../javadoc/org/eclipse/emf/cdo/view/CDOViewProviderRegistry.html" title="Interface in org.eclipse.emf.cdo.view"><code>CDOViewProviderRegistry</code></a>, + as the following example suggests: + <p> + + +<div class="snippet" style="margin-left:24px;" align="left"> + <a name="snippet_snippet2"></a> + <table border="0" cellspacing="0" cellpadding="0"> + <tr> + <td><img src="../../../images/editor-top-left-java.png"></td> + <td style="background-image:url(../../../images/editor-top1.png); background-repeat:repeat-x;" width="1px"><font face="Segoe UI,Arial" size="-1">ProviderContribution.java</font></td> + <td width="1px"><img src="../../../images/editor-close.png"></td> + <td style="background-image:url(../../../images/editor-top2.png); background-repeat:repeat-x;"> </td> + <td><img src="../../../images/editor-top-right.png"></td> + </tr> + <tr> + <td style="background-image:url(../../../images/editor-left.png); background-repeat:repeat-y;"> </td> + <td colspan="3" align="left" valign="top" nowrap> + <div style="margin:10px 0px 10px 0px;"> + <code> + <font color="#3f7f5f">// Instantiate your view provider</font><br/>
+ CDOViewProvider viewProvider = <a name="callout_snippet2_1_code" href="#callout_snippet2_1" alt="Get the target CDOViewProvider implementation." title="Get the target CDOViewProvider implementation."><img src="../../../images/callout-1.png" width="16" height="16" border="0" align="top"></a> org.eclipse.emf.internal.cdo.view.PluginContainerViewProvider.INSTANCE;<br/>
+ <br/>
+ <font color="#3f7f5f">// Add the instance to the registry</font><br/>
+ <a name="callout_snippet2_2_code" href="#callout_snippet2_2" alt="Add the provider instance to CDOViewProviderRegistry." title="Add the provider instance to CDOViewProviderRegistry."><img src="../../../images/callout-2.png" width="16" height="16" border="0" align="top"></a> CDOViewProviderRegistry.INSTANCE.addViewProvider(viewProvider); + </code> + </div> + </td> + <td style="background-image:url(../../../images/editor-right.png); background-repeat:repeat-y;"> </td> + </tr> + <tr> + <td><img src="../../../images/editor-bottom-left.png"></td> + <td style="background-image:url(../../../images/editor-bottom.png); background-repeat:repeat-x;" colspan="3"> </td> + <td><img src="../../../images/editor-bottom-right.png"></td> + </tr> + </table> +</div> +<p> +<div style="margin-left:24px;"><a name="callout_snippet2_1" href="#callout_snippet2_1_code" alt="Jump to snippet..." title="Jump to snippet..."><img src="../../../images/callout-1.png" width="16" height="16" border="0" align="top"></a> Get the target <a href="../../../javadoc/org/eclipse/emf/cdo/view/CDOViewProvider.html" title="Interface in org.eclipse.emf.cdo.view"><code>CDOViewProvider</code></a> implementation. + +</div> +<div style="margin-left:24px;"><a name="callout_snippet2_2" href="#callout_snippet2_2_code" alt="Jump to snippet..." title="Jump to snippet..."><img src="../../../images/callout-2.png" width="16" height="16" border="0" align="top"></a> Add the provider instance to <a href="../../../javadoc/org/eclipse/emf/cdo/view/CDOViewProviderRegistry.html" title="Interface in org.eclipse.emf.cdo.view"><code>CDOViewProviderRegistry</code></a>. + +</div> +<p> + + +<h2><a name="ContributeProviderUsingExtensionPoint"></a>3 Contributing View Providers Using Extension Points</h2> +<p> + A specific <a href="../../../javadoc/org/eclipse/emf/cdo/view/CDOViewProvider.html" title="Interface in org.eclipse.emf.cdo.view"><code>CDOViewProvider</code></a> implementation can also be contributed using the + <code>org.eclipse.emf.cdo.viewProviders</code> extension point. Clients specify: + <p> + <ul> + <li>A mandatory <b><code>class</code></b> implementing the <a href="../../../javadoc/org/eclipse/emf/cdo/view/CDOViewProvider.html" title="Interface in org.eclipse.emf.cdo.view"><code>CDOViewProvider</code></a> interface. + <li>A mandatory <b>regular expression</b> string indicating the shape of <a href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.7.0/org/eclipse/emf/common/util/URI.html" title="Class in org.eclipse.emf.common.util"><code>URIs</code></a> that should match with the contributed provider. + <li>An optional <b><code>priority</code></b> integer value, to indicate preference over other implementations + matching the same regular expression. A higher value indicates a higher priority, <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Integer.html" title="Class in java.lang"><code>Integer#MAX_VALUE</code></a> being + the maximum priority value and <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Integer.html" title="Class in java.lang"><code>Integer#MIN_VALUE</code></a> the minimum. + </ul> + +<p align="right"> +<a href="Architecture.html" title="Backward to Understanding the Architecture of a Client Application"><img src="../../../images/backward.png" border="0"></a> <a href="../server/index.html" title="Forward to Dealing with Servers"><img src="../../../images/forward.png" border="0"></a></p> +<HR> +<i>Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.</i> +</BODY> +</HTML> |