The sidebar in Lotus Notes 8 is home to many useful embedded applications such as a feed reader and it provides constant access to IBM Lotus Sametime contacts and the Notes calendar. This article will give a quick run through how you can create a simple Eclipse plug-in which is housed as panel in the sidebar.
Prerequisites
If you are not familiar with creating Eclipse plug-ins, it is recommendable to read the Eclipse tutorial on this wiki beforehand. Also, make sure that your Eclipse environment is configured for launching Notes from the IDE as described on this wiki.
Introduction
Creating a sidebar panel is actually quite easy and simply involves creating an Eclipse plug-in which uses a pre-defined extension.
When creating a sidebar panel you are really creating what's called a ViewPart in Eclipse (also simply referred to as a "View"). The article (Creating an Eclipse View ), although a few years old, is still valid and recommended reading.
Creating a plug-in
1. Open Eclipse and create a new blank plug-in project named "ShelfProject".
2. Under the Dependencies tab in your plug-in manifest editor add "com.ibm.rcp.ui". This is needed to extend the sidebar.
3. Under the Extensions tab add "org.eclipse.ui.views" to create our view and set the name and id as "SampleView".
4. Next select the plugin.xml tab and replace the content in that editor with this XML fragment:
<?xml version="1.0" encoding="UTF-8"?
<?eclipse version="3.2"?
<plugin
<extension
id="SampleView"
name="SampleView"
point="org.eclipse.ui.views"
<view
allowMultiple="true"
class="views.SampleView"
id="SampleView"
name="SampleView"/
</extension
</plugin
5. Save the plug-in manifest.
6. Select the project in the package explorer view on the left, right click to open the context menu and select New -> Class.
7. Name your class "SampleView" and change the package name to "views_". Press "Browse..." next to the "Superclass" field and type in "ViewPart". Select the matching class (org.eclipse.ui.part.ViewPart) and click "OK", then click "Finish" to close the new class dialog.
In the package explorer you now have a class called "SampleView" in a new package called "views". Now that our view is created it is time to move on to extending the sidebar.
Extending the sidebar
1. Open again the plug-in manifest. In the Extensions tab add an extension "com.ibm.rcp.ui.shelfViews" which will be represent the visible part of the panel in the sidebar.
2. The id should be set to "ShelfProject.shelfView1" which should already be set as default. The view entry should be changed to the id of our view, which is "SampleView". The other settings can stay as they are.
3. Save the plug-in manifest. Now, we have already extended the sidebar!
Creating our UI
In order to create our UI we simply need to create a standard Eclipse view. We have already created our view class and for the sake of simplicity we will only add some text to the view in this example.
Open the SampleView class and replace its createPartControl() method with the following code:
public void createPartControl(Composite arg0) {
arg0.setLayout(new FillLayout());
Label label = new Label(arg0, SWT.NONE);
label.setText("My new sideshelf view");
}
Click Source -> Organize Imports and accept the default values in order to resolve any compile errors. Save the file.
Now, if you run Lotus Notes 8 from Eclipse you should see the new panel in the sidebar.
Contributing to the sidebar panel menu
Each sidebar application has its own menu beside the title of the application, called the panel menu. We need another extension in order to contribute to this menu. In order to achieve this we need to open the plug-in manifest, go to the Extensions tab and add an extension "org.eclipse.ui.viewActions".
Create a new package called menu.actions in the src folder and create a class called MenuAction in that package. The MenuAction class should extend ActionDelegate and implement IViewActionDelegate. This class will handle the action.
We now add the following method to our MenuAction class, which will simply display a message box when the menu item is selected:
public void run(IAction arg0) {
MessageBox msg = new MessageBox(PlatformUI.getWorkbench().getDisplay().getActiveShell());
msg.setMessage("Item Selected");
msg.setText("Item Selected");
msg.open();
}
Again, click Source -> Organize Imports for including the required import statements.
The next step involves editing the actual XML source, which is available in the tab named "plugin.xml" of the plug-in manifest. In the plugin.xml tab of the manifest editor you will see all of the XML that defines our plug-in. There will be an extension point which looks like this:
<extension point="org.eclipse.ui.viewActions"></extension>
We need to replace this section with the following one:
<extension point="org.eclipse.ui.viewActions"
<viewContribution id="ShelfSample.actions" targetID="SampleView"
<action id="menu.actions.MenuAction" label="Sample Menu Item" tooltip="Sample Menu Contribution"
menubarPath="additions" class="menu.actions.MenuAction" enablesFor="*"/
</viewContribution
</extension
This simply defines the id of the view we are contributing to, the id of the action, the class where the action is handled, the text, the tooltip, where the item is added (menubarPath) and the conditions under which the action should be enabled (enablesFor).
Save the manifest file.
Now if you launch Lotus Notes 8 from Eclipse, your sidebar application should have a menu contribution which, when clicked, will display a message box.
Adding ac tions to the sidebar panel menu programmatically
Besides using the org.eclipse.ui.viewActions extension point as shown above you can also add actions to the sidebar panel menu programmatically using Java code. This approach can be beneficial if you need to add actions to the menu but you need to decide which actions to add at runtime. Imagine a case where the user needs to be able to switch between different data sources but you do not know which data sources are available at compile time. Some data sources may even be supplied via an extension point.
The below snippet shows how to add actions at runtime.
you need a reference to the viewpart
ViewPart part = ...;
get the menu manager from the viewsite
final IMenuManager menu_mgr = part.getViewSite().getActionBars().getMenuManager();
create an Action if you don't already have one
Action a = new Action("Some title") {
public void run() {
simply show a dialog box
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Info", "Some information...");
}
};
specifying an id is optional
a.setId("com.example.someId");
add to menu manager to add to menu
menu_mgr.add(a);