| Before you get started Before you get started, you may want to have some views to lay out on your perspective. Check out the view tutorial for more information. |
What is a perspective?
The basic structure of a Moomba application is a set of "views" which may or may not have "actions" associated with them. These views are then grouped together and laid out on a "perspective". This concept of a "perspective" maps directly to the concept of an Eclipse perspective.
To further illustrate this point, take a look at the following screenshots from the MOOMBA-0.5 demo: 
Here what we see is the "Demo perspective", as highlighted by the Moomba perspective switcher - the tab bar at the top of the screen. The demo perspective defines a layout for the Explorer, Help, Details and Dialogs view parts. The view parts themselves have no knowledge of any perspective that they may be participating in the layout of.
Now look at the screenshot below: 
By switching from the Demo Perspective to the OSGI perspective, we are shown a completely different view part layout. The OSGI perspective defines the layout containing the Bundles, Help, Services and Diagnostics View Parts.
To see this in action, have a look at http://www.karora.org/moomba-demo
Writing your first perspective
The IPerspectiveFactory Interface
IPerspectiveFactory (part of the org.karora.moomba.ui package) is a very simple interface 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 interface consists of one essentially self explanitory methods:
public interface IPerspectiveFactory { public Component createInitialLayout(IPageLayout layout); }
createInitialLayout - Is the key method. This method allows you to add views and actions to the page layout using the IPageLayout interface.
Writing a hello world perspective
The following assumes that you already have a project setup for creating this perspective.
Create a perspective factory class
- Create a new class that implements IPerspectiveFactory. Let's and call it HelloWorldPerspective
You will need to fill in all of the methods required by the interface. All are self explanatory except for "createInitialLayout". Detailed layouts are out of scope of this tutorial, however, you will want to put something like the following into your createInitialLayout section:
(Given two predefined views (View1, View2) with the IDs, org.karora.moomba.demo.View1 and org.karora.moomba.demo.View2)
public Component createInitialLayout(IPageLayout layout) { layout.addView("org.karora.moomba.demo.View1"); layout.addView("org.karora.moomba.demo.View2"); }
BE AWARE : We are not creating the view, nor are we specifying the class name here. Add view takes the ID of the view part. This id MUST be the ID that appears in your plugin.xml file for your view part. If the view part ID can not be located, the view part will not be loaded into the perspective. Of course, you're now probably asking "Why can't I just give it a class?". Its quite simple - the workbench runs in an entirely dynamic environment. As such, you want as little coupling as is possible. Referencing a class directly in a perspective would require an undesirable level of coupling in your dynamic workbench application, as we need to remember that bundles, services, etc in OSGI can come and go as they please. A class that is here today, may not be tomorrow.
Spring/OSGi configuration files
As of Moomba-0.8 there is no longer any support for defining perspectives 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.perspectives"> <perspective id="org.karora.wiki.demo.Demo" name="Demo Perspective" icon="icons/sample.gif" class="org.karora.wiki.demo.DemoPerspective"> </perspective> </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.perspectives extension point here: Perspectives - org.karora.moomba.ui.perspectives
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 perspective.
How Moomba Perspectives have evolved since 0.7
Prior to Moomba 0.8, the workbench recognised perspectives by them being exported as OSGI services (under the interface org.karora.moomba.ui.IPerspectiveFactory). 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 Perspectives registered as Spring beans or OSGI services will no longer be recognised by the Moomba Workbench and will consequently not appear.
More Information
The following link is a detailed article on perspectives and perspective extensions (See 'Extending an Existing Perspective').
http://www.eclipse.org/articles/using-perspectives/PerspectiveArticle.html
Note that perspective extensions currently only support view parts and these can only be stacked along with existing stacked view parts.

Add Comment