Writing your first view
The ViewPart Abstract Class
ViewPart (part of the org.karora.moomba.ui.part package) is a very simple class to work with. If you are familiar at all with the Eclipse APIs then you will find this, and most of the workbench APIs follow much the same format. This class consists of the following methods:
public interface IViewPart { public void init(IViewSite site); public void createPartControl(Component parent); }
init - This is called by the workbench when the ViewPart is first created.
createPartControl - Is the key method. When you implement this method you will add all your widgets/UI components and such on to the Echo2 component passed in. This method is called by the workbench and should not be called by the client.
Writing a hello world part
So lets create a new class, you'll notice the archetype created some hello world classes for you earlier, however these won't run out of the box without some configuration (hah!).
- Create a new class that extends ViewPart. Lets call it "HelloBigWorldPart"
In createPartControl, add some form of component container, such as a column, row, whatever takes your fancy. (Check out the Echo2 api for more information about components and such). Throw a label on it stating "Hello World". Then add this component to the parent component passed in. Maybe it would look a bit like the following.
public void createPartControl(Component parent) { Column content = new Column(); Label myLabel = new Label("Hello World"); content.add(myLabel); parent.add(content); }
Adding the view to a perspective
To see the view it needs to be added to a perspective. Let's add this view to the perspective created in the previous tutorial. Adding the following line to the HelloWorldPerspective.createInitialLayout method will do this for us.
layout.addView("helloworld.HelloBigWorldPart");
Note: There are 2 addView methods in the IPageLayout interface. This method adds the view directly under previous views. The second method allows detailed positioning of the view within the perspective.
Spring/OSGi configuration files
As of Moomba-0.8 there is no longer any support for defining views as either OSGI services or Spring beans.
Plugin.XML definition
In the root directory of your project, you will need a file called "plugin.xml". If you're using Eclipse as your development environment, this file will most likely be created for you via the Plugin development environment. In this file, you will need something along the lines of the following:
<extension point="org.karora.moomba.ui.views"> <view id="org.karora.wiki.demo.DemoView" name="Demo View" icon="icons/sample.gif" class="org.karora.wiki.demo.DemoView"> </view> </extension>
The ID you use should match the ID you defined in your IPerspectiveFactory implementation.
You can find out more about the org.karora.moomba.ui.views extension point here: Views - org.karora.moomba.ui.views
MANIFEST.MF
If you haven't done so already, you should have an import package statement for "org.karora.moomba.ui". You should also have an export package statement for the package containing your view.
How Moomba Views have evolved since 0.7
Prior to Moomba 0.8, the workbench recognised views by them being exported as OSGI services (under the interface org.karora.moomba.ui.IViewPart). If you were not running in an OSGI environment, they were detected by being registered as Spring beans. However Karora has since decided to focus even further on adherence to the Eclipse way of doing things which means using the Eclipse Extension Registry for detecting new extensions. This means Views registered as Spring beans or OSGI services will no longer be recognised by the Moomba Workbench and will consequently not appear.

Add Comment