Tuesday, March 3, 2009

Getting access to files in Eclipse plug-ins

There are several ways to access files in Eclipse. Here are some samples
  • Getting an ImageDescriptor from a plug-in
  • Getting a resolved URL to a resource in another plug-in
  • Opening a resource in an editor

Getting an ImageDescriptor from a plug-in

You can get an image descriptor to an image resource via the
  • UIPlugin.imageDescriptorFromPlugin("pluginId", "icons/image.png")

Getting a URL to a resource inside a plug-in
First you have to have a plug-in (Bundle). Your can get it via
  • Activator.getDefault().getBundle() or
  • Platform.getBundle("plug-in id")

//If you want to access your own plug-in use Activator.getDefault().getBundle()

Bundle bundle = Platform.getBundle("org.eclipse.ui");

// This line return a url looking like this, bundleentry://921/plugin.xml
URL url = bundle.getEntry("/plugin.xml");

try {
// This line resolves the bundle resource url to an explicit file url into the bundle
// The url will get to look like below,
// jar:file:C:\...\org.eclipse.ui_3.4.0.I20080610-1200.jar!/plugin.xml
URL realUrl = FileLocator.resolve(url);

} catch (IOException e) {
e.printStackTrace();
}


Opening a resource in an editor
Here is a sample on how to open the org.eclipse.ui plugin.xml in an editor.

// Start by getting an IPath to a bundle resource.
IPath path = null;
URL url = null;
try {
url = FileLocator.toFileURL( Platform.getBundle("org.eclipse.ui").getEntry("/plugin.xml"));
path = new Path(url.getPath());
} catch (IOException e) {

e.printStackTrace();
}

// Next, use the Eclipse file store to validate and pass to an editor
IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);

if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {

IWorkbenchPage page = getSite().getPage();
try {
IDE.openEditorOnFileStore(page, fileStore);
} catch (PartInitException e) {
e.printStackTrace();
}
}

Listening for selected Lotus Notes documents

If you want to react when documents are selected in the Notes client, you will use the Eclipse Selection Service.

When listening you can reference the some of the document summary classes
  • DocumentSummary (base class for selections)
  • NotesDocumentSummary (document selection in view or when opened)
  • NotesOpenDocumentSummary (only when opened)
  • NotesFieldSelection (field activation in open document)
  • NotesLiveNameSelection (live name field activation in open document)
  • And many others
The classes are located in the following plug-ins
  • com.ibm.csi
  • com.ibm.notes.client

Creating the listener


// Prepare the selection listening. Start by getting the selection service.
ISelectionService ss = getSite().getWorkbenchWindow().getSelectionService();

// Create a selection listener
listener = new ISelectionListener() {

public void selectionChanged(IWorkbenchPart part, ISelection selection) {

// Is the selection a structured selection
if (selection instanceof IStructuredSelection) {

// Get the selection (could contain multiple selected objects)
IStructuredSelection ss = (IStructuredSelection) selection;

// Are the any objects in the selection?
if (ss.isEmpty()) return;

// Let's test the first selected object
Object e = ss.getFirstElement();

// Is the object a NotesOpenDocumentSummary?
if (e instanceof NotesOpenDocumentSummary) {
NotesOpenDocumentSummary ds = (NotesOpenDocumentSummary)e;
String title = ds.getTitle();
String url = ds.getUrl();

//...

}
}
}
};

// Add a post selection listener, so we don't have to listen to
// insignificant UP and DOWN keystroke selection triggering,

// we just need the final selection.

ss.addPostSelectionListener( listener);

Removing the listener
Remember to remove you listener when done.

// Do the following in the dispose() method of the view part or alike.

public void dispose() {
if (listener != null) {
ISelectionService ss = getSite().getWorkbenchWindow().getSelectionService();
ss.removePostSelectionListener(listener);
}
super.dispose();
}

Saturday, November 1, 2008

Fasttrack: Lotus 8 Eclipse development


Please be aware that this fasttrack is outdated!!

Some day I might update it from Lotus Notes 8.0.1 to a more current version
(currently Lotus Notes 8.5 & Expeditor 6.2)


If you're interested in getting involved in IBM Lotus 8 / Eclipse development technologies and you're wondering how to get started, here are some guidance you might want to explore.

This blog contains some step-by-step tutorials and informational guides that you can use in your quest to advance your skills and your company's competitive advantages.

Abstract
  • Introduction
  • Prerequisites
  • Setting up development environments
  • Learning the new stuff
  • Courses
  • Adjusting the project culture
  • Iterating your product / client strategy

Introduction
Prerequisites
Setting up development environments

Lotus Notes

Lotus Sametime

Learning the new stuff

So now you've got the development environments up and running, that's nice, but you still have some more stuff to do.

Next up is the understanding of the possibilities in the Eclipse based Lotus Notes and Sametime architectures, features and plug-ins.

Here are some examples on development best practices worth thinking about :
  • Java in Eclipse
  • Eclipse plug-ins
  • Eclipse SWT
  • Eclipse RCP (Rich Client Platform)
  • Lotus Expeditor 8 architecture and plug-ins
  • Lotus Notes /Eclipse architecture and plug-ins
  • Lotus Sametime /Eclipse architecture and plug-ins
Courses
Currently there are not many official learning suppliers on Lotus, Eclipse and Expeditor technologies other than IBM and The RCP Company were I work.

Adjusting the project culture
If many of the mentioned technologies are new to you, you should find a way to merge the new project and development considerations into your current procedures.

I know there are a lot of today's traditional Lotus Notes developers out there that, again, will have to adjust to IBM's innovative strategies, like this IBM Lotus Eclipse client. It might take a few years for most of them to get up to speed, depending on their customers needs.

This is a good opportunity for new software players to conquer new niche markets.

Iterating your product / client strategy
With this need for investment in new skills and knowledge, you have to re-think how your investment will generate the best pay-off on your solutions.

  • Where can you get professional best-practice guidance and knowledge
  • How can a solution benefit best from the new features and possibilities
  • How should you model the optimal plugin architecture
  • How will you integrate to the existing business logic
  • How should you prepare and model the development teams

Search This Blog

Eclipse Live: Equinox Ganymede

The creator of an Eclipse Bible, introduces Equinox and its building blocks for creating applications. We overview the architecture and technology, and demonstrate many of the building blocks.
by Jeff McAffer (Code 9)