Learn Eclipse RCP framework by using open source projects

Open source is not a new concept and you can find open source projects for almost all commonly used frameworks. In 2010, UCI published their project corpus which contains about 18,000 open source java projects. We can easily search and find projects that use popular frameworks such as Eclipse RCP, Struts 2, Spring, Android, etc.

It is a common sense that framework is hard to learn, especially those large framework that has thousands of classes/interfaces. Research has shown that one barrier is lack of examples. With those open source projects, I don’t think lack of example is so critical as it was before, because it is not hard to find examples. In the following, I will show how to use open source projects to learn Eclipse RCP framework.

Developers using Eclipse RCP can follow the “Monkey see, monkey do” rule. That is, find an existing project that use Eclipse RCP and do the similar thing. This approach is very efficient. There are basically two thing we need: a decent Eclipse RCP project and Eclipse Java API Doc. We start from reading the code and check the Doc whenever we see some class/interface/method not obvious to understand.

Here is a list of projects that use Eclipse RCP framework. Those can be called Eclipse RCP client applications and they are all from Google code. We can browse those RCP projects’ file layout and the source code of each class. I have verified their accessibility and here are the links:

Eclipse RCP open source projects:

  • http://code.google.com/p/localizedproperties/
  • http://code.google.com/p/audiotageditor/
  • http://code.google.com/p/pluralism/
  • http://code.google.com/p/eclipse-plugin-ftp-server/
  • http://code.google.com/p/change-impact-analysis/
  • http://code.google.com/p/eclipsender/
  • http://code.google.com/p/humiee/
  • http://code.google.com/p/zeusatlas/
  • http://code.google.com/p/i18n-mead-properties-plugin/
  • http://code.google.com/p/overtureeditor/

You can also browse commonly used classes or interfaces, and directly read their code by using API examples.

The first thing we learn is the layout of a typical project, i.e., a perspective, a view, etc.

Except the domain specific code, we can find framework API usage too.

For example, from this view class: http://code.google.com/p/eclipse-plugin-ftp-server/source/browse/trunk/plugin/src/com/holmconsulting/ftp/server/plugin/views/FTPServerView.java, it has the following createPartControl method.

public void createPartControl(Composite parent) {
       viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
                               | SWT.V_SCROLL | SWT.FULL_SELECTION);
       createColumns(viewer, parent);
       File rootDir = Activator.getDefault().getStateLocation().toFile();
       List<File> files = new ArrayList<File>();
       FileUtils.getInstance().loadFiles(rootDir, files);
       viewer.setContentProvider(new ViewContentProvider(files));
       viewer.setLabelProvider(new ViewLabelProvider());
       FileWrapperSorter sorter = new FileWrapperSorter();
       // Initial sort
                        viewer.getTable().getColumnCount() - 1));
       // Create the help context id for the viewer's control
                 .setHelp(viewer.getControl(), "viewer.context.help");
       //IContextService contextService = (IContextService) getSite()
       //              .getService(IContextService.class);
       PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "com.holmconsulting.ftp.server.plugin.viewer");

We can easily catch how to use a TableViewer, from the code snippet:

viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
 viewer.setContentProvider(new ViewContentProvider(files));
 viewer.setLabelProvider(new ViewLabelProvider());

Unlike Eclipse RCP, other frameworks may not have such an obvious layout and class hierarchy, I will explore how to use open source projects to learn other frameworks later.

Leave a Comment