[ome-devel] Agent samples

Donald MacDonald donald at lifesci.dundee.ac.uk
Tue Jul 15 12:36:43 BST 2008


Hi,

You seem to mixing up two concepts:

The TreeViewerAction which is created in the TreeViewerControl is for  
the actions inside the agent. They are derived from TreeViewerAction  
and are in the TreeViewer.Actions package. These are then just used  
like any other AbstractAction in Java. To use them to post an event  
to another agent you would create an action which then called a post  
event; these are derived from ActionCmd in the Treeviewer package  
treeviewer.cmd and they call the appropriate method in  
TreeViewerComponent to fire the post event. You do not need to  
register for an event to be able to post it.

The events registered for in the setContext are those events created  
outside the agent:

Register for event.

/**
      * Implemented as specified by {@link Agent}.
      * @see Agent#setContext(Registry)
      */
     public void setContext(Registry ctx)
     {
         registry = ctx;
         EventBus bus = registry.getEventBus();
         bus.register(this, CopyRndSettings.class);
         bus.register(this, SaveEventRequest.class);
     }

Listen to event.

/**
      * Responds to an event fired trigger on the bus.
      * Listens to ViewImage event.
      * @see AgentEventListener#eventFired(AgentEvent)
      */
	public void eventFired(AgentEvent e)
	{
		if (e instanceof CopyRndSettings)
			handleCopyRndSettings((CopyRndSettings) e);
		else if (e instanceof SaveEventRequest)
			handleSaveEventRequest((SaveEventRequest) e);
	}


To post an event inside an agent you only need to post the event:
Method inside TreeViewerComponent:
public void copyRndSettings()
	{
		Browser browser = model.getSelectedBrowser();
		if (browser == null) return;
		TreeImageDisplay node = browser.getLastSelectedDisplay();
		Object o = node.getUserObject();
		if (!(o instanceof ImageData)) return;
		ImageData img = (ImageData) o;
		long pixelsID = img.getDefaultPixels().getId();
		EventBus bus = TreeViewerAgent.getRegistry().getEventBus();
		bus.post(new CopyRndSettings(pixelsID));
	}
Hope this helps

Donald MacDonald

On 15 Jul 2008, at 10:37, Jost Gundelach wrote:

> Hi Jean-Marie,
>
> ok, I found the agent entries inside the container.xml  
> configuration stuff of Insight client. Now I know we have to  
> implement the Agent and AgentEventListener interface for our own  
> agent. Which events we need register inside setContext, when I  
> would like to add a TreeViewerAction inside the TreeViewerControl?
>
> Thank you!
> Jost Gundelach
>
> --
> Jost Gundealch, Dipl.-Inform.
> c.a.r.u.s. IT AG
> Phone: (040) 5 14 35-0, intl.: +49.40.5 14 35-0
>
>
>
> _______________________________________________
> ome-devel mailing list
> ome-devel at lists.openmicroscopy.org.uk
> http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel



More information about the ome-devel mailing list