Skip navigation


This simple example shows creating a new action and adding it to a brand new toolbar. The HermesBrowser.getSelectedMessages() method returns a collection of any messages selected by the user in a browse document window.

from javax.swing import Action
from javax.swing import AbstractAction
from java.awt.event import ActionEvent
from hermes.browser import IconCache

# The singleton HermesJMS browser

browser = HermesBrowser.getBrowser()

# Wrap your new code in a Swing action like this.

class JythonAction (AbstractAction):
	def __init__(self, browser):
		self.browser = browser
		self.putValue(Action.NAME, "Jython Script")
		self.putValue(Action.SHORT_DESCRIPTION, "This is something in Jython")
		self.putValue(Action.SMALL_ICON, IconCache.getIcon("python"))

	def actionPerformed(self, event):
		numMessages = browser.getSelectedMessages().size()
		if numMessages == 0:
			browser.showInformationDialog("No messages selected")
		else:
			browser.showInformationDialog("%d messages selected" % numMessages)


# Get HermesJMS to create a command (tool) bar, add the action and add the command bar to the GUI

commandBar = browser.getDockableBarManager().getDockableBar("Scripts")

if commandBar == None:
	commandBar = browser.createDockableBar("Scripts")
	browser.getDockableBarManager().addDockableBar(commandBar)

commandBar.add(JythonAction(browser))

If you add this to your $HOME/.hermes/hermesrc.py, start HermesJMS, browse some messages and click on the icon you'll see something like this:

Adaptavist Theme Builder Powered by Atlassian Confluence