| <!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="UTF-8" type="text/css"> |
| |
| <noscript></noscript> |
| <script type="text/javascript"> |
| function windowTitle() |
| { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="View Providers (CDO Model Repository Documentation)"; |
| } |
| } |
| </script> |
| |
| <link rel="stylesheet" href="../../editor.css" charset="UTF-8" type="text/css"> |
| |
| <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> |
| |
| <script src="http://code.jquery.com/ui/1.11.0/jquery-ui.min.js"></script> |
| |
| <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css"> |
| |
| <script> |
| $(function() { |
| $( ".resizable" ).resizable({ handles:"s,e,se", autoHide:true }); |
| }); |
| </script> |
| |
| <script type="text/javascript"> |
| function maximize(id) |
| { |
| e = document.getElementById('max_' + id); |
| c1 = document.getElementById('editor_content_1_' + id); |
| c2 = document.getElementById('editor_content_2_' + id); |
| pv = document.getElementById('max_pv_' + id); |
| if (e.className == 'max') |
| { |
| e.className = 'rst'; |
| e.setAttribute('title', 'Restore'); |
| c1.setAttribute('style_orig', c1.getAttribute('style')); |
| c1.setAttribute('style', 'border:2px solid #99b4d1; border-top:none;'); |
| c2.setAttribute('style', ''); |
| if (pv != null) |
| { |
| pv.setAttribute('width_orig', pv.getAttribute('width')); |
| pv.setAttribute('width', ''); |
| } |
| } |
| else |
| { |
| e.className = 'max'; |
| e.setAttribute('title', 'Maximize'); |
| c1.setAttribute('style', c1.getAttribute('style_orig')); |
| c1.setAttribute('style_orig', ''); |
| c2.setAttribute('style', 'overflow:scroll; width:100%; height:100%;'); |
| if (pv != null) |
| { |
| pv.setAttribute('width', pv.getAttribute('width_orig')); |
| pv.setAttribute('width_orig', ''); |
| } |
| } |
| } |
| </script> |
| </head> |
| |
| <body bgcolor="white" onload="windowTitle();"> |
| <!-- <div class="help_breadcrumbs breadcrumbs_top"><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="Doc02_PreparingModels.html" title="Backward to Preparing EMF Models for CDO"><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.9.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.9.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.9.0/org/eclipse/emf/ecore/resource/ResourceSet.html#getResource(org.eclipse.emf.common.util.URI, boolean)" title="Method in org.eclipse.emf.ecore.resource.ResourceSet"><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 class="te" colspan="3"><a href="Doc03_ViewProviders.html#ProviderImplementation" title="Chapter in CDO Model Repository Documentation">Implementing a View Provider</a></td></tr> |
| <tr><td>2 </td><td class="te" colspan="3"><a href="Doc03_ViewProviders.html#ContributeProviderProgrammatically" title="Chapter in CDO Model Repository Documentation">Contributing View Providers Programmatically</a></td></tr> |
| <tr><td>3 </td><td class="te" colspan="3"><a href="Doc03_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_ProviderImplementation_1"></a> |
| <table border="0" cellspacing="0" cellpadding="0"> |
| <tr> |
| <td width="25px"><div style="position:relative;"><img src="../../../images/editor-1.png"><img style="position:absolute; top:5px; left:5px;" src="../../../images/formatter-java.gif"></div></td> |
| <td style="background-image:url(../../../images/editor-2.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-3.png"></td> |
| <td style="background-image:url(../../../images/editor-4.png); background-repeat:repeat-x;" align="right"></td> |
| <td style="background-image:url(../../../images/editor-4.png); background-repeat:repeat-x;" align="center" width="16"><a href="javascript:maximize('ProviderImplementation_1')" id="max_ProviderImplementation_1" class="max" title="Maximize"> </a></td> |
| <td width="6px"><img src="../../../images/editor-5.png"></td> |
| </tr> |
| <tr> |
| <td colspan="6" align="left" valign="top" style="border:1px solid #a0a0a0; border-top:none;" nowrap> |
| <div id="editor_content_1_ProviderImplementation_1" class="ui-widget-content resizable" style="width:600px; height:300px; border:2px solid #99b4d1; border-top:none;"> |
| <div id="editor_content_2_ProviderImplementation_1" style="overflow:scroll; width:100%; height:100%;"> |
| <code> |
| <a name="callout_ProviderImplementation_1_1_code" href="#callout_ProviderImplementation_1_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_ProviderImplementation_1_2_code" href="#callout_ProviderImplementation_1_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> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <p> |
| <div style="margin-left:24px;"> |
| <a name="callout_ProviderImplementation_1_1" href="#callout_ProviderImplementation_1_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_ProviderImplementation_1_2" href="#callout_ProviderImplementation_1_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> |
| <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_ContributeProviderProgrammatically_1"></a> |
| <table border="0" cellspacing="0" cellpadding="0"> |
| <tr> |
| <td width="25px"><div style="position:relative;"><img src="../../../images/editor-1.png"><img style="position:absolute; top:5px; left:5px;" src="../../../images/formatter-java.gif"></div></td> |
| <td style="background-image:url(../../../images/editor-2.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-3.png"></td> |
| <td style="background-image:url(../../../images/editor-4.png); background-repeat:repeat-x;" align="right"></td> |
| <td style="background-image:url(../../../images/editor-4.png); background-repeat:repeat-x;" align="center" width="16"><a href="javascript:maximize('ContributeProviderProgrammatically_1')" id="max_ContributeProviderProgrammatically_1" class="max" title="Maximize"> </a></td> |
| <td width="6px"><img src="../../../images/editor-5.png"></td> |
| </tr> |
| <tr> |
| <td colspan="6" align="left" valign="top" style="border:1px solid #a0a0a0; border-top:none;" nowrap> |
| <div id="editor_content_1_ContributeProviderProgrammatically_1" class="ui-widget-content resizable" style="width:600px; height:300px; border:2px solid #99b4d1; border-top:none;"> |
| <div id="editor_content_2_ContributeProviderProgrammatically_1" style="overflow:scroll; width:100%; height:100%;"> |
| <code> |
| <font color="#3f7f5f">// Instantiate your view provider</font><br/> |
| CDOViewProvider viewProvider = <a name="callout_ContributeProviderProgrammatically_1_1_code" href="#callout_ContributeProviderProgrammatically_1_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_ContributeProviderProgrammatically_1_2_code" href="#callout_ContributeProviderProgrammatically_1_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> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <p> |
| <div style="margin-left:24px;"> |
| <a name="callout_ContributeProviderProgrammatically_1_1" href="#callout_ContributeProviderProgrammatically_1_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_ContributeProviderProgrammatically_1_2" href="#callout_ContributeProviderProgrammatically_1_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> |
| <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.9.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#MAX_VALUE" title="Field in java.lang.Integer"><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#MIN_VALUE" title="Field in java.lang.Integer"><code>Integer#MIN_VALUE</code></a> the minimum. |
| </ul> |
| |
| <p align="right"> |
| <a href="Doc02_PreparingModels.html" title="Backward to Preparing EMF Models for CDO"><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> |
| <!-- <div class="help_breadcrumbs breadcrumbs_bottom"><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> --> |
| |
| <div class="copyright">Copyright (c) 2014 Eike Stepper (Berlin, Germany) and others.<br>All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html</div> |
| </body> |
| </html> |