Plug yourself in and your app will never be the same (2 hour edition)

Embed Size (px)

Citation preview

LSBG Vrseminar, maj 2011
Larvik, Norge

Plug yourself in and your applications will never be the same!(An introduction to plugin development for Lotus Notes, Domino and Sametime)

About me

Developer: Notes / Domino / Sametime / Java / DB2 / WebSphere / web / plug-ins

Design Partner for Domino NEXT and Lotus Connections 3.0

Active blogger: lekkimworld.com

Speaker at Lotusphere

Articles for THE VIEW

E-mail: [email protected]

.com/lekkim

What I do!

Well plugins of course... But plugins are a many-headed beast!It's not just stuff for the Notes sidebar

It's about extending the UI in Notes, Sametime
and Symphony

It's about delivering a UI capable of doing
stuff you cannot do in traditional Notes

It's about developing custom components for
the XPages Extensibility Library

It's about DOTS (previously JAVADDIN) and OSGi
on the Lotus Domino Server

Why I do it!

Plugin development is often about integrationYou often build extensions to existing applications to add functionality

Eclipse and therefore Expeditor, Notes, Symphony, and Sametime, are built to allow for extensibility

Plugin development has several advantagesJavaMature

Well Adopted

Multi-platform

Libraries

Eclipse CommunityWeb Services

Web Applications

Database Integrations

etc....

What's possible with plugins

Torsdag, sal 1, 11:20-12:00 - Ta samarbeid og planlegging til neste niv

RedWiki for plugin development

Lotus Notes and Domino Application Development wiki / IBM Redbook Publicationshttp://www-10.lotus.com/ldd/ddwiki.nsf/dx/Table_of_Contents_Developing_Customized_Components_for_Lotus_Notes_Sametime_and_Symphony

...or use the bit.ly link >> http://bit.ly/pluginredwiki

What I'm going to build (if time permits)

Sidebar panel containingA list box

Three buttons at the bottomOne button reads from a web service

One button reads contacts from names.nsf

One button creates a new emailReads recipient from list

Create document

Set subject

Add data from web service call to body

Create a feature for the plugin

Create an update site with the feature

Create a widget for the feature from the update site

Agenda

About Eclipse and Lotus Expeditor Toolkit

Installing Lotus Expeditor Toolkit

Plugin Development Basics

Building UI's with SWT and JFace

Jobs, Jobs, Jobs

Logging

APIs

Debugging

Deployment

Resources / Q&A

Eclipse architecture

Workbench

JFace

SWT

Core ExtensionPoint Framework

Service FrameworkRich Client Platform

Plug-inPlug-inExtension Pt.

Plug-in

ExtensionPointExtensionPointExtensionPoint

A software component in EclipseExtension Point declares contract
to extend plug-in functionalityExtension code extends this functionalityRCP allows you to build GUI apps on multiple OSSWT provides
uniform UI API across multiple OS that calls
OS UI API for native look and feelJFace provides components to make it easier to write a GUI e.g. wizards, preference pages, actions, dialogs Workbench is desktop UI and customizableService Framework supports registration and lifecycle management of
plug-ins

IBM Lotus Clients built on Eclipse

Notes

Sametime

Expeditor

SymphonyIndustry knowledge
and experienceecosystem of partners open and
extensible

Apps and Plug-ins (ISV + Customer)

collaborative servicesIntegratedapplications

Portal

BrowserDesktopMobileMultiplatform supportScalabilitySecurity

Eclipse workbench

Notes workbench

s

Lotus Expeditor (XPD) Toolkit

An integrated set of tools to develop, test, and deploy applications built on top of ExpeditorSupports Expeditor, Sametime, Notes and Symphony

FREE! No charge to use the Expeditor toolkit

Supported on Windows and Linux operating systems

Benefits Of Using The ToolkitEasily configure your development environment to develop for the platforms aboveTakes ~ 1 minute to configure your environmentSet your target environment

Point to the target locations on your machine

Provides a new launcher to launch products built on top of ExpeditorCreate a new launch configuration to launch the application from Eclipse

Provides numerous samples to get your started developing for Expeditor based products

Installing XPD Toolkit (1)

Download the XPD Toolkithttp://bit.ly/fKMF5o

Unzip

In Eclipse 3.4(.2)Help Software Updates...

http://www.eclipse.org/downloads/packages/eclipse-rcpplug-developers/ganymedesr2

Installing XPD Toolkit (2)

Click New Local Site...

Browse to unziped update
site

Select OK

Installing XPD Toolkit (3)

Select The XPD Toolkit

Click Install...

Installing XPD Toolkit (4)

Agree to the license
agreement

Install all features

Restart

Installing XPD Toolkit (5)

Start IDE

Select Test EnvironmentNotes, Sametime, Symphony, XPD

Specify Target LocationPoint to target runtime

/framework/rcp/eclipse

Click OK

Run Run Configuration

Double Click Client Services

Give The Configuration A Name

Select Run

Installing XPD Toolkit Demo

Start IDE

Select Test EnvironmentSymphony, Sametime, Notes , Expeditor

Specify Target LocationPoint to target runtime

/framework/rcp/eclipse

Click OK

Run Run Configuration

Double Click Client Services

Give The Configuration A Name

Select Run

What are plugins?

Plugins are the building blocks of Eclipse based applicationsAt their core a plugin is some code plus some declarations (extension points)

By themselves plugins may not do anything, but when you start combining plugins you can build very powerful applications

Examples: Eclipse, Notes, Sametime, Symphony

Application

Plugin

Anatomy of a plugin

Java code (optional)

Manifest.mf Basic properties of a plugin

Specifies dependencies this plugin has

Plugin.xmlExtension points the plugin uses / defines

Build.propertiesManages the build configuration of the plugin

Resources (optional)Jars the plugin may need

Files used for translation

Images

etc....

Demo: Creating a plugin project

File New Project Plugin Development

Select Plug-in Project

Extension Points

Extension points make plugins pluggablePlugins define extension points for other plugins to useExamples: sidebar, toolbar buttons, right click menus...

Extension points allow the platform to be more performant

Eclipse has a nice editor for adding and defining extension points

How do I know what extension points are available?Eclipse.org and the Expeditor wiki are your friends

Plugin

Using Extension Point

Extension Point Definition

Key Extension Points

org.eclipse.ui.viewsRegisters a view part with the platform

View parts can be used inside perspectives or in the sidebar

com.ibm.rcp.ui.shelfViewAn Expeditor extension point

Used to add a view part to the sidebar

org.eclipse.ui.actionSetsUsed to add top level toolbars and menus

org.eclipse.ui.menusUsed to add context menus

org.eclipse.ui.preferencePagesUsed to add preference pages to the preferences

The arcane art of building UI's

UI's are built using code

UI's are built using Java code adding widgets (controls) to containes (composites)

custom drawn using Java
code to listen for paint
events

In either case it isn't
WYSIWYG :-(

Standard Widget Toolkit (SWT)

Platform native look and feel

Protection from OS Level Changes

Very responsive

Resulting UI looks like native platform applications

JFace

UI toolkit built on top of SWT without hiding it

Provides coarser grained components than SWTDialogs

Image / Font Registries

Wizards

Viewers

Meet WindowBuilder!

http://eclipse.org/windowbuilder/

Demo: Create a sidebar plugin

Add org.eclipse.ui.views extension point

Create view part class

Add com.ibm.rcp.ui.shelfView
extension point

Use WindowBuilder to create UI

Try It Out!

All The APIs You Need

Do not reinvent the wheel!

Java and Eclipse contains a rich set of API's that you can use when developing plugins for Lotus clients

Knowing the API's available to you is crucial

We'll coverJobs (threading)

Logging

Notes backend

Notes frontend

Threading lightly

A thread is an abstraction in computers to allow programs to perform multiple operations simultaneouslyAvoid tying up the program with background operations

Two ways to call other codeSynchronously == blockingBlocks current code until call is done and then returns to continue processing

Like you're used to from LotusScript

Asynchronously == non-blockingThe calling code continues to run you now have two pieces of code running

To tell the caller we're done we use callbacks or listeners

Harder to grasp

Used in AJAX you request data in the background and once the data has been fetched you are told

Jobs, jobs, jobs - lets vote for jobs!

Eclipse Job Frameworkjava.lang.Thread is way too low-level and error prone

Allows for easy background processing

Very simple to use

Allows scheduling of jobs (run this code in 2 minutes)

Allows weaving of jobs

Allows for listening to job status etc.

Standard UI for manipulating jobs

Two types of JobJob for background processing

UIJob for user interface updates

Both are abstract classes and normally used as anonymous inner classes

There can be only one

Any Eclipse application only has ONE thread that may update the user interface

It's surprise, surprise called the UI thread

This means thatTying up the UI thread will render the entire client unresponsive

Attempts to access the UI (i.e. set the text of a label) outside the UI thread will fail with an exception

You need a way to do stuff in the UI thread

To do stuff in the UI thread you use an UIJob from the Job API

Using Job in code

public void fireOnTheEmpire(int initDelay, final String jediName) { // create recurring job to poll web service new Job("Poll the Force!") { protected IStatus run(IProgressMonitor monitor) { // invoke endpoint using input String srvc = http://moon5.tatooine.com/JediFinder; WSFacade facade = new WSFacade(srvc); String result = facade.fire(jediName); // do something with the result ...

// reschedule this job (in 5 mintues) this.schedule(5 * 60 * 1000); // return return Status.OK_STATUS; } }.schedule(initialDelay * 60 * 1000);}

final

Using UIJob in code

final List lstJedis = new List(parent, SWT.NONE);...public void psssst(final String[] jedis) { // since we're called in a background process // use that UIJob we learned about to update the UI new UIJob("Load Jedis") { public IStatus runInUIThread(IProgressMonitor monitor) { // update UI for (String jedi : jedis) { lstJedis.add(jedi); } // return status return Status.OK_STATUS; } }.schedule();}

Avoid Spinning Wheel of Death

public void createPartControl(Composite parent) { final Label txt = new Label(parent, SWT.NONE); new UIJob("Indicate job starting") { public IStatus runInUIThread(IProgressMonitor monitor) { txt.setText("Turning star cruiser (" + new Date() + ")...");

// do long running task == BAD!! try { Thread.sleep(5000); } catch (Exception e) {} txt.setText("Done turning star cruiser (" + new Date() + ")..."); // reschedule and return this.schedule(5000); return Status.OK_STATUS; } }.schedule(5000);}

Weaving Jobs

Most operations usually include a UI and a background component so you need to weave jobs

A typical operation from the user consists of 3 steps:

Usually you start of with a UI call (button click i.e. button selection)

You perform some background operation (e.g. load data from a web service or similar)

You need to call back into the UI and update or inform

We call this to weave job

We do it by nesting Job instances

Do it right!

public void widgetSelected(SelectionEvent event) { list.add("Starting to run code (" + new Date() + ")...", 0); new Job("Long running job") { protected IStatus run(IProgressMonitor monitor) { downloadEntireGoogleSearchIndex();

// call back into UI to tell user we're done new UIJob("Update UI") { public IStatus runInUIThread(IProgressMonitor monitor) { list.add("Done running code (" + new Date() + ")...", 0); return Status.OK_STATUS; } }.schedule(); return Status.OK_STATUS; } }.schedule();}

Demo: Using jobs in your code

Adding a button for background operation

Add selection listener

Load data from the web

Once call is done update the UI

Logging

System.out.println is NEVER the solution!Seems easy at first but 99% of the time it's easier to just use logging from the beginning

Lotus Expeditor / Notes comes with many supported logging mechanismsThe one to use is java.util.logging as it's built-in and easy to use and configure

Logging is done through the Logger class and at a specified LevelLevel (SEVERE, WARNING, INFO, FINE, FINER, FINEST, CONFIG)

Expensive logging may be guarded using isLoggable(Level)

Loggers are hierarchically named and level is set hierarchically as well

Logging Example

package com.example.demo1;

public class MainViewPart extends ViewPart { private static final Logger logger = Logger.getLogger(MainViewPart.class .getPackage().getName());

public MainViewPart() { try { logger.info("Main view part instantiated"); String senateCount = this.countSenators(); if (logger.isLoggable(Level.FINEST)) { logger.finest("Found + senateCount + senators (" + this + )); } } catch (Throwable t) { logger.severe(There was a disturbance in the Force!, t); } }}

Logging getting at it

Logging output goes to client logHelp > Support > View Log/Trace

Configured using OSGi console

Edit /workspace/.config/rcpinstall.properties and add .level= at the endcom.lekkimworld.twitnotes2.level=FINEST

Demo: Adding logging to the code

Add a logger to our view part

Log the current sunrise and sunset

Enable logging

Notes backend API

You have access to the Notes Java API you know and love!

Basic usage is almost the same as you know and love

To get access to the classes youDO NOT import notes.jar as you normally do

DO depend on the com.ibm.notes.java.api plugin

To access Notes data youDO NOT use NotesThread.sinitThread

DO use the Job API and the supplied NotesSessionJob

Notes backend API in code

new NotesSessionJob("Access Notes data") { public IStatus runInNotesThread(Session session,
IProgressMonitor monitor) throws NotesException {

// print username System.out.println(session.getDatabase(null, names.nsf).getTitle()); // return return Status.OK_STATUS; } }.schedule();

Notes frontend API

Modeled pretty much like the LotusScript UI APINotesUIWorkspace, NotesUIView, NotesUIDocument,

Should run in the UI thread

Bridges a MAJOR gap in the Notes product as it gives us access to the Notes UI from Java

Been with us for a whileAdded in Notes 8.5 as beta

Supported from Notes 8.5.1

More functionality added in Notes 8.5.2

To use it add a dependency on com.ibm.notes.java.ui

Example project available from OpenNTF.org (Java UI API Exerciser)

Notes frontend API (cont.)

NotesUIWorkspaceEntry point

Access to run an agent with context (access to LotusScript!)

NotesUIViewMost functionality added in Notes 8.5.2

Listen for selection events and view entries

Works for Java and traditional views

NotesUIDocumentYou can work in the document on the glass

Access to backend document

Edit / Field / Modify listeners

Access to copy/paste, refresh, reload

Data classes for easy access (i.e. NotesViewData)

Demo: Use the Notes APIs

Use NotesSessionJob to access the user's name.nsf file

Place the email addresses of the user's contacts in the list box

Use the composeDocument API to compose an email to selected contact with data

Final word on APIs

AccountsSecure storage for credentials, Automatic authentication for HTTP requests

Lotus SametimeAwareness / realtime collaboration

SearchSearch other applications from the search center

Domino DesignerExtend Domino Designer with custom actions

Composite ApplicationsCreate components for using Eclipse technology and listen for properties and expose actions

XPages Extensibility LibraryAdd custom widgets for XPages

LiveText / Toolbox (LiveText / Widgets API's is targeted to be publicly supported from 8.5.3)Inject recognizers based on business rules

Final word on APIs I promise!!

Like with Lotus Notes there a multitude of API's available to you for Selection, Jobs, Actions / menus, Drag'n'drop, Custom drawing, Charting

Explore Eclipse.org and remember to search for Eclipse and not Lotus Notes as it will yield far more results

Demo: Debugging basics

Launching Notes from Eclipse in debug mode

Set breakpoints

Inspecting variables

The console, logging levels

Deploying your fantastic work

Deployment is done by

Packaging your plugin(s) in
a feature

Creating an update site to hold
the feature

Installing the feature into the
clients either manually or using
a widget descriptor

Feature

Plug-in

Plug-in

. . .Feature

Plug-in

Plug-in

. . .Update Site. . .

Demo: Wrapping it all up

Create a feature project

Create an update site

Create an update site NSF

Add our feature to the update site NSF

Create a widget for our feature

Add it to a widget catalog

Watch a video at: http://bit.ly/h4pjMb

DOTS (used to be JAVADDIN)

XPages Extensibility Library

A new project has been created which contains a simple sample for how to to develop a 'native' XPages control via the Java extensibility API. This control can be deployed globally as an OSGi bundle/plugin to Lotus Domino and Lotus Notes/Domino Designer and then used in all NSFs without having to put the code in all NSFs redundantely. The new control shows up in the palette in Designer as other out of the box controls.

Summary and resources

RedWiki about plugin development >> http://bit.ly/pluginredwiki

HIGHLY recommended article on the Job API >> http://www.eclipse.org/articles/Article-Concurrency/jobs-api.html

Eclipse articles >> http://www.eclipse.org/articles

Eclipse WindowBuilder >> http://www.eclipse.org/windowbuilder

Q&A

But!

How do I?

Doesn't that mean?

Give it to me! :-)

IV_Logo.png

OnTime_Logo.png

IV_Logo.png

OnTime_Logo.png

2011 IBM Corporation