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))