Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Developing a location awareness plug-in for IBM Lotus Sametime Connect V7.5

Shruti Gandhi, Lead architect, IBM, Software Group
Shruti Gandhi is the lead architect for location-based services for real-time collaboration. She is also a developer on the IBM Lotus Sametime Connect V7.5 client. She is in the process of finishing her Masters of Science in Computer Science at Columbia University.

Summary:  Once you understand the location awareness feature in IBM Lotus Sametime V7.5, you can use it along with the Lotus Sametime Software Development Kit (SDK) to create a plug-in that displays local weather for a selected Sametime partner.

Date:  12 Sep 2006
Level:  Intermediate
Also available in:   Chinese

Activity:  7128 views
Comments:  

In the previous article, "Discover location awareness in IBM Lotus Sametime V7.5," you learned what location awareness is and how it is used in Lotus Sametime V7.5. You also learned that location awareness functionality is accessible through the IBM Lotus Sametime V7.5 Software Development Kit (SDK). In this article, we show how to use the Lotus Sametime SDK to write a location-based plug-in for Lotus Sametime Connect V7.5.

This article shows you how to use the Sametime location awareness feature to create a plug-in that displays local weather for your Sametime partners. It assumes that you have some prior experience developing plug-ins for IBM Lotus Sametime Connect in the Eclipse IDE. For more information about developing Sametime plug-ins and about the Lotus Sametime SDK, see the Resources section.

Displaying local weather

This article guides you through the creation of the Local Weather plug-in, showing you how to extend a live name on your Contacts list to serve location-based data. In the example, we show you how to get local weather information for a contact when you right-click a partner name (see figure 1). Using location awareness, you can find weather information for the city in which your partner lives.


Figure 1. Local Weather plug-in
Local Weather plug-in

As you see in figure 1, the partner is located in Cambridge, MA, US. When you choose Local Weather from the right-click context menu, the Local Weather plug-in retrieves and displays weather information about Cambridge, MA (see figure 2) in a separate window. Weather information is retrieved from the Web site DynaWeather.com.


Figure 2. Local weather for Cambridge, MA
Local weather for Cambridge, MA

You can select multiple partners from your Contacts list and receive multiple weather mash-ups for each one.


Getting started

To build the Local Weather plug-in, you need to make your environment plug-in ready for Lotus Sametime. These are basic steps you take to write any plug-in for the product:

  1. Download the Eclipse SDK 3.2 and install the J9 Java Development Tools (JDT) launch plug-in for Eclipse.
  2. Configure your run-time to use J9.
  3. Configure the Eclipse compiler settings for Java Developer Kit (JDK) 1.4.
  4. Specify Lotus Sametime as the target platform in Eclipse.

You can download the Eclipse SDK 3.2 from the Eclipse Web site. The first three steps are explained in more detail in the Lotus Sametime SDK documentation, which is available with the SDK, so we won't cover them in this article.

Making Lotus Sametime your target platform in Eclipse

To use Eclipse to create plug-ins for Lotus Sametime, you must specify Lotus Sametime as the target platform. In Eclipse, choose Window - Preferences to open the Preferences dialog box. In the left pane, select Plug-in Development - Target Platform.

In the Location field, browse to the installation location of your Lotus Sametime Connect client, for example, C:\Program Files\IBM\Sametime, and then click Reload (see figure 3).


Figure 3. Preferences dialog box
Preferences dialog box

Now, let’s write the plug-in that demonstrates how to use location information to deliver location-based services for any partner you select in your Contacts list. This plug-in provides you weather details for any user for whom you want that information.


Create a new plug-in

In Eclipse, to create a plug-in you need to begin with a project. To do so, follow these steps:

  1. Choose File - New Project.
  2. In the New Project dialog box, open the Plug-in Development folder, select Plug-in Project, and then click Next.
  3. In the New Plug-in Project wizard, name your project: com.ibm.collaboration.realtime.location.weather, and then click Next.
  4. In the next wizard panel, complete the following fields:
    • Plug-in ID: com.ibm.collaboration.realtime.location.weather (or something similar)
    • Plug-in Version: 1.0.0
    • Plug-in Name: com.ibm.collaboration.realtime.location.weather (make the same as the plug-in ID)
    • Plug-in Provider: (enter your company name)
    • Classpath: Weather.jar
  5. Select the "Generate an activator, a Java class that controls the plug-in's life cycle" and the "This plug-in will make contributions to the UI" options (see figure 4). When you select the latter option, the Activator class extends the AbstractUIPlugin, which extends the Plugin class. For more information about this, see the developerWorks Lotus article, "Extending the Lotus Sametime client with an LDAP directory lookup plug-in."
  6. Click Finish when done.

Figure 4. New Plug-in Project wizard
New Plug-in Project wizard


Plug-in dependencies

The Local Weather plug-in is dependent upon other plug-ins to extend the Lotus Sametime Connect user interface. Follow these steps to add required plug-ins:

  1. In Eclipse, open META-INF MANIFEST.MF in the Manifest Editor.
  2. Select the Dependencies tab.
  3. Add the following plug-ins in the Required Plug-ins section (see figure 5):
    • org.eclipse.ui
    • org.eclipse.core.runtime
    • com.ibm.collaboration.realtime.people
    • com.ibm.rcp.realtime.livenames
    • com.ibm.collaboration.realtime.core

Figure 5. Dependencies
Dependencies


Adding to the right-click menu

To trigger the Local Weather plug-in, you use a right-click context menu item, Local Weather, as shown in figure 1. You can add to the right-click mouse action of a selected person, multiple selected people, or a group by using the following livenames.PersonSelection extension. Edit the plugin.xml file in Eclipse to add the following extension.

<plugin>
	<extension point="org.eclipse.ui.popupMenus">   
		<objectContribution
		adaptable="false"
		id=
		"com.ibm.collaboration.realtime.location.weather.BuddyLocalWeather"
		objectClass=
		"com.ibm.collaboration.realtime.livenames.PersonSelection">
			<action
			class=
			"com.ibm.collaboration.realtime.location.weather.BuddyLocalWeather"
			id=
			"com.ibm.collaboration.realtime.location.weather.BuddyLocalWeather"
			label="Local Weather"
			menubarPath="im_additions"/>
		</objectContribution>
	</extension>
</plugin>

BuddyLocalWeather is the class that you need to implement these actions. That class detects the change in partner selection for the right-click menu and specifies how many people are selected.

You can also add the BuddyLocalWeather class through the Extensions tab in MANIFEST.MF by following these steps:

  1. In Eclipse, open MANIFEST.MF in the Manifest Editor.
  2. Select the Extensions tab.
  3. Click the Add button.
  4. In the New Extension dialog box, select org.eclipse.ui.popupMenus, and then click Finish.


The extension should look like figure 6.


Figure 6. BuddyLocalWeather class added to extension
BuddyLocalWeather class added to extension


Creating a class that implements IObjectActionDelegate

A plug-in can contribute its own menu items to an object using Eclipse's org.eclipse.ui.popupMenus extension point. The class that defines the behavior of the menu action implements the IActionDelegate interface. This interface defines required methods, including the run method, which is called when the user selects the contributed menu item.

For more information about IActionDelegate, refer to the Eclipse documentation.

In the Package Explorer view in Eclipse, there is a package called com.ibm.collaboration.realtime.location.weather. Right-click it to create a new Java class by choosing New - Class from the context menu.

In the New Java Class dialog box, enter the name BuddyLocalWeather. Click the Add button in the dialog box, and then enter IObjectActionDelegate in the Implemented Interfaces Selection dialog box that opens. Click OK.

IObjectActionDelegate extends IActionDelegate by providing an interface for any object action that contributes to a right-click context menu. Refer to the Eclipse documentation for more information.

The entries should look like figure 7. Click Finish when done.


Figure 7. New Java Class dialog box
New Java Class dialog box

You have created the following class:

public class BuddyLocalWeather implements IObjectActionDelegate {

	public void setActivePart(IAction arg0, IWorkbenchPart arg1) {
		// TODO Auto-generated method stub
	}

	public void run(IAction arg0) {
		// TODO Auto-generated method stub
	}

	public void selectionChanged(IAction arg0, ISelection arg1) {
		// TODO Auto-generated method stub
	}
}

Next, you implement the selectionChanged and the run methods. The selectionChanged method helps you detect which partner is selected and how many partners are selected. This selection is returned as IStructuredSelection. The run method is executed when the right-click action is invoked.

Because selection is returned as an IStructuredSelection, you have to traverse down the list to get the PersonSelection member entries. Each PersonSelection entry contains a Person object that holds information about a live name, contact name, display name, and so on. Along with this information, you also get a location object in return.

The location object is accessed from a person object:

person[x].getLocationInfo()


This location object contains information about your partner, including:

  • City
  • State
  • Country
  • Postal code
  • User’s personal location name
  • Time zone
  • User’s phone number for that location


The following code shows how information for the location object is accessed:

	public String getZip(Person persons){
		return persons.getLocationInfo().getPostalCode();
	}

	public String getCity(Person persons){
		return persons.getLocationInfo().getCityName();
	}
	public String getState(Person persons){
		return persons.getLocationInfo().getStateName();
	}

…

For the complete code of the Local Weather plug-in, see the Download section.


Getting location data

In our example, we use DynaWeather’s service to get a pictorial representation of the weather for a location. In the following URL, you can substitute #ZIP# with any zip code to get the weather image for that location:

http://dynaweather.com/hw3.cgi?forecast=hourly&pands=#ZIP#&config=png&alt=hwicc&daysonly=1

Thus, in the Local Weather plug-in, once you retrieve a person’s location, you can substitute the #ZIP# with a valid zip code. When the run method is invoked, the code gets the number of people selected, retrieves their contactId and communityId to get the person’s location, and creates the weather mash-up.

public void run(IAction arg0) {
		Person[] persons = getSelectedPersons();
		getSelectedUsersString(persons);
}

//Create a list of people selected
	protected Person[] getSelectedPersons() {
		if (ss == null)
			return new Person[0];
		
		List items = ss.toList();
		List people = new ArrayList();
		for (Iterator it = items.iterator(); it.hasNext();) {
			Object item = it.next();
			if (item instanceof PersonSelection) {
				PersonSelection personSelection = 
				(PersonSelection) item;
				String contactId = 
				personSelection.getPerson().getContactId();
				String communityId = 
				personSelection.getPerson().getCommunityId();
				Person person = getPerson(contactId, communityId);
				people.add(person);
			}
		}
		
		return (Person[]) people.toArray(new Person[people.size()]);
	}

//Traverse through all the people that you selected 
//and create a mash-up shell for them
private void getSelectedUsersString(Person[] persons) {
    	for ( int i=0;i<persons.length;i++) {
    		Person person = persons[i];
    		String zip = getZip(person);
    		String city = getCity(person);
    		String state = getState(person);
    		String country = getCountry(person);
    		createShell(zip, city, state, country, person);

    	}
    	
	}

To create the mash-up, you use a browser widget to invoke the Browser.setURL method to set the DynaWeather URL to display the weather image in the mash-up.

NOTE: We use DynaWeather.com in our example for demo purposes only. You can use any weather service that you choose. If you want to use DynaWeather, then we encourage you to seek an agreement with the site.


Conclusion

In the Local Weather plug-in, we use partner location data to determine the weather in a partner’s geographical area. You can use location information to find many more location-related attractions, such as restaurants, movie theaters, and so on. We hope that this article inspires you to make the most of Lotus Sametime's location awareness feature.



Download

DescriptionNameSizeDownload method
Sample plug-in codelocation-awareness.zip13 KB HTTP

Information about download methods


Resources

Learn

Get products and technologies

Discuss

About the author

Shruti Gandhi is the lead architect for location-based services for real-time collaboration. She is also a developer on the IBM Lotus Sametime Connect V7.5 client. She is in the process of finishing her Masters of Science in Computer Science at Columbia University.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Lotus
ArticleID=158353
ArticleTitle=Developing a location awareness plug-in for IBM Lotus Sametime Connect V7.5
publish-date=09122006
author1-email=
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers