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

Corona HowTo: Customize "Project Container Explorer" view

Eclipse Home Wiki Home Development How To...

Expandable RepositoryDescriptors

Introduction

By default Project Container Explorer view in corona without any additional work is capable of showing following objects:

  • ProjectContextContainer
  • ProjectContextContainerStub
  • RepositoryDescriptor
  • RepositoryDescriptorStub

In following structure:

  - ProjectContextContainer
  |  |
  |  |RepositoryDescriptor
  |  |
  |  |RepositoryDescriptorStub
  + ProjectContextContainerStub

Please note that RepositoryDescriptors are leafs in the displayed tree. There might be a need that some of the repository descriptors should 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.
Please see how new tree structure could look in the example below:
CoronaPcxViewTeamMember.JPG

New type of objects displayed in PCX

To achieve the result shown in above example the list of objects shown in the PCX had to be enlarged to:

  • IWorkbenchAdapter
  • IAdaptable (with IWorkbenchAdapter defined)
  • 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.
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: Join RepositoryDescriptorStub 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 IAdaptable article). Special 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 attribute can have any value.
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". It's also possible to restrict the range of RepositoryDescriptorStubs which have the IWorkbenchAdapter defined by setting up other attributes.

Example implementation

You can find exemplary implementation in package org.eclipse.corona.container.project.ui.explorer.views.team.

PCX action extension

//TODO describe pre and post pcx action calls

PreAction

PostAction

RepositoryDescriptorStub attributes

//TODO describe all the attributes based on which PCX action can be tested

Back to the top