Chapter 4. Creating a new software component for Nuxeo RCP

Table of Contents

4.1. Creating a new plugin component
4.1.1. Creation of the plugin
4.1.2. Plugin dependencies
4.2. Document tabs
4.3. Viewers in Nuxeo
4.3.1. Adapters as providers.
4.3.2. Table/Tree columns

Adding a new software component to nuxeo RCP is finally similar to adding a classic Eclipse RCP component. However, you may have things that have been already done and you would like to reuse and the underlying application server is always different from one software to another.

This chapter will cover things that may be useful to know when starting coding for nuxeo RCP. Following the development of the "comments" component, you'll have a nice example of a nuxeo software component.

4.1. Creating a new plugin component

4.1.1. Creation of the plugin

New project -> Plugin development -> plugin project

Because it is a RCP application, you should use "Eclipse version 3.3" as target platform.

Check "no" to the question "Would you like to create a rich client application?": this option is for creating a new rich client application. We won't do that because our plugin will contribute to an existing rich client application

We won't create any template as well.

The others options are up to you.

4.1.2. Plugin dependencies

  • org.eclipse.core.runtime,

  • org.eclipse.ui,

  • org.nuxeo.ecm.rcp,

  • org.nuxeo.ecm.platform.comment.api (this is specific to the "comment" component),

  • org.nuxeo.ecm.core.api,

  • org.eclipse.ui.forms

4.2. Document tabs

Now that we have created the plug in, we are going to create a new tab to the document editor.

org.nuxeo.ecm.rcp.editors.DocumentPage classes are editor tabs classes you will have to subclass to create a new editor tabs in Nuxeo RCP.

Create a new class that subclass org.nuxeo.ecm.rcp.editors.DocumentPage. The most important part to look at is the method createPageContent. It will create the graphical widgets of the tab. You will create there your SWT/JFace widgets and forms, or other content that will be in the tab.

Once the class created, you need to reference it to the extension point "org.nuxeo.ecm.rcp.formPages".

4.3. Viewers in Nuxeo

Things have been done in the Nuxeo RCP to make easy the creation of table viewers and tree viewers.

If you are looking at DocumentCommentsPage, you'll notice that the viewer is creating by a CommentsManager. You'll have to create your own "Manager" if you want to use a treeViewer or a tableViewer. In Nuxeo, there are two classes you may reuse to create a manager: TreeViewerManager and TableViewerManager.

These ViewerManagers are another layer above JFace StructuredViewers. The methods you have to override are:

  • protected ItemAdapterFactory createAdapterFactory()

  • protected String[] getColumns()

  • protected String[] getColumnsHeader()

  • protected int getColumnSize(int columnIndex)

4.3.1. Adapters as providers.

The method createAdapterFactory() will provide a factory to ViewerManagers to create JFace label and content providers. These providers are managed underline behind adapters. So an adapter will provide pretty the same method than JFace providers that you will have to implement according to your needs.

For comments: see DocumentCommentsAdapter.

Here is how to add a new adapter to a ViewerManager :

protected ItemAdapterFactory createAdapterFactory() {
   ItemAdapterFactory factory = new ItemAdapterFactory();
   factory.registerAdapter(DocumentModel.class, new DocumentCommentsAdapter());
   return factory;
}

4.3.2. Table/Tree columns

Columns are managed with three other ViewerManagers methods.

getColumns will provide the array of String identifier of a column. For these columns, getColumnsHeader will provide the displayed header text. Then the last methods getColumnSize will return the size of the column according to its index.