| 23 |
some revision before the end of the Eclipse 3.1 development cycle. |
some revision before the end of the Eclipse 3.1 development cycle. |
| 24 |
<h3>The Basic Resource Mapping API</h3> |
<h3>The Basic Resource Mapping API</h3> |
| 25 |
<p>This solution involves adding API to the Resources plugin that maps logical |
<p>This solution involves adding API to the Resources plugin that maps logical |
| 26 |
elements to physical ones. The API is purposely simple with logical model manipulations |
models elements to workspace (i.e. file system) resources. The API is purposely |
| 27 |
omitted. A client can't use this interface to display logical models or gain |
simple with logical model manipulations omitted. A client can't use this interface |
| 28 |
any interesting additional knowledge about it. The API consists of the following |
to display logical models or gain any interesting additional knowledge about |
| 29 |
classes: </p> |
it. It's purpose is simply to map one or more model elements to workspace resources. |
| 30 |
|
</p> |
| 31 |
|
<p>The API consists of the following classes: </p> |
| 32 |
<ul> |
<ul> |
| 33 |
<li><strong>ResourceMapping</strong>: class to which logical model elements |
<li><strong>ResourceMapping</strong>: The Class to which logical model elements |
| 34 |
adapt to indicate that the model corresponds to a set of resources in the |
adapt to indicate that the model corresponds to a set of resources in the |
| 35 |
workspace. The complete <code>ResourceMapping</code> class can be viewed <a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.core.resources/src/org/eclipse/core/resources/mapping/ResourceMapping.java?rev=HEAD&content-type=text/vnd.viewcvs-markup">here</a>. |
workspace. The complete <code>ResourceMapping</code> class can be viewed <a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.core.resources/src/org/eclipse/core/resources/mapping/ResourceMapping.java?rev=HEAD&content-type=text/vnd.viewcvs-markup">here</a>. |
| 36 |
The methods of interest are: |
The methods of interest are: |
| 47 |
to which the resources in the traversal are associated with the originating |
to which the resources in the traversal are associated with the originating |
| 48 |
model object. Resource traversals are provided to a client by a resource mapping |
model object. Resource traversals are provided to a client by a resource mapping |
| 49 |
in order to describe the contents of a model in sich a way that a repository |
in order to describe the contents of a model in sich a way that a repository |
| 50 |
provider can perform its operations in as efficient a means as possible.</li> |
provider can perform its operations in as efficient a means as possible. Methods |
| 51 |
|
of interest are: |
| 52 |
|
<ul> |
| 53 |
|
<li><code>getResources()</code></li> |
| 54 |
|
<li><code>getDepth()</code></li> |
| 55 |
|
</ul> |
| 56 |
|
</li> |
| 57 |
<li><strong>ResourceMappingContext</strong>: a context that is provided to the |
<li><strong>ResourceMappingContext</strong>: a context that is provided to the |
| 58 |
resource mapping by the client. This context allows the logical model to determine |
resource mapping by the client when obtaining traversals. This context allows |
| 59 |
what the remote state of the model is so that the proper resources can be |
the logical model to determine what the remote state of the model is so that |
| 60 |
covered by the resource traversals returned by the resource mapping. The use |
the proper resources can be covered by the resource traversals returned by |
| 61 |
of the<code> <a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.core.resources/src/org/eclipse/core/resources/mapping/ResourceMappingContext.java?rev=HEAD&content-type=text/vnd.viewcvs-markup">ResourceMappingContext</a></code> |
the resource mapping. The use of the<code> <a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.core.resources/src/org/eclipse/core/resources/mapping/ResourceMappingContext.java?rev=HEAD&content-type=text/vnd.viewcvs-markup">ResourceMappingContext</a></code> |
| 62 |
is a bit more complicated and is described <a href="#ResourceMappingContext">later</a>.</li> |
is a bit more complicated and is described <a href="#ResourceMappingContext">later</a>.</li> |
| 63 |
</ul> |
</ul> |
| 64 |
<p>There are two types of plugins that should be interested in resource mappings. |
<p>There are two types of plugins that should be interested in resource mappings. |
| 65 |
Those who provide a model that consists of or is persisted in resources in the |
Those who provide a model that consists of, or is persisted in, resources in |
| 66 |
workspace and those that want to perform operations of resources. The following |
the workspace and those that want to perform operations on resources. The following |
| 67 |
two sections describe how to associate a resource mapping with a model object |
two sections describe how to associate a resource mapping with a model object |
| 68 |
and how to contribute menus to objects that adapt to resource mappings.</p> |
and how to contribute menus to objects that adapt to resource mappings.</p> |
| 69 |
<h4>Adapting a Model to a ResourceMapping</h4> |
<h4>Adapting a Model to a ResourceMapping</h4> |
| 70 |
<p>Plugins that adapted their model objects to <code>IResource</code> in order |
<p>Plugins that adapted their model objects to <code>IResource</code> in order |
| 71 |
to get resource specific object contributions shown in the context menu can |
to get resource specific actions shown in the context menu can now adapt to |
| 72 |
now adapt to <code>ResourceMapping</code> if a richer description of how the |
<code>ResourceMapping</code> if a richer description of how the object adapts |
| 73 |
object adapts to resources is benefitial. However, they are not required to |
to resources is benefitial. However, they are not required to do so if there |
| 74 |
do so if there is no benefit. For instance a Java class that now currently adapts |
is no benefit. For instance a Java class that now currently adapts to <code>IFile</code> |
| 75 |
to <code>IFile</code> need no adapt to <code>ResourceMapping</code> since nothing |
need not adapt to <code>ResourceMapping</code> since nothing is gained. However, |
| 76 |
is gained. However, a Java package shoudl adapt to <code>ResourceMapping</code> |
a Java package should adapt to <code>ResourceMapping</code> in order to indicate |
| 77 |
in order to indicate that the package is only the files in the corresponding |
that the package is only the files in the corresponding folder and not the subfolders.</p> |
| 78 |
folder and not the subfolders.</p> |
<p>The preferred way to adapt model elements to a resource mapping is to use an |
| 79 |
<p>An adapter factory can be used to adapt model objects into resource mappings. |
adapter factory. The following is the XML markup for contributing an adapter |
| 80 |
The following is the XML markup for contributing an adapter factory in a plugin |
factory in a plugin manifest. </p> |
|
manifest. </p> |
|
| 81 |
<pre style="background-color: rgb(204, 204, 255);"> <extension<br> point="org.eclipse.core.runtime.adapters"><br> <factory<br> class="org.eclipse.example.library.logical.AdapterFactory"<br> adaptableType="org.eclipse.example.library.Book"><br> <adapter type="org.eclipse.core.resources.mapping.ResourceMapping"/><br> </factory><br> <factory<br> class="org.eclipse.example.library.logical.AdapterFactory"<br> adaptableType="org.eclipse.example.library.Library"><br> <adapter type="org.eclipse.core.resources.mapping.ResourceMapping"/><br> </factory><br> ...<br> </extension></pre> |
<pre style="background-color: rgb(204, 204, 255);"> <extension<br> point="org.eclipse.core.runtime.adapters"><br> <factory<br> class="org.eclipse.example.library.logical.AdapterFactory"<br> adaptableType="org.eclipse.example.library.Book"><br> <adapter type="org.eclipse.core.resources.mapping.ResourceMapping"/><br> </factory><br> <factory<br> class="org.eclipse.example.library.logical.AdapterFactory"<br> adaptableType="org.eclipse.example.library.Library"><br> <adapter type="org.eclipse.core.resources.mapping.ResourceMapping"/><br> </factory><br> ...<br> </extension></pre> |
| 82 |
|
<p>The adapter factory implementation would look something like this:</p> |
| 83 |
|
<pre style="background-color: rgb(204, 204, 255);">public class AdapterFactory implements IAdapterFactory { |
| 84 |
|
public Object getAdapter(Object adaptableObject, Class adapterType) { |
| 85 |
|
if((adaptableObject instanceof EObject) && adapterType == ResourceMapping.class) { |
| 86 |
|
return new EMFResourceMapping((EObject)adaptableObject); |
| 87 |
|
} |
| 88 |
|
return null; |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
public Class[] getAdapterList() { |
| 92 |
|
return new Class[] {ResourceMapping.class}; |
| 93 |
|
} |
| 94 |
|
}</pre> |
| 95 |
<p>For popup menu contribuions, it is not required that the model objects implement |
<p>For popup menu contribuions, it is not required that the model objects implement |
| 96 |
the <code>IAdaptable</code> interface. However, if they do they must ensure |
the <code>IAdaptable</code> interface. However, if they do they must ensure |
| 97 |
that the Platform adapter manager is consulted. This can be done by either subclassing |
that the Platform adapter manager is consulted. This can be done by either subclassing |
| 187 |
file from a repository, the user would expect that any new images would be included. |
file from a repository, the user would expect that any new images would be included. |
| 188 |
The getTraversals method for a ResourceMapping for the HTML file model would |
The getTraversals method for a ResourceMapping for the HTML file model would |
| 189 |
look something like this:</p> |
look something like this:</p> |
| 190 |
<pre style="background-color: rgb(204, 204, 255);">public class HTNLResourceMapping extends ResourceMapping { |
<pre style="background-color: rgb(204, 204, 255);">public class HTMLResourceMapping extends ResourceMapping { |
| 191 |
private HTMLFile htmlFile; |
private HTMLFile htmlFile; |
| 192 |
getTraversals(ResourceMappingContext context, IPorgressMonitor monitor) { |
getTraversals(ResourceMappingContext context, IPorgressMonitor monitor) { |
| 193 |
IResource[] resources = htmlFile.getRsources(); |
IResource[] resources = htmlFile.getRsources(); |