Skip to end of metadata
Go to start of metadata

In this guide we show how to create custom ECL commands. As an example we create two ECL commands for Eclipse Views. First one will show us all registered views in our Eclipse. And the second one will open specified view by ID.
You can find source of the examples used in this guide in the ECL repository: https://github.com/xored/ecl/tree/master/examples

Create Plug-in Project

First of all we'll create new plugin project for our ECL commands called org.eclipse.ecl.example.view. You can you any existing plug-in as well.

Define EMF model for ECL command

We need to create two EMF classes to show registered plugins with ECL:

  • ShowViews which will be used as an ECL command. This EClass should extend Command EClass from the http://www.eclipse.org/ecl/core.ecore package
  • View which will be used to store view details. It should contains three string properties: id, label and description.

If you're not experienced EMF user you can find detailed instruction on the Define EMF model for ShowViews command page.

Implement ShowViews command

Now we need to implement ECL command. Make sure you have all necessary dependencies:

Implement ICommandService interface

Add new class ShowViewsService which implements org.eclipse.ecl.runtime.ICommandService interface as shown below:

As you can see the implementation is very simple. We use platform IViewRegistry to collect details of Eclise Views and store this information using EMF View objects. Then we write collected information to the output pipe. Note that view service will be executed using Eclipse Jobs, so we use Workbench Display to access view info in the UI thread.

Register ECL command implementation

Finally we need to register our service using org.eclipse.ecl.core.scriptlet extension point:

  • name - name of the EClass which we use for ECL command
  • namespace - EMF Package URI
  • class - command implementation class. Should implement ICommandService interface

By default name of the command EClass will be transformed to the ECL command name. For example, in our case commands will be named show-views. However you can override this name using friendly_name part of the org.eclipse.ecl.core.scriptlet extension point.

Use show-views command

  • Let's start new Eclipse instance with org.eclipse.ecl.example.view plugin installed
  • Connect to the ECL telnet server started in this Eclipse (on the 2323 port by default) using any telnet client
  • Enter show-views command

  • As a result of your command you will see something like this:

There is text presentation of the EMF objects collected from the Eclipse environment. However it's not readable enought for terminal. Fortunately ECL has core print command which can be used for better text presentation of the EMF objects. Let's use show-views | print command instead:

This presentation looks much better.

Add show-view command

In the previous sections we discussed how to collect information from Eclipse using ECL. Now let's add another command which will open some view by id.

Add ShowView EClass

Create one more EClass called ShowView with one string field id. This is ECL command and should extend Command EClass.

Implement ShowView command

Add ShowViewService java class:

We added this service specially for ShowView command, so we can freely cast specified command to ShowView interface. This allows us to get id of the view we need to open. Next we use Eclipse Platform API to open view by id in the UI thread.

Register ShowView command

Finally we need to register new command through org.eclipse.ecl.core.scriptlet extension point:

Use show-view command

Now we can run our plugin and open necessary view by id:

By the way, you can use show-views command to find id of a view you want to open.

Labels: