Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Corona HowTo: Customize "Project Container Explorer" view"

m (Initial version 0.000001)
 
m (obsolete)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
<table border='1' cellpadding='3'>
 
<tr>
 
<td>[http://www.eclipse.org/corona Eclipse Home]</td>
 
<td>[[Corona|Wiki Home]]</td>
 
<td>[[Corona Development|Development]]</td>
 
<td>[[Corona HowTo|How To...]]</td>
 
</tr>
 
</table>
 
----
 
==Expandable RepositoryDescriptors==
 
By default Project Container Explorer view in corona without any additional coding is capable of showing following objects:
 
* ProjectContextContainer
 
* ProjectContextContainerStub
 
* RepositoryDescriptor
 
* RepositoryDescriptorStub
 
  
In following structure:
 
  - ProjectContextContainer
 
  |  |
 
  |  |RepositoryDescriptor
 
  |  |
 
  |  |RepositoryDescriptorStub
 
  + ProjectContextContainerStub
 
 
Please note that RepositoryDescriptors are leafs of displayed tree and on other additional elements can be shown under the repository descriptor.<br>
 
Some of the repository descritors could show additional information inside PCX view, let's take as an example "team member repository". The repository descriptor describing team members could show as it's leafs all team members defined for it.<br>
 
Please see how the new tree structure can look in the example below:<br>
 
[[Image:CoronaPcxViewTeamMember.JPG]]
 
===New type of objects displayed in PCX===
 
To achieve the result of RepositoryDescriptors with additional information the list of objects shown in the PCX was enlarged to:
 
* <b>IWorkbenchAdapter</b>
 
* <b>IAdaptable (with <i>IWorkbenchAdapter</i> defined)</b>
 
* ProjectContextContainer
 
* ProjectContextContainerStub
 
* RepositoryDescriptor
 
* RepositoryDescriptorStub
 
 
IWorkbenchAdapter interface provides common solution for all objects displayed in the tree, it contains all required method to show a tree view structure in different forms.<br>
 
Additionally RepositoryDescriptorStub was changed and now it's also implementing the IAdaptable interface.
 
===Step 1: Implement IWorkbenchAdapter interface for TeamMember RepositoryDescriptorStub===
 
As a first step we should implement the IWorkbenchAdapter which handles the RepositoryDescriptorStub objects. Let's call that class for TeamMembers the TeamRepositoryDescriptorWorkbenchAdapter. Below you can find the example of getChildren method:
 
  public Object[] getChildren(Object o) {
 
      if (o instanceof RepositoryDescriptorStub) {
 
        RepositoryDescriptor rd = ((RepositoryDescriptorStub) o).getRepositoryDescriptor();
 
        IRepositoryAdapter adapter = Activator.getRepositoryAdapter(rd);
 
        try {
 
            adapter.open();
 
            List<Object> l = new ArrayList<Object>();
 
            Iterator it = adapter.listResourceIds().iterator();
 
            while (it.hasNext()) {
 
              l.add((String) it.next());
 
            }
 
            adapter.close();
 
            return l.toArray();
 
        } catch (Exception e) {
 
            Activator.getCoronaLogService().log(CoronaLogService.LOG_ERROR, "Failed to open team repository!", e);
 
        }
 
      }
 
      return null;
 
  }
 
Please note that it will retrieve the list of objects ids which in the "Team Member" repository are strings and they are the team member login names. Following questions might arise now:
 
* how to connect the TeamRepositoryDescriptorWorkbenchAdapter class with the "Team Member Repository Descriptor".
 
* how do we know if repository descriptor stub in getChildren method is a "Team Member Repository Descriptor".
 
===Step 2: Connect repository descriptor stub with IWorkbenchAdapter===
 
As an eclipse developer you should be familiar with the idea of IAdaptable interface and IAdaptableFactory classes/concept (if not please read the [http://www.eclipsezone.com/articles/what-is-iadaptable IAdaptable article]). A special [http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.corona/plugins/org.eclipse.corona.container.project.ui/src/org/eclipse/corona/internal/container/project/ui/explorer/views/extension/WorkbenchAdapterAdaptableFactory.java?root=Technology_Project&view=markup adaptable factory class] was created for retrieving IWorkbenchAdapter adaptable for RepositoryDescriptorStub object. To use the factory use the repositoryDescriptorWorkbenchAdapter extension point like in example below:
 
  <extension
 
        point="org.eclipse.corona.container.project.ui.repositoryDescriptorWorkbenchAdapter">
 
      <repositoryDescriptorStubWorkbenchAdaptable
 
            class="org.eclipse.corona.container.project.ui.explorer.views.team.TeamRepositoryDescriptorWorkbenchAdapter"
 
            content-type="http://www.eclipse.org/corona/contentTypes/teamContent"
 
            access-type="any"
 
            name="any"
 
            uri="any"/>
 
  </extension>
 
The extension point defines which IWorkbenchAdapter object will be returned when calling RepositoryDescriptorStub.getAdapter(IWorkbenchAdapter) method, additional attributes like content-type etc provides better match for retrieving proper WorkbechAdapter. ''"any"'' string is reserved factory word which indicates that repository descriptor can have any value describing the attribute.<br>
 
The example above adds the TeamRepositoryDescriptorWorkbenchAdapter class for all repository descriptors which have the content-type equal to "http://www.eclipse.org/corona/contentTypes/teamContent".
 

Latest revision as of 10:58, 27 February 2008

Back to the top