[ome-devel] Agent samples

Jost Gundelach omero at gundelacht.de
Tue Jul 15 14:42:02 BST 2008


Hi Donald,

but I don't want to post an event. I wish to integrate a menu item into 
the existing TreeViewerControl without changing it.

thanks for help
Jost Gundelach

Donald MacDonald schrieb:
> 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



More information about the ome-devel mailing list