PDI Spoon Plugin Development
PDI Spoon Plugin Development
Spoon plugins provide developers the ability to add new or modify existing functionality of the Spoon UI. A Spoon plugin can modify any area that's been written in Pentaho XUL Xul Developer's Guide (http://wiki.pentaho.com/display/ServerDoc2x/The+Pentaho+XUL+Framework+Developer's+Guide). They can also provide whole new areas of funtionality to Spoon through the concept of a Spoon Perspective, which is not limited to XUL.
Attached to this wiki is a zip file containing an example Spoon Plugin, some of which you'll see below. In addition to a simple Hello World example, it also contains a more complex document-based Spoon Perspective.
Current Spoon Plugin Doc:
Common Use Cases
The most common use case is to add new functionality to Spoon. However, user interface elements can be hidden, rearranged or have their behaviors changed by Spoon Plugins.
Spoon Plugin Structure
Spoon Plugins are packaged as a folder under the $SPOON_HOME/plugins/spoon folder. They contain a plugin.xml file which contains a list of Plugin class names, and a lib directory where the plugin jar and all needed dependent jars are located. Spoon Plugins can also be supplied using annotated classes
<?xml version='1.0' encoding='UTF-8'?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="YOUR_BEAN_ID" class="org.sample.YourSpoonPluginClass"></bean> </beans>
@SpoonPlugin(id = "SpoonExample", image = "") @SpoonPluginCategories({"spoon"}) public class HelloWorldSpoonPlugin implements SpoonPluginInterface { .... }
Spoon Plugin Implementations
Spoon Plugins don't tell Spoon where they're to be applied. Instead the control is inverted and every Spoon Plugin registered will be asked to apply itself to a given area (category) when that area is loaded. For instance when the Database Explorer dialog is created all plugins will be given the chance to make their customizations.
public void applyToContainer(String category, XulDomContainer container) throws XulException { container.registerClassLoader(getClass().getClassLoader()); if(category.equals("spoon")){ container.loadOverlay("org/pentaho/di/plugins/examples/helloworld/res/spoon_overlay.xul"); container.addEventHandler(new HelloWorldPerspectiveHandler()); } }
Plugin Area |
Category ID |
---|---|
Spoon Menusystem and toolbar |
"spoon" |
Database Explorer Dialog |
"database_dialog" |
Job Toolbar |
"job-graph" |
Transformation Toolbar |
"trans-graph" |
Repository Explorer |
"repository-explorer" |
Providing New Prespectives to Spoon
Perspectives are wholly distinct area of functionality. Spoon ships with several, from ETL to Agile BI, Scheduling, etc. Most are XUL-based, but you can implement them is pure SWT as well.
Perspectives are supplied through Spoon Plugins. Simply implement the following:
public SpoonPerspective getPerspective() { return HelloWorldSwtPerspective.getInstance(); }
Perspectives must implement several methods which provide Spoon with what it needs to manage their presentation and by which it can notify the perspective when it's become active.
Method |
Description |
---|---|
getId() |
Unique ID |
getUI() |
Return the Composite panel |
getDisplayName(Locale l) |
Localized name |
getPerspectiveIcon() |
Icon to be showed in the toolbar |
setActive(boolean active) |
Notification when active state changes |
getOverlays() |
Return a list of XulOverlays to apply when your perspective is activated |
getEventHandlers() |
Return a list of XulEventHandlers to be added to Spoon |
addPerspectiveListener(...listener) |
Allows outside code to register to for activation events for this perspective |
getActiveMeta() |
Return the active EngineMeta in the case of perspectives with save-able content |
public class HelloWorldSwtPerspective implements SpoonPerspective { private Composite comp; private static HelloWorldSwtPerspective instance = new HelloWorldSwtPerspective(); private HelloWorldSwtPerspective(){ createUI(); } private void createUI(){ comp = new Composite(((Spoon) SpoonFactory.getInstance()).getShell(), SWT.BORDER); comp.setLayout(new GridLayout()); comp.setLayoutData(new GridData(GridData.FILL_BOTH)); Label lbl = new Label(comp, SWT.CENTER); lbl.setLayoutData(new GridData(GridData.FILL_BOTH)); lbl.setText("This perspective has added two menu-items to the Spoon menu-system. One is under " + "Tools->\"Spoon Plugin Example\", the other is only visible when the perspective is active: " + "Edit->\"Perspective Only Action\""); } public static HelloWorldSwtPerspective getInstance(){ return instance; } public void setActive(boolean b) { } public List<XulOverlay> getOverlays() { return Collections.singletonList((XulOverlay) new DefaultXulOverlay("org/pentaho/di/plugins/examples/helloworld/res/spoon_perspective_overlay.xul")); } public List<XulEventHandler> getEventHandlers() { return Collections.singletonList((XulEventHandler) new HelloWorldPerspectiveHandler()); } public void addPerspectiveListener(SpoonPerspectiveListener spoonPerspectiveListener) { } public String getId() { return "helloWorld"; } // Whatever you pass out will be reparented. Don't construct the UI in this method as it may be called more than once. public Composite getUI() { return comp; } public String getDisplayName(Locale locale) { return "Spoon Example"; } public InputStream getPerspectiveIcon() { ClassLoader loader = getClass().getClassLoader(); return loader.getResourceAsStream("org/pentaho/di/plugins/examples/helloworld/res/blueprint.png"); } /** * This perspective is not Document based, therefore there is no EngineMeta to save/open. */ public EngineMetaInterface getActiveMeta() { return null; } }